🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: muc.lists.freebsd.bugs
5 messages
5 total messages Started by bugzilla-noreply Sat, 28 Nov 2026 14:59
[Bug 301234] sys_sctp_generic_recvmsg() copies uninitialized kernel stack out as the peer address on EOF
#831
Author: 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
[Bug 301234] sys_sctp_generic_recvmsg() copies uninitialized kernel stack out as the peer address on EOF
#832
Author: bugzilla-noreply
Date: Sat, 28 Nov 2026 14:59
18 lines
2561 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301234

--- Comment #1 from laamalif@proton.me ---
Created attachment 277897
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277897&action=edit
zero the 256-byte sockbufstore in sys_sctp_generic_recvmsg() and skip the
ktrsockaddr call when the returned address length is 0; adds the regression
test

-- 
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 301234] sys_sctp_generic_recvmsg() copies uninitialized kernel stack out as the peer address on EOF
#833
Author: bugzilla-noreply
Date: Sat, 28 Nov 2026 14:59
19 lines
2610 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301234

--- Comment #2 from laamalif@proton.me ---
Created attachment 277898
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277898&action=edit
reproducer: five EOF recvmsg calls report the returned fromlen and classify the
leaked bytes (kernel-map pointers, direct-map, canary word); controls included

-- 
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 301234] sys_sctp_generic_recvmsg() copies uninitialized kernel stack out as the peer address on EOF
#834
Author: bugzilla-noreply
Date: Sat, 28 Nov 2026 14:59
18 lines
2562 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301234

--- Comment #3 from laamalif@proton.me ---
Created attachment 277899
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277899&action=edit
16.0-CURRENT canary probe: reads __stack_chk_guard[0]'s address with kldsym(2)
and compares the leaked first word

-- 
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 301234] sys_sctp_generic_recvmsg() copies uninitialized kernel stack out as the peer address on EOF
#835
Author: bugzilla-noreply
Date: Sat, 28 Nov 2026 14:59
19 lines
2612 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301234

--- Comment #4 from laamalif@proton.me ---
Created attachment 277900
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277900&action=edit
ATF regression test: the EOF call must return fromlen 0 without writing the
caller buffer; a real message must return the peer address (same file as in the
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