summaryrefslogtreecommitdiffstats
path: root/sys/netinet
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2008-01-23 21:15:51 +0000
committerrwatson <rwatson@FreeBSD.org>2008-01-23 21:15:51 +0000
commit8aff4dd3cd645f9f47be00700a8ec11e4a262873 (patch)
tree9711353985548f1b5cea16bcfe180dc131446df3 /sys/netinet
parenta0d60019afa3ab214dcb1edb63a7155f3279da5b (diff)
downloadFreeBSD-src-8aff4dd3cd645f9f47be00700a8ec11e4a262873.zip
FreeBSD-src-8aff4dd3cd645f9f47be00700a8ec11e4a262873.tar.gz
tcp_usrreq.c:1.313 removed tcbinfo locking from tcp_usr_accept(), which
while in principle a good idea, opened us up to a race inherrent to the syncache's direct insertion of incoming TCP connections into the "completed connection" listen queue, as it transpires that the socket is inserted before the inpcb is fully filled in by syncache_expand(). The bug manifested with the occasional returning of 0.0.0.0:0 in the address returned by the accept() system call, which occurred if accept managed to execute tcp_usr_accept() before syncache_expand() had copied the endpoint addresses into inpcb connection state. Re-add tcbinfo locking around the address copyout, which has the effect of delaying the copy until syncache_expand() has finished running, as it is run while the tcbinfo lock is held. This is undesirable in that it increases contention on tcbinfo further, but a more significant change will be required to how the syncache inserts new sockets in order to fix this and keep more granular locking here. In particular, either more state needs to be passed into sonewconn() so that pru_attach() can fill in the fields *before* the socket is inserted, or the socket needs to be inserted in the incomplete connection queue until it is actually ready to be used. Reported by: glebius (and kris) Tested by: glebius
Diffstat (limited to 'sys/netinet')
-rw-r--r--sys/netinet/tcp_usrreq.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c
index a70a551..c19bc0c 100644
--- a/sys/netinet/tcp_usrreq.c
+++ b/sys/netinet/tcp_usrreq.c
@@ -605,6 +605,7 @@ tcp_usr_accept(struct socket *so, struct sockaddr **nam)
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
+ INP_INFO_RLOCK(&tcbinfo);
INP_LOCK(inp);
if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
error = ECONNABORTED;
@@ -624,6 +625,7 @@ tcp_usr_accept(struct socket *so, struct sockaddr **nam)
out:
TCPDEBUG2(PRU_ACCEPT);
INP_UNLOCK(inp);
+ INP_INFO_RUNLOCK(&tcbinfo);
if (error == 0)
*nam = in_sockaddr(port, &addr);
return error;
OpenPOWER on IntegriCloud