git: 5632dd45cc10 - stable/14 - tcp: improve error handling in syncache_socket()

From: Michael Tuexen <tuexen_at_FreeBSD.org>
Date: Sat, 03 Aug 2024 22:50:06 UTC
The branch stable/14 has been updated by tuexen:

URL: https://cgit.FreeBSD.org/src/commit/?id=5632dd45cc10ec75f9ba679b9b985c82b7a40267

commit 5632dd45cc10ec75f9ba679b9b985c82b7a40267
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2024-06-27 05:25:15 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2024-08-03 22:49:33 +0000

    tcp: improve error handling in syncache_socket()
    
    If syncache_socket() fails after calling tcp_newtcpcb(), the resources
    allocated in tcp_newtcpcb() needs to be freed. Just call
    tcp_discardcb() to do this.
    Thanks to jtl for making me aware of the issue and proposing a fix.
    
    Reviewed by:            glebius, jtl, rscheff
    MFC after:              1 week
    Differential Revision:  https://reviews.freebsd.org/D45749
    
    (cherry picked from commit 3703e1a73e0e0367c04f47f793e46495e46e647b)
---
 sys/netinet/tcp_syncache.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c
index 20c77930556e..21dfe8dd123e 100644
--- a/sys/netinet/tcp_syncache.c
+++ b/sys/netinet/tcp_syncache.c
@@ -1050,6 +1050,7 @@ allocfail:
 	return (NULL);
 
 abort:
+	tcp_discardcb(tp);
 	in_pcbfree(inp);
 	sodealloc(so);
 	if ((s = tcp_log_addrs(&sc->sc_inc, NULL, NULL, NULL))) {