🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: muc.lists.freebsd.bugs
Article #831

[Bug 301234] sys_sctp_generic_recvmsg() copies uninitialized kernel stack out as the peer address on EOF

#831
From: bugzilla-noreply
Date: Sat, 28 Nov 2026 14:59
107 lines
6398 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301234

            Bug ID: 301234
           Summary: sys_sctp_generic_recvmsg() copies uninitialized kernel
                    stack out as the peer address on EOF
           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

On EOF, sys_sctp_generic_recvmsg() reads the stale first byte of
its stack buffer as sa_len and copyout()s that many
uninitialized bytes to the caller.

uint8_t sockbufstore[256] in sys/netinet/sctp_syscalls.c (main
44de1df2a033; releng/15.1 bb03631fe3b7) is aliased to fromsa
and never zeroed. sctp_sorecvmsg() returns 0 at EOF without
writing from, and the syscall then does len = MIN(len,
fromsa->sa_len) and copyout()s len bytes. sa_len is one byte:
one call copies at most 255 bytes, only when the stale byte is
255. recvfrom() does not: sctp_soreceive() sets from->sa_len
= 0 first (sctputil.c 6566 on that main, 6573 on releng/15.1).
The syscall is SYF_CAPENABLED; loading sctp.ko takes privilege,
the call after that does not.

sctp_recvmsg_leak.c prints the controls before EOF; the data
call was ret=1 fromlen=28 sa_family=28.

$ cc -Wall -Wextra -Werror -o sctp_recvmsg_leak sctp_recvmsg_leak.c
$ ./sctp_recvmsg_leak

FreeBSD 15.1-RELEASE-p7 GENERIC amd64
(releng/15.1-n283696-bb03631fe3b7):

[PASS] Control 1 (recvfrom / sctp_soreceive at EOF): ret=0 fromlen=0
from[0]=0xaa
[FAIL] Case 1 (sctp_generic_recvmsg at EOF): leaked up to 255 bytes of kernel
stack (first_word=0x0000ffffffffffff, first_kptr=0xfffffe00d1343ca0,
kptrs_found=16)
[FAIL] Case 2 (Capsicum cap_enter EOF): leaked up to 255 bytes of kernel stack
(first_word=0x0000ffffffffffff, first_kptr=0xfffffe00d1343ca0, kptrs_found=16)

Both EOF calls copied 255 bytes. kldstat and nm of the
world-readable kernel resolved leaked frames to live return
addresses (_sleep+0x1e1, dofilewrite+0x81, kern_sendit+0x1c0,
_fdrop+0x46, closef+0x24a, fget_cap+0x45, sogetopt+0x1a6) and
to kernel-map and direct-map pointers. 15.1-RELEASE-p6 arm64
(releng/15.1-n283643-95719d8a895b) returned 255 bytes the same
way, with 11 kernel-map pointers, the first
0xffff000088ffd810; that kernel's canary is per thread, and it
was not in those bytes. 16.0-CURRENT GENERIC amd64
(main-n287061-65251c43415a), as nobody in a jail, returned a
longest copy of 161 bytes (10 pointers).

On that same boot, sctp_recvmsg_canary.c primed with sendto()
of a 255-byte stack address and printed:

live __stack_chk_guard addr = 0xffffffff82206c50 (size 0x40)
  child0: iter=3 fromlen=246 word0=0x1012556d34a251f6 kmap=11 dmap=4
  child1: iter=3 fromlen=246 word0=0x1012556d34a251f6 kmap=11 dmap=4
  child2: iter=3 fromlen=246 word0=0x1012556d34a251f6 kmap=11 dmap=4
[PASS] canary word identical across 3 fresh kernel stacks: 0x1012556d34a251f6

kldsym(2) needs no privilege for that address; reading /dev/kmem
there does. As root on that boot the first 8 bytes were
0x1012556d34a251f6, stable across more than 20 runs on this
boot only. On 15.1-RELEASE-p7 the canary slot sits one byte
past the window.

The patch zeroes all 256 bytes of sockbufstore, not just
sa_len: sctp_sorecvmsg() memcpy()s only min(fromlen, len)
bytes into the buffer (sys/netinet/sctputil.c), so a short
fromlen replaces sa_len and leaves the tail stale, and
ktrsockaddr() records sa_len bytes of that tail; the ktrace
call is skipped unless fromlen and sa_len are greater than
0. tests/sys/netinet/sctp_generic_recvmsg.c checks that the
EOF length is 0 and the caller buffer is unchanged, and that
a real message still returns the peer address. I built
sctp.ko from the releng/15.1 sources with this patch's kernel
hunk and ran it on 15.1-RELEASE-p7: both EOF cases return
fromlen 0, the data control is unchanged, and the test passes
both cases under kyua. Under ktrace the stock module writes a
garbage sockaddr record for the EOF call, the patched module
writes none. Not run: the patched module on 16.0-CURRENT or
arm64, or the installed sctp.ko binary.

-- 
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-301234-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!news.szaf.org!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail

Show 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!news.szaf.org!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 301234] sys_sctp_generic_recvmsg() copies uninitialized kernel
 stack out as the peer address on EOF
Date: Sat, 28 Nov 2026 14:59:22 +0000
Organization: Newsgate at muc.de e.V.
Approved: news-admin@muc.de
Distribution: world
Message-ID: <bug-301234-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="10114"; 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=1795877962;
	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=sKT94cY3lW4zFYA1i89sQMv7x8T2IYzmtCE9Q09860M=;
	b=FpT+E3ec0uZZpyfX3Kly1iojl4WLV9urAzdAWHGFHb4+i1sGLr48E1J9JeYG7g6spMTBkZ
	48gjrtZXNoHtix5+Iyqqd6XXaLXDwDAXhhgTDRCQMwAvWMNiTNQ9xIBARpDYci5HhLD3RK
	/5sFG5VVV5GK/GafltWsLQZsDV93/zdso43Q4bTJ4qCfUZiNP4f160xc6e7NBwL3Eg8nUI
	vOnanEbbByNGYpM4L34okL9biuvadveGx0/737xWD9zHke94KgIejYB5W1Uv8XB+QjTXOB
	07cYRXqE2B9BFT+zQBiACmXVjQLMADu6eQnBbYZsCE+S3/Au4KgZ1EHqRBOJGg==
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