Thread View: muc.lists.freebsd.bugs
6 messages
6 total messages
Started by bugzilla-noreply
Fri, 27 Nov 2026 15:25
[Bug 301189] sctp_iterator_work() drops the inp reference at entry, so a close racing sctp_sendall_completes() locks a freed inp
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 15:25
Date: Fri, 27 Nov 2026 15:25
89 lines
6082 bytes
6082 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301189
Bug ID: 301189
Summary: sctp_iterator_work() drops the inp reference at entry,
so a close racing sctp_sendall_completes() locks a
freed inp
Product: Base System
Version: 15.1-RELEASE
Hardware: Any
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: kern
Assignee: bugs@FreeBSD.org
Reporter: laamalif@proton.me
sctp_sendall_completes() locks the inp after sctp_iterator_work()
dropped the last reference, so a racing close frees it first
sctp_iterator_work() drops the reference the iterator holds on the
inp at entry (SCTP_INP_DECR_REF at sys/netinet/sctputil.c:1463) and
then, at done_with_iterator (:1467-1476), releases the iterator and
inp_info locks before calling it->function_atend. For SCTP_SENDALL
that callback is sctp_sendall_completes()
(sys/netinet/sctp_output.c:6851 on main; the stock 15.1 trace
below shows the same statement at :6858), which does
SCTP_INP_WLOCK(ca->inp) at :6868 on main, :6858 on releng/15.1,
with no reference left. A close() that reaches sctp_inpcb_free()
in that window passes the refcount gate (sys/netinet/sctp_pcb.c:3469
on main, :3461 on releng/15.1 - the count is already 0), destroys
the mutex (:3572 main, :3564 on releng/15.1) and frees the inp
(:3575 main, :3567 on releng/15.1) while the iterator is locking it.
Reproduced on FreeBSD 15.1-RELEASE-p7 GENERIC amd64, unprivileged
(sctp.ko loaded), by racing the sendall against close():
panic: page fault
fault virtual address = 0x488
current process = 1882 (sctp_iterator)
#8 __mtx_lock_sleep (v=4) at kern_mutex.c:627
#9 sctp_sendall_completes at sctp_output.c:6858
#10 sctp_iterator_work at sctputil.c:1472
The 4 is MTX_DESTROYED, written by SCTP_INP_LOCK_DESTROY in the
free path before the zone free; the CAS in sctp_sendall_completes()
reads it, and the adaptive-mutex owner check dereferences
lv_mtx_owner(4) = NULL into NULL->td_state (0x488 is
offsetof(struct thread, td_state), verified in the dump). I hit the
same panic twice (second run: process 1766, a different inp and a
different CPU), about 90 seconds into each sendall+close loop. The
access the INVARIANTS and KASAN builds take at the same point is the
use-after-free syzbot has been reporting since 2022
(https://syzkaller.appspot.com/bug?extid=583ce35a13ec4552b187
write, https://syzkaller.appspot.com/bug?extid=8a3ead6aa115945e43fc
read; both entries still reproduce there).
The reproducer uses the minimized trigger: a one-to-many SCTP
socket with setsockopt(SCTP_DEFAULT_SNDINFO, snd_flags = EOF |
SENDALL) makes write(2) take the sendall path, and a second thread
closes the socket at a fixed delay after the write returns. The
control (close without SENDALL) does not crash.
The attached patch keeps the enqueue-time reference
(sctp_pcb.c:6960 on main, :6946 on releng/15.1) until the
iterator is done with the endpoint: it
moves the drop after function_atend at done_with_iterator and adds
drops at the two places a multi-inp iterator advances to the next
endpoint. A close racing the completes then sees refcount != 0 at
the gate and defers the free to the INPKILL timer. Built as a
module on 15.1 (releng/15.1-n283696-bb03631fe3b7 sources) and
exercised: 50000 close-at-write-return pairs plus a 0-12us delay
sweep, no panic, and vm.uma.sctp_ep allocs == frees == 103002 with
current 0 afterwards. On 16.0-CURRENT the same patch built against
main as a KASAN module survived 20000 pairs with dtrace showing the
gate deferring frees. Not tested: the asconf multi-inp walk under
address churn (the lockless LIST_NEXT in
sctp_iterator_inp_being_freed() is a separate defect; the queued
branch there needs no fix, its function_atend runs before any lock
or refcount check).
--
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
[Bug 301189] sctp_iterator_work() drops the inp reference at entry, so a close racing sctp_sendall_completes() locks a freed inp
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 15:25
Date: Fri, 27 Nov 2026 15:25
17 lines
2577 bytes
2577 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301189 --- Comment #1 from laamalif@proton.me --- Created attachment 277811 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277811&action=edit hold the enqueue reference through function_atend and the two advance sites; the entry DECR is removed -- 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
[Bug 301189] sctp_iterator_work() drops the inp reference at entry, so a close racing sctp_sendall_completes() locks a freed inp
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 15:25
Date: Fri, 27 Nov 2026 15:25
19 lines
2650 bytes
2650 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301189 --- Comment #2 from laamalif@proton.me --- Created attachment 277812 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277812&action=edit reproducer: setsockopt(SCTP_DEFAULT_SNDINFO, EOF|SENDALL) makes write(2) take the sendall path; a closer thread races the close. --no-sendall runs the plain-sendto control -- 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
[Bug 301189] sctp_iterator_work() drops the inp reference at entry, so a close racing sctp_sendall_completes() locks a freed inp
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 15:25
Date: Fri, 27 Nov 2026 15:25
17 lines
2556 bytes
2556 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301189 --- Comment #3 from laamalif@proton.me --- Created attachment 277813 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277813&action=edit crash dump excerpt, run 1: the v=4 NULL-owner fault at sctp_sendall_completes -- 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
[Bug 301189] sctp_iterator_work() drops the inp reference at entry, so a close racing sctp_sendall_completes() locks a freed inp
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 15:25
Date: Fri, 27 Nov 2026 15:25
16 lines
2541 bytes
2541 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301189 --- Comment #4 from laamalif@proton.me --- Created attachment 277814 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277814&action=edit crash dump excerpt, run 2: the same fault, a different boot/inp/CPU -- 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
[Bug 301189] sctp_iterator_work() drops the inp reference at entry, so a close racing sctp_sendall_completes() locks a freed inp
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 15:58
Date: Fri, 27 Nov 2026 15:58
16 lines
2563 bytes
2563 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301189
Mark Linimon <linimon@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|bugs@FreeBSD.org |net@FreeBSD.org
--
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