Skip to content

Commit 1df3097

Browse files
committed
unix/stream: fix wakeup race between pr_poll and pr_soreceive
Both selrecord(9) and UXST_PEER_SEL marking should happen under the receive buffer lock. Otherwise, there is a race window, when a reading thread would issue wakeup(9) before a polling thread have entered sleep(9). Reported by: cy Fixes: d157927
1 parent a130a60 commit 1df3097

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

sys/kern/uipc_usrreq.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,11 +1681,12 @@ uipc_sopoll_stream_or_seqpacket(struct socket *so, int events,
16811681
(POLLOUT | POLLWRNORM);
16821682
if (sb->sb_state & SBS_CANTRCVMORE)
16831683
revents |= POLLHUP;
1684-
if (!(revents & (POLLOUT | POLLWRNORM)))
1684+
if (!(revents & (POLLOUT | POLLWRNORM))) {
16851685
so2->so_rcv.uxst_flags |= UXST_PEER_SEL;
1686+
selrecord(td, &so->so_wrsel);
1687+
}
16861688
SOCK_RECVBUF_UNLOCK(so2);
1687-
}
1688-
if (!(revents & (POLLOUT | POLLWRNORM)))
1689+
} else
16891690
selrecord(td, &so->so_wrsel);
16901691
}
16911692
}

0 commit comments

Comments
 (0)