Thread View: muc.lists.freebsd.bugs
1 messages
1 total messages
Started by bugzilla-noreply
Wed, 04 Nov 2026 07:50
[Bug 300494] unix(4): shutdown(SHUT_WR) on a stream socket doesn't run the peer's receive upcall (soupcall_set(SO_RCV))
Author: bugzilla-noreply
Date: Wed, 04 Nov 2026 07:50
Date: Wed, 04 Nov 2026 07:50
110 lines
6302 bytes
6302 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300494
Bug ID: 300494
Summary: unix(4): shutdown(SHUT_WR) on a stream socket doesn't
run the peer's receive upcall (soupcall_set(SO_RCV))
Product: Base System
Version: 15.1-RELEASE
Hardware: Any
OS: Any
Status: New
Severity: Affects Some People
Priority: ---
Component: kern
Assignee: bugs@FreeBSD.org
Reporter: grepjava@gmail.com
Created attachment 276962
--> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=276962&action=edit
Reproducer kernel module: counts SO_RCV upcalls across peer shutdown(SHUT_WR)
When one end of a connected SOCK_STREAM (or SOCK_SEQPACKET) AF_UNIX socket pair
calls shutdown(SHUT_WR), the peer's receive buffer gets SBS_CANTRCVMORE, and
select(2), poll(2) and kqueue waiters on the peer are woken. A receive upcall
installed on the peer with soupcall_set(so, SO_RCV, ...) is not called, though.
A consumer that waits on the upcall therefore never learns that the input
ended, and waits until something else happens on the socket. Data sent by the
peer does run the upcall, and so does closing the peer.
uipc_shutdown() handles SHUT_WR on a stream socket by calling
uipc_cantrcvmore() on the peer. That function sets SBS_CANTRCVMORE and calls
selwakeuppri() and KNOTE_LOCKED() itself, and then uipc_wakeup_writer() if
there is a uxst_peer. It never goes through sorwakeup_locked()/sowakeup(),
which is where SB_UPCALL is handled. socantrcvmore(), which other protocols use
for the same event, goes through sorwakeup_locked(). The data paths in
uipc_usrreq.c call sorwakeup_locked() too, so the upcall works for them.
History: the unix/stream rewrite (d15792780760) lost the read wakeup on
SHUT_WR. Commit 52c0aa086d6b ("unix/stream: shutdown(SHUT_WR) shall trigger
read event on peer", June 2025) restored it for select, poll and kqueue by
adding the open-coded selwakeuppri() and KNOTE_LOCKED() to uipc_cantrcvmore(),
but not the SB_UPCALL half of sowakeup(). So upcall consumers are still
affected; this report is a follow-up to that commit.
Every in-kernel consumer of SO_RCV upcalls on local stream sockets is affected.
We hit it with an out-of-tree io_uring-style module, and krpc's use of AF_LOCAL
transports is a likely in-tree candidate. Userland aio_read(2) on such a socket
does complete, so the bug isn't visible from userland directly.
How to reproduce:
The attached module (unix_shutdown_upcall.c, about 100 lines) creates a socket
pair with socreate() and soconnect2(), installs a counting upcall on one end's
SO_RCV, sends one byte from the other end, and then calls soshutdown(SHUT_WR)
on that end. Build it with this Makefile:
KMOD= unix_shutdown_upcall
SRCS= unix_shutdown_upcall.c
.include <bsd.kmod.mk>
On 15.1-RELEASE-p6 (GENERIC-DEBUG):
# make && kldload ./unix_shutdown_upcall.ko
kldload: an error occurred while loading module ./unix_shutdown_upcall.ko.
Please check dmesg(8) for more details.
# dmesg | tail -4
unix_shutdown_upcall: upcalls after data: 1 (expect >= 1)
unix_shutdown_upcall: after peer SHUT_WR: 0 new, SBS_CANTRCVMORE set
unix_shutdown_upcall: BUG: SHUT_WR set SBS_CANTRCVMORE but ran no SO_RCV upcall
module_register_init: MOD_LOAD (unix_shutdown_upcall, 0xffffffff84248000, 0)
error 5
(The module fails its load with EIO when the bug is present, so it's never left
loaded. It prints OK and loads when the bug is fixed.)
Expected: the peer's SO_RCV upcall runs once its receive side is marked
SBS_CANTRCVMORE, as it does with socantrcvmore() for TCP, and as it does on
AF_UNIX for data and for close(2).
Suggested fix: have uipc_cantrcvmore() run the full receive wakeup. For
example, keep its locking and replace the two lines 52c0aa086d6b added with
what sorwakeup_locked() does, or call sowakeup(so, SO_RCV) there (it drops the
receive buffer lock), and then take the uipc_wakeup_writer() step under the
lock again. We haven't tested a patch.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads