diff options
author | trociny <trociny@FreeBSD.org> | 2011-05-29 18:00:50 +0000 |
---|---|---|
committer | trociny <trociny@FreeBSD.org> | 2011-05-29 18:00:50 +0000 |
commit | 1dfa9ab8735324b683e437551bc3829f83c6e8f0 (patch) | |
tree | 8709a800f790b40b793280b085b866839e46be37 /sys/kern/uipc_socket.c | |
parent | 32bc69c8c8c3658d3ecb4643a9686383bb09e6d4 (diff) | |
download | FreeBSD-src-1dfa9ab8735324b683e437551bc3829f83c6e8f0.zip FreeBSD-src-1dfa9ab8735324b683e437551bc3829f83c6e8f0.tar.gz |
In soreceive_generic(), if MSG_WAITALL is set but the request is
larger than the receive buffer, we have to receive in sections.
When notifying the protocol that some data has been drained the
lock is released for a moment. Returning we block waiting for the
rest of data. There is a race, when data could arrive while the
lock was released and then the connection stalls in sbwait.
Fix this by checking for data before blocking and skip blocking
if there are some.
PR: kern/154504
Reported by: Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua>
Tested by: Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua>
Reviewed by: rwatson
Approved by: kib (co-mentor)
MFC after: 2 weeks
Diffstat (limited to 'sys/kern/uipc_socket.c')
-rw-r--r-- | sys/kern/uipc_socket.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 54a050f..3334fc2 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1845,10 +1845,16 @@ dontblock: } SBLASTRECORDCHK(&so->so_rcv); SBLASTMBUFCHK(&so->so_rcv); - error = sbwait(&so->so_rcv); - if (error) { - SOCKBUF_UNLOCK(&so->so_rcv); - goto release; + /* + * We could receive some data while was notifying + * the protocol. Skip blocking in this case. + */ + if (so->so_rcv.sb_mb == NULL) { + error = sbwait(&so->so_rcv); + if (error) { + SOCKBUF_UNLOCK(&so->so_rcv); + goto release; + } } m = so->so_rcv.sb_mb; if (m != NULL) |