Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 May 2024 20:20:34 GMT
From:      Michael Tuexen <tuexen@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: fe136aecc2a0 - main - tcp: improve inp locking in setsockopt
Message-ID:  <202405232020.44NKKYmE047443@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by tuexen:

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

commit fe136aecc2a0ae9d9cc5f78b2d1430cd33b6b7c4
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2024-05-23 20:14:27 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2024-05-23 20:19:12 +0000

    tcp: improve inp locking in setsockopt
    
    Ensure that the inp is not dropped when starting a stack switch.
    While there, clean-up the code by using INP_WLOCK_RECHECK, which
    also re-assigns tp.
    
    Reviewed by:            glebius
    MFC after:              3 days
    Sponsored by:           Netflix, Inc.
    Differential Revision:  https://reviews.freebsd.org/D45241
---
 sys/netinet/tcp_usrreq.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c
index 3e705181d5e8..9e0a702a6c0f 100644
--- a/sys/netinet/tcp_usrreq.c
+++ b/sys/netinet/tcp_usrreq.c
@@ -1709,11 +1709,7 @@ tcp_ctloutput_set(struct inpcb *inp, struct sockopt *sopt)
 		default:
 			return (error);
 		}
-		INP_WLOCK(inp);
-		if (inp->inp_flags & INP_DROPPED) {
-			INP_WUNLOCK(inp);
-			return (ECONNRESET);
-		}
+		INP_WLOCK_RECHECK(inp);
 	} else if (sopt->sopt_name == TCP_FUNCTION_BLK) {
 		/*
 		 * Protect the TCP option TCP_FUNCTION_BLK so
@@ -1728,8 +1724,7 @@ tcp_ctloutput_set(struct inpcb *inp, struct sockopt *sopt)
 		if (error)
 			return (error);
 
-		INP_WLOCK(inp);
-		tp = intotcpcb(inp);
+		INP_WLOCK_RECHECK(inp);
 
 		blk = find_and_ref_tcp_functions(&fsn);
 		if (blk == NULL) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202405232020.44NKKYmE047443>