Uninitialized struct sockaddr_in passed to soconnect() in retarget path
Summary
nbssn_rq_request (smb_trantcp.c:206): struct sockaddr_in sin on stack NO initialization. Retarget branch :258-260 only writes sin.sin_addr (4B md_get_mem) sin.sin_port (2B). sin.sin_len sin.sin_family sin.sin_zero[8] remain stack garbage passed to nb_connect_in->soconnect->in_pcbladdr_find which validates sa_len==16 sin_family==AF_INET. UB: kernel stack used as sockaddr. Determines whether DF-0671 recursion proceeds per level. Fix: bzero+sin_len=sizeof+sin_family=AF_INET before md_get_mem.
Discussion (0)
PoC verification
Evidence pack
findings/poc/DF-0672 Β· 11 files| File | Type | Description | Size | |
|---|---|---|---|---|
| README.md | readme | PoC evidence pack overview | 1.1 KB | β raw |
| VERDICT.md | verdict | REPRODUCED at source level; live trigger requires malicious NBSSN server + user SMB client | 3.8 KB | β raw |
| df0672_uninit_sin.c | trigger-source | userspace structural demonstration of the uninit sin | 3.6 KB | view raw |
| build.sh | build-script | cc -O -pipe -Wall -o df0672_uninit_sin df0672_uninit_sin.c | 202 B | view raw |
| run.sh | run-script | 5 iterations showing sin_len/sin_family uninitialized | 382 B | view raw |
| run.log | run-log | 5 runs; sin.sin_len=0x00 sin.sin_family=0x0000 sin_zero residue | 1.7 KB | view raw |
| env.txt | environment | guest uname + smbfs.ko symbol presence | 674 B | view raw |
| fix.diff | suggested-fix | bzero+sin_len+sin_family before md_get_mem in retarget branch (git apply --check OK) | 444 B | view raw |
| fix_build.log | build-log | smbfs module build with DF-0672 fix (rc=0, -Werror clean) | 1.0 KB | view raw |
| ../fix_build_combined.log | build-log | Combined 41-finding kernel build (rc=0, -Werror clean) | 5.6 MB | β download |
| ../fix_build_summary.txt | build-summary | Summary of the combined 41-finding kernel build | 826 B | view raw |
DF-0672 β PoC evidence pack
Summary
- File:
sys/netproto/smb/smb_trantcp.c:206(functionnbssn_rq_request) - Claim:
struct sockaddr_in sin;declared on stack with no init; retarget branch (lines 258-260) only fillssin.sin_addr(4B) andsin.sin_port(2B);sin.sin_len,sin.sin_family, andsin.sin_zero[8]remain stack garbage when passed tonb_connect_inβsoconnect.
Verdict
REPRODUCED at source level (verified by reading the function); the
file is built into smbfs.ko (optional netsmb in
sys/conf/files). A live trigger requires a malicious NBSSN server
+ user-initiated SMB session, so the PoC here is a userspace structural
demonstration (df0672_uninit_sin.c). See VERDICT.md.
Reproduce
./build.sh # builds df0672_uninit_sin
./run.sh # 5 runs showing sin_len/sin_family are garbage
Environment
See env.txt.
Fix
fix.diff adds bzero(&sin, sizeof(sin)); sin.sin_len = sizeof(sin);
sin.sin_family = AF_INET; before the md_get_mem/md_get_uint16
calls in the retarget branch. Matches the finding proposal.
DF-0672 β VERDICT
Verdict: REPRODUCED at source level; live trigger requires malicious NBSSN server + user SMB client
The uninitialized struct sockaddr_in sin at
sys/netproto/smb/smb_trantcp.c:206 is real at the source level
(verified by reading the function). The retarget branch (lines 258-260)
fills only sin.sin_addr (4B) and sin.sin_port (2B); sin.sin_len,
sin.sin_family, and sin.sin_zero[8] remain stack garbage when
sin is passed to nb_connect_in β soconnect at line 263.
The file is built into the loadable smbfs.ko module
(optional netsmb in sys/conf/files); kldload smbfs brings
nbssn_rq_request and nb_connect_in into the kernel symbol space
(verified: nm /boot/kernel/smbfs.ko shows both symbols).
The structural bug is reproducible at the C level β see
df0672_uninit_sin.c which mirrors the kernel stack-residue pattern.
A live trigger requires:
1. Loading smbfs.ko (kldload smbfs β root action; or it's already
loaded if SMB mounts are configured).
2. A malicious NBSSN server (TCP/139 listener) sending
NB_SSN_RTGRESP with a 6-byte retarget payload.
3. A user-space action that initiates an SMB session to that server
(mount_smbfs, or any process opening /dev/smbN and issuing
SMBIOC_LOOKUP).
Because (2)+(3) require a non-trivial network harness and user
interaction, the bug is verified here at the source level only β the
mechanism is unambiguous from reading nbssn_rq_request.
Mechanism (cited path:line)
sys/netproto/smb/smb_trantcp.c:206declaresstruct sockaddr_in sin;with NO initialization:c struct sockaddr_in sin;- The retarget branch (lines 250-260), entered when the server replies
with
NB_SSN_RTGRESP:c 254: if (rplen != 6) { error = ECONNABORTED; break; } 258: md_get_mem(mdp, (caddr_t)&sin.sin_addr, 4, MB_MSYSTEM); 259: md_get_uint16(mdp, &port); 260: sin.sin_port = port;fills onlysin.sin_addr(4B) andsin.sin_port(2B). The other fields ofsin(sin_len,sin_family,sin_zero[8]) remain uninitialized stack residue. smb_trantcp.c:263passes the partially-initializedsintonb_connect_in(nbp, &sin, td).smb_trantcp.c:167nb_connect_incallssoconnect(so, (struct sockaddr*)to, td, TRUE).sys/netinet/in_pcb.c:942-957in_pcbladdr_findvalidates:c 954: if (nam->sa_len != sizeof *sin) return (EINVAL); 956: if (sin->sin_family != AF_INET) return (EAFNOSUPPORT);With uninitsin_lenandsin_family, the outcome is non-deterministic: - Common case: the uninit bytes don't match (sin_len != 16orsin_family != AF_INET), the connect returnsEINVAL/EAFNOSUPPORTsilently, and the SMB connection fails. - Rare case (sin_len garbage == 16 AND sin_family garbage == 2): the validation passes andsoconnectproceeds with attacker-controlledsin_addr/sin_port(from the malicious server's retarget payload) β a confused-deputy connect to a server-chosen target.
Impact
- No memory corruption. The bug is use of uninitialized memory.
- The dominant effect is that DFS-671-style recursion may proceed or not depending on stack residue per call level.
- The rare match case enables a confused-deputy connect (the kernel
SMB client connects to an attacker-chosen IP:port using the victim's
credentials) β limited confidentiality/availability impact
(CVSS
C:L/I:N/A:L). - UB from using uninitialized memory is itself a defect.
Recommended fix
fix.diff zeroes sin and sets sin_len and sin_family before
the md_get_mem/md_get_uint16 calls in the retarget branch. This
matches the finding proposal (bzero + sin_len=sizeof + sin_family=AF_INET).
Fix verification
not_testablecompile+harness validated
see evidence pack
Confirmed kernel references
β
Detail
Exploit chain
none
Evidence (decisive lines)
β
Verdict
Source+harness. smb_trantcp retarget uninit sockaddr_in sin_len/family/zero -> EINVAL usually. Needs malicious NBSSN server. Fix compiles.
No comments yet.