Article View: muc.lists.freebsd.bugs
Article #799[Bug 301189] sctp_iterator_work() drops the inp reference at entry, so a close racing sctp_sendall_completes() locks a freed inp
From: 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
Technical Details
Message-ID:
<bug-301189-227@https.bugs.freebsd.org/bugzilla/>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail From: bugzilla-noreply@freebsd.org Newsgroups: muc.lists.freebsd.bugs Subject: [Bug 301189] sctp_iterator_work() drops the inp reference at entry, so a close racing sctp_sendall_completes() locks a freed inp Date: Fri, 27 Nov 2026 15:25:28 +0000 Organization: Newsgate at muc.de e.V. Approved: news-admin@muc.de Distribution: world Message-ID: <bug-301189-227@https.bugs.freebsd.org/bugzilla/> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2"; logging-data="25574"; mail-complaints-to="news-admin@muc.de" X-Original-To: bugs@mlmmj.nyi.freebsd.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795793128; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TmzDWPsKX+hpBEV32EhRqPrslc716yt3e2zhCFqkmNg=; b=sUyDlqeEq/2B2x2Qg5aJ00Dqg5K4hSh2g1dTeUW0TbFnMmA/o92Veo2QYZjxKbV/+b8wTM /W25fBAXWgOqwAIu0YNtDQ5n4qqCDK3MyRl85SSHgL7SpQsGYKweixl45/jH4LPXB5/0BI kt1NcyW9Im/30ByLB4KNmAPr9WbVcDUYq4ckUAo96+HgbqijVliKv8nnL/qryHn/QyQm+Y kHwXDN+W8l0nyu1dmSrxep0klnUql9i88Y4WbtX0jCyEHRNgQB0osQDQXCmWmDu+ZzvJh5 Q6hkTOQ2tM7bpf0hHA35ajGjOz5ihUn/vWj429yd1QiTQTh2vFJuJxglzSQS3A== X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f Auto-Submitted: auto-generated Precedence: list X-Newsgate-Id: f02c70b8849f+ X-No-Archive: Yes