Repository navigation
Open
Description
Reported by @paolobarbolini. Open the ticket first, then I will go through them one by one and handle them accordingly.
nix 0.31.2 Security & Soundness Audit
Date: 2026-04-12 through 2026-04-13
Scope: All src/ files + dependencies (libc, bitflags, cfg-if, memoffset, pin-utils)
Method: Manual review of all unsafe code, cargo geiger, cargo audit
cargo geiger summary: 46/2039 unsafe expressions, 0/16 unsafe fn used in build
CRITICAL
C1. dup2_raw missing error check — wraps -1 in OwnedFd
- File:
src/unistd.rs:625-639 - GitHub: No existing issue or PR.
libc::dup2returns -1 on error. The code never checks for this and unconditionally wraps the return value inOwnedFd::from_raw_fd(duplicated_fd). This creates anOwnedFdholding fd -1. When dropped,close(-1)is called. Compare withdup3_raw(line 710) which correctly callsErrno::result(res)?first.- Impact: UB via invalid OwnedFd; potential close of wrong fd in multithreaded programs.
C2. SigSet::wait() uses wrong error convention for sigwait(3)
- File:
src/sys/signal.rs:587-596 - GitHub: No existing issue or PR.
sigwait(3)returns 0 on success and a positive errno on failure. It does NOT return -1 and set errno. But the code usesErrno::result(res), which only checks for -1. Since sigwait never returns -1, errors (e.g. EINVAL) are treated as success, and the code proceeds tosignum.assume_init()on an uninitializedMaybeUninit<c_int>— instant UB.- Impact: Undefined behavior when sigwait fails. Reading uninitialized memory.
C3. sendmmsg returns iterator that calls assume_init() on never-initialized addresses
- File:
src/sys/socket/mod.rs:1826,1991 - GitHub: No existing issue for this specific bug. Related but different: #2176 (sendmmsg control message buffer overflow), #2031 (sendmmsg panic), #2030 (sendmmsg docs).
sendmmsg()returnsMultiResultswhose.next()callsself.rmm.addresses[i].assume_init(). Butsendmmsgnever writes toMultiHeaders.addresses— they remainMaybeUninit::uninit()frompreallocate(). The comment on line 1989 says "written by recvmmsg" but this code path issendmmsg.- Impact: UB (assume_init on uninit) reachable from safe code by iterating sendmmsg results.
C4. Use-after-free in openlog on non-Linux platforms
- File:
src/syslog.rs:45-63 - GitHub: Known/discussed but no fix. #2597 (open) mentions openlog's lifetime problem as motivation for a new trait. PR #2537 review comments identified the dangling pointer issue.
- The non-Linux
openlogvariant passes a temporaryCStrpointer (fromwith_nix_pathclosure) tolibc::openlog. Per POSIX,openlogstores theidentpointer and dereferences it later duringsyslog()calls. The temporary is freed when the closure returns. Any subsequentsyslog()call dereferences a dangling pointer. The Linux variant correctly requires&'static CStr, but the non-Linux variant accepts any&S where S: AsRef<OsStr>— no lifetime restriction. Triggerable from safe code. - Impact: Use-after-free on every non-Linux platform (BSDs, macOS, etc).
C5. lio_listio fat-to-thin pointer cast corrupts kernel arguments (deprecated)
- File:
src/sys/aio.rs:1214-1215 - GitHub: Known. #1980 (closed) identified the fat-to-thin pointer bug. PR #2019 (merged) fixed
aio_suspendand deprecatedlio_listio. #2017 (open) tracks lio_listio redesign. Pin<&mut dyn AsMut<libc::aiocb>>is a fat pointer (16 bytes on 64-bit: data ptr + vtable ptr). The code casts the slice to*mut [*mut libc::aiocb]— an array of thin (8-byte) pointers. The kernel reads alternating data pointers and vtable pointers asaiocb*values, following vtable addresses as aiocb structures. Function is deprecated but still public and callable from safe code.- Impact: Memory corruption / arbitrary kernel-memory dereference from safe code.
HIGH
H1. UnixCredentials::groups() on FreeBSD — OOB slice from safe code
- File:
src/sys/socket/mod.rs:498-511 - GitHub: No existing issue or PR.
groups()creates a slice with lengthcmcred_ngroups as usize. TheFrom<libc::cmsgcred>impl (line 508-511) allows safe code to constructUnixCredentialswith arbitrarycmcred_ngroups. A negativec_shortwraps to a hugeusize; a value larger thanCMCRED_MAX_GROUPSreads past the array.- Impact: Out-of-bounds read from safe code. Soundness hole.
H2. AlgAddr::alg_type() / alg_name() — CStr::from_ptr reads past array bounds
- File:
src/sys/socket/addr.rs:1700-1707 - GitHub: No existing issue or PR.
- Both methods use
CStr::from_ptrto scan for NUL in fixed-size arrays (salg_type= 14 bytes,salg_name= 64 bytes). If the array is completely filled (no NUL), the scan continues into adjacent struct fields or past the allocation.AlgAddr::new()(line 1688) does not validate that inputs leave room for NUL, making this triggerable from safe code with a 14-bytealg_typeor 64-bytealg_name. - Impact: Out-of-bounds read, potentially returning garbage data from adjacent fields.
H3. AlgSetIv control message length mismatch
- File:
src/sys/socket/mod.rs:1512-1513 - GitHub: #1960 (open) — "ControlMessage::len() likely incorrect for AlgSetIv". Filed 2023-01-08, zero comments.
len()forControlMessage::AlgSetIv(iv)returnsmem::size_of::<&[u8]>() + iv.len(). A&[u8]is 16 bytes on 64-bit (fat pointer). But the actual data written incopy_to_cmsg_dataissize_of::<libc::af_alg_iv>()(~4 bytes) +iv.len(). The cmsg header gets an inflated length, causing 12 extra uninitialized bytes to be sent to the kernel.- Impact: Information leak (uninitialized memory sent to kernel), incorrect cmsg metadata.
H4. SigAction::new leaves sa_restorer field uninitialized
- File:
src/sys/signal.rs:852-864 - GitHub: Partially covered by #2720 (open) — "Various soundness bugs related to
MaybeUninit::uninit, partial initialization, then.assume_init()". Does not specifically mentionSigAction/sa_restorer. - Creates
MaybeUninit::<libc::sigaction>::uninit(), only initializessa_sigaction,sa_flags,sa_mask. On Linux,sa_restorer(a function pointer) is left uninitialized. The struct is then passed tolibc::sigaction(). Reading uninitialized bytes is UB. - Fix: Use
MaybeUninit::zeroed()instead ofuninit().
H5. SigAction::handler() pointer type-punning through local variable
- File:
src/sys/signal.rs:879-909 - GitHub: No existing issue or PR.
- Converts
usizeback to function pointer by casting&p as *const usize as *const extern "C" fn(...)and dereferencing. This is a type-pun through pointer cast.handler()is safe but can be called onSigActionreturned from unsafesigaction(), where the kernel-suppliedsa_sigactionvalue is blindly reinterpreted as a function pointer. - Impact: Potential UB if kernel returns non-standard handler values.
H6. SendfileVec::newself allows arbitrary memory reads from safe code (Solaris/illumos)
- File:
src/sys/sendfile.rs:136-141 - GitHub: No existing issue or PR.
- Safe public function that constructs a
sendfilevec_twithsfv_fd = SFV_FD_SELF. When passed to safesendfilev(), the kernel readslenbytes from addressoffin the process's address space and sends them to a socket. This allows reading arbitrary process memory without anyunsafeblock. - Impact: Soundness hole — safe code can read arbitrary memory.
H7. From<User> for libc::passwd leaks memory unconditionally
- File:
src/unistd.rs:3629-3696 - GitHub: Related but different: #1977 (open) — "
Fromimpls that takelibctypes are unsound". That issue covers the reverse direction (From<libc::passwd> for User), not the leak inFrom<User> for libc::passwd. - Calls
.into_raw()on multipleCStringvalues to produce raw*mut c_charpointers forlibc::passwdstruct fields. These leaked heap allocations can never be reclaimed sincelibc::passwdhas noDropimpl. - Impact: Guaranteed memory leak on every conversion. Not UB but a significant resource bug.
H8. Stack buffer overflow in workaround_xnu_bug (apple_targets)
- File:
src/ifaddrs.rs:57-83 - GitHub: No existing issue for the overflow. PR #1788 (merged) introduced the function to fix #1709, but did not address the overflow when
sa_len > sizeof(sockaddr_storage). copy_nonoverlappingcopies(*src_sock).sa_lenbytes (u8, max 255) into aMaybeUninit<sockaddr_storage>(128 bytes). No bounds check. If kernel returnssa_len > 128, this overflows the stack buffer.- Impact: Stack buffer overflow from kernel-controlled data on Apple platforms.
H9. MqAttr::new calls assume_init() on struct with uninitialized padding
- File:
src/mqueue.rs:111-121 - GitHub: #2720 (open) — explicitly calls out
mq_attratsrc/mqueue.rs#L111-L121as "the most problematic" instance. MaybeUninit::<libc::mq_attr>::uninit()is used, then only 4 of the fields are set. On Linux/glibc,mq_attrhas additional padding fields (__pad1through__pad4) left uninitialized.assume_init()on partially-initialized memory is UB. The struct also derivesEq, Hash, PartialEqwhich would compare/hash uninitialized padding.- Fix: Use
MaybeUninit::zeroed().
H10. AioReadv/AioWritev iovec array use-after-free (FreeBSD)
- File:
src/sys/aio.rs:702-710, 930-942 - GitHub: No existing issue or PR. Verified:
cargo check --target x86_64-unknown-freebsdpasses with a repro crate that dropsbufswhileAioReadvsurvives. AioReadv::newstoresbufs.as_mut_ptr()(a pointer into the caller's&mut [IoSliceMut]slice) inaio_buf. But the outer borrow ofbufsis NOT tied to lifetime'aof the returned struct. Afternewreturns, the caller can drop thebufsslice, andaio_bufbecomes a dangling pointer. Same issue forAioWritev. The inner data buffers are lifetime-bound, but the iovec array itself is not.- Impact: Use-after-free when the kernel reads the iovec array during AIO submission. FreeBSD only.
H11. AsMut<libc::aiocb> allows safe buffer pointer corruption
- File:
src/sys/aio.rs:611-614(and 734, 846, 966) - GitHub: No existing issue or PR.
- All AIO types implement
AsMut<libc::aiocb>, exposing&mut libc::aiocbto safe code. A caller can overwriteaio_bufto point to arbitrary memory, then pin and submit. The kernel reads/writes the attacker-controlled address. Entirely in safe Rust. - Impact: Arbitrary read/write primitive from safe code.
H12. lio_listio dangling pointer to temporary sigevent (deprecated)
- File:
src/sys/aio.rs:1217 - GitHub: No specific issue. #2017 (open) tracks lio_listio redesign but does not mention the dangling sigevent.
sigev.sigevent()returnslibc::sigeventby value.&mut sigev.sigevent() as *mutcreates a pointer to a temporary that is dropped at the end of the statement.sigevpis dangling when passed tolibc::lio_listio.- Impact: Use-after-free of stack memory passed to kernel. Function is deprecated but public.
H13. Nmount::nmount() dangling pointer on repeated calls (FreeBSD)
- File:
src/mount/bsd_without_apple.rs:357-386 - GitHub: No existing issue or PR. Verified:
cargo check --target x86_64-unknown-freebsdpasses with a repro crate that callsnmount()twice. nmount()pushes iov entries pointing to a localerrmsgVec. When the function returns,errmsgis dropped but the iov entries remain inself.iov. A second call tonmount()passes dangling pointers to the kernel. Also desynchronizesiovandis_ownedvectors (missingpushtois_ownedat line 367), potentially causingDropto callCString::from_rawon wrong pointers. Triggerable from safe code (nmounttakes&mut self).- Impact: Use-after-free / dangling pointer passed to kernel. Unsound Drop.
MEDIUM
M1. VsockAddr::PartialEq compares self.svm_len against itself (Apple)
- File:
src/sys/socket/addr.rs:2094-2108 - GitHub: No existing issue or PR.
- On Apple targets, line 2106 compares
inner.svm_lenwith itself instead ofother.svm_len. TwoVsockAddrvalues with differentsvm_lenbut identical other fields compare as equal, violating the Eq/Hash contract.
M2. ptrace::getregset calls assume_init() without checking kernel wrote all bytes
- File:
src/sys/ptrace/linux.rs:397-413 - GitHub: #2447 (open) — "
ptrace::getregs&ptrace::getregsetmay lead to UB of uninitialized data read". - Kernel may write fewer bytes than
size_of::<S::Regs>()(setsiov.iov_lento actual). Code unconditionally callsdata.assume_init(). Tail bytes may be uninitialized. - Fix: Zero-init buffer or check
iov.iov_lenafter syscall.
M3. ptrace_get_data + PTRACE_GET_SYSCALL_INFO partial initialization
- File:
src/sys/ptrace/linux.rs:501-513, 576 - GitHub: No existing issue for this specific bug.
- Same pattern as M2: kernel may write fewer bytes than the struct size if running on an older kernel than libc headers were compiled against.
M4. decode_from cmsg length underflow
- File:
src/sys/socket/mod.rs:1006-1007 - GitHub: No existing issue or PR.
header as usize + cmsg_len as usize - p as usizecan underflow (wrap to huge value) ifcmsg_lenis corrupted. Result is used forslice::from_raw_partslength.
M5. recvfrom / recvmsg call assume_init() on partially-written addresses
- File:
src/sys/socket/mod.rs:2212, 2424 - GitHub: #2693 (open) — "Soundness Bug (UB): recvfrom wrapper incorrectly uses assume_init on a partially-initialized buffer". Also PR #2249 (open) — fixes recvm(m)sg blindly assuming correct initialization.
- Kernel may write fewer bytes than
size_of::<T>()for the address.assume_init()on the remainder is technically UB.
M6. recv_err_helper uses ptr::offset on potentially out-of-bounds pointer
- File:
src/sys/socket/mod.rs:1187, 1189 - GitHub: No existing issue or PR.
addrp.offset(1)may violate the requirement that both pointers be within the same allocation.
M7. Gid layout assumption in getgroups/setgroups
- File:
src/unistd.rs:1897-1904, 1970-1978 - GitHub: No existing issue or PR.
- Casts
Vec<Gid>pointer togid_t*.Gidisstruct Gid(gid_t)but lacks#[repr(transparent)]. Formally unsound even if it works in practice. Code has FIXME comments acknowledging this.
M8. File descriptor leak in Dir::from_fd on fdopendir failure
- File:
src/dir.rs:107-113 - GitHub: No existing issue or PR.
fd.into_raw_fd()consumes theOwnedFd. Iffdopendirfails, the raw fd is never closed.
M9. Panic on non-UTF-8 paths in fcntl F_GETPATH/F_KINFO
- File:
src/fcntl.rs:918, 930, 939 - GitHub: No existing issue or PR.
- Uses
CStr::to_str().unwrap(). Unix paths can contain arbitrary bytes (except NUL), so this panics on valid non-UTF-8 paths.
M10. BSD LinkAddr::addr() panic with kernel-controlled sdl_nlen
- File:
src/sys/socket/addr.rs:1983-1998 - GitHub: PR #1675 (closed) — "Fix a panic in Linkaddr::addr". May be a prior partial fix.
- Always reads 6 bytes at
data[nlen..nlen+6]but guard only checksnlen + alen >= data_len. Crafted kernel values can cause out-of-bounds index (panic, not UB).
M11. SockaddrStorage::from_raw type-punning sockaddr_storage to UnixAddr
- File:
src/sys/socket/addr.rs:1180-1184 - GitHub: #1866 (closed) — "
SockaddrStoragebroken for variable-length addresses". Also PR #1871 (closed). - Casts
*mut sockaddr_storageto*mut UnixAddrto writesun_len. Relies on exact layout compatibility.
M12. getgrouplist potential set_len on partially-initialized data
- File:
src/unistd.rs:2025-2038 - GitHub: #1541 (closed) — "Memory unsafety in nix::unistd::getgrouplist". Fixed by PR #1542 and PR #1545. The current code is the result of that fix; residual risk of trusting kernel output remains.
- Trusts kernel to have written exactly
ngroupselements beforeset_len.
M13. ioctl buffer size truncation
- File:
src/sys/ioctl/mod.rs:725-736 - GitHub: No existing issue or PR.
- Size encoded in ioctl request code is masked to 14 bits (16383). Larger buffers silently truncate, causing kernel to see wrong size.
M14. if_indextoname error not detected — Errno::result checks for -1, not NULL
- File:
src/net/if_.rs:30-39 - GitHub: No existing issue or PR.
libc::if_indextonamereturns NULL on error. ButErrno::resultfor*mut c_voidchecks against-1isize as *mut c_void(the sentinel), not NULL. Errors silently pass through as success, returning aCStringfrom an unwritten buffer.- Impact: Silent incorrect behavior on error; reads from zero-initialized buffer returned as empty string.
M15. prctl::get_name() mutates through shared reference — UB
- File:
src/sys/prctl.rs:154-165 - GitHub: No existing issue or PR.
let buf = [0u8; 16]; let res = prctl(PR_GET_NAME, &buf, ...)— buffer is immutable but prctl writes through the pointer derived from&buf. This violates Rust's aliasing rules (mutation through shared reference).- Fix: Change to
let mut buf = [0u8; 16]and pass&mut buf.
M16. Invalid enum discriminant UB via GetStruct<SocketTimestamp> (FreeBSD)
- File:
src/sys/socket/sockopt.rs:935-943 - GitHub: No existing issue or PR.
TsClocksocket option usesGetStruct<SocketTimestamp>. Kernel-returned i32 is directly reinterpreted as the#[repr(i32)]enum with only 4 variants (0-3). Values outside this range produce an invalid discriminant — instant UB.- Fix: Use
GetStruct<i32>+TryFrom<i32>likeSockTypedoes.
M17. GetCString::assume_init reads uninitialized buffer bytes (apple_targets)
- File:
src/sys/socket/sockopt.rs:2006-2011 - GitHub: Partially covered by #2720 (open, general
MaybeUninit::uninitpattern). self.val.assume_init()is called on the full buffer, but kernel only wroteself.lenbytes.CStr::from_bytes_until_nulthen scans the entire buffer including uninitialized trailing bytes.- Impact: Reads of uninitialized memory on Apple targets.
M18. EpollEvent::events() panics on unknown kernel flags
- File:
src/sys/epoll.rs:66 - GitHub: #1102 (open) — "Future bit flag extensions can cause program failure". Covers the general
from_bitsunwrap problem. EpollFlags::from_bits(...).unwrap()panics if kernel returns flag bits not known to the bitflags definition. Future kernel extensions would break this.
M19. KEvent::flags() / KEvent::fflags() panic on unknown kernel flags
- File:
src/sys/event.rs:385, 390 - GitHub: #1102 (open, same as M18).
- Same as M18 for kqueue events.
EvFlags::from_bits().unwrap()andFilterFlag::from_bits().unwrap().
M20. Deprecated signalfd() double-close on borrowed fd
- File:
src/sys/signalfd.rs:50-68 - GitHub: #2116 (closed) — "
SignalFd::set_maskcloses the signal file descriptor". Reports the exact double-close bug. - When called with
Some(&existing_fd),signalfdsyscall returns the same fd number. Code wraps it in a newOwnedFd. Now two owners hold the same fd — double-close on drop.
M21. Integer overflow in TimeSpec arithmetic
- File:
src/sys/time.rs:333-337, 412-413, 420-421 - GitHub: PR #2522 (open, draft) — "Use TryFrom for TimeSpec/Duration conversions which may underflow/overflow".
num_nanoseconds()doesnum_seconds() * 1_000_000_000without checked arithmetic.TimeSpec::new()accepts arbitrary values bypassing bounds checks.Add/Subimpls can overflow even with in-range operands. Panics in debug, wraps silently in release.
M22. From<TimeSpec> for Duration — negative values produce wrong Duration
- File:
src/sys/time.rs:222-225 - GitHub: #2479 (open) — "Shouldn't TimeSpec::from_duration preserve monotonicity?". Also PR #1502 (closed without merge) and PR #2522 (draft).
- Negative
tv_seccast tou64wraps to near-max value. Non-normalizedtv_nsec >= 1_000_000_000causesDuration::newto panic. Reachable from safe code.
M23. TimeSpec::new() / TimeVal::new() accept non-normalized values, breaking Ord
- File:
src/sys/time.rs:357-362, 621-626 - GitHub: No existing issue or PR.
- Public constructors accept arbitrary
tv_sec/tv_nsecwithout normalization.Ordimpl assumestv_nsecis in[0, 1_000_000_000). Non-normalized values produce incorrect ordering.
M24. pthread_kill is safe but can cause UB with invalid Pthread
- File:
src/sys/pthread.rs:33-42 - GitHub: No existing issue or PR.
- Not marked
unsafe, but passing aPthreadfor a joined/exited thread is UB per POSIX. On platforms wherepthread_tis a pointer, this dereferences invalid memory.
M25. WaitStatus::from_raw panics on unexpected kernel status
- File:
src/sys/wait.rs:225 - GitHub: No existing issue or PR.
assert!(continued(status))panics if status matches no WIFEXITED/WIFSIGNALED/WIFSTOPPED/WIFCONTINUED. Should return an error.
M26. PollTimeout::as_millis() panics unconditionally on NONE due to eager then_some
- File:
src/poll_timeout.rs:30 - GitHub: No existing issue or PR. Confirmed by running a standalone reproduction.
self.is_some().then_some(u32::try_from(self.0).unwrap())—then_someeagerly evaluates its argument. Whenself.0 == -1(PollTimeout::NONE),u32::try_from(-1).unwrap()panics even thoughis_some()returned false. Also affectsduration()(line 33) andTryFrom<PollTimeout> for Duration. Also aliased asEpollTimeout.- Fix: Change
then_some(...)tothen(|| ...).
M27. AIO no guard against double submit — POSIX UB
- File:
src/sys/aio.rs:404-409 - GitHub: #714 (closed) — "AIOs that fail to enqueue should not be marked as
in_progress". Fixed by PR #715 and later rewrite in PR #1713. Current code may still have the issue post-rewrite. - No check for
in_progressbefore calling the libc submit function. Submitting an already in-progress aiocb is UB per POSIX. Triggerable from safe code.
M28. AIO aio_return clears in_progress before syscall, disabling Drop guard
- File:
src/sys/aio.rs:123-124 - GitHub: No existing issue or PR.
self.in_progress = falseis set BEFORE theaio_returnsyscall. If called while the operation is still in progress, the Drop guard no longer fires, allowing the struct to be dropped while the kernel still holds buffer pointers.
M29. AIO Drop during panic leaks kernel state — use-after-free
- File:
src/sys/aio.rs:206-214 - GitHub: No existing issue or PR.
- When
thread::panicking()is true andin_progressis true, Drop completes silently. The kernel retains buffer pointers whose lifetime is about to expire during stack unwinding.
M30. decode_from missing per-variant length validation before read_unaligned
- File:
src/sys/socket/mod.rs:1001-1174 - GitHub: No existing issue or PR.
- Individual cmsg decode branches (SCM_CREDENTIALS, SCM_TIMESTAMP, SCM_TIMESTAMPING, etc.) use
ptr::read_unalignedwithout checking thatlenis >= the type size. A truncated or corruptedcmsg_lenwould cause reads past valid data.
LOW
L1. SysControlAddr::from_name off-by-one (Apple)
src/sys/socket/addr.rs:1805— allows 96-byte name with no NUL terminator.- GitHub: No existing issue or PR.
L2. SigSet::wait() unwrap on Signal::try_from — panic on RT signals
src/sys/signal.rs:594— panics if kernel delivers signal not in enum.- GitHub: No existing issue or PR.
L3. vmsplice + SPLICE_F_GIFT undocumented unsafety
src/fcntl.rs:1317-1333— kernel takes ownership of user pages; safe API doesn't reflect this.- GitHub: #2633 (open) — "possible safety violation via vmsplice". Also #1647 (closed) — "IoVec::from_mut_slice and vmsplice are unsound".
L4. SockProtocol::EthIp aliases NetlinkISCSI discriminant on little-endian
src/sys/socket/mod.rs:262— both produce value 8; pattern matching can't distinguish them.- GitHub: #1903 (open) — "SockProtocol: No support for redundant protocol values from different families".
L5. PosixSpawnAttr::reinit double-destroy on init failure
src/spawn.rs:40-56— ifinitfails afterdestroy, Drop calls destroy again.- GitHub: No existing issue or PR.
L6. SendfileHeaderTrailer derives Clone with self-referential raw pointers
src/sys/sendfile.rs:83— Clone would produce dangling pointers. Currently private/unused.- GitHub: No existing issue or PR.
L7. from_raw_parts safety doc has wrong formula
src/sys/socket/addr.rs:439— says-should be+.- GitHub: No existing issue or PR.
L8. accept/accept4 return RawFd instead of OwnedFd
src/sys/socket/mod.rs:2343, 2368— inconsistent withsocket()/socketpair(), fd leak risk.- GitHub: No existing issue or PR.
L9. ScmRights stores Vec<RawFd> — received fds leak on drop
src/sys/socket/mod.rs:760— no auto-close. Should beVec<OwnedFd>or documented.- GitHub: No existing issue or PR.
L10. SetUsize truncates usize to c_int without bounds check
src/sys/socket/sockopt.rs:1841— values abovei32::MAXsilently truncate.- GitHub: No existing issue or PR.
L11. GetUsize sign-extends negative c_int to huge usize
src/sys/socket/sockopt.rs:1827— if kernel returns negative, wraps to near-maxusize.- GitHub: No existing issue or PR.
L12. Inconsistent from_bits_truncate vs from_bits_retain for ControlFlags
src/sys/termios.rs:224 vs 240—tcgetattrloses unknown bits,cfmakerawpreserves them.- GitHub: No existing issue or PR.
L13. cfgetispeed/cfgetospeed panic on unknown baud rate
src/sys/termios.rs:782, 791—try_into().unwrap()panics on rates not inBaudRateenum.- GitHub: No existing issue or PR.
L14. Fanotify::read_events() infinite loop on event_len == 0
src/sys/fanotify.rs:366-380— offset never advances ifevent_lenis zero.- GitHub: No existing issue or PR.
L15. statfs::filesystem_type_name() panics on non-UTF-8
src/sys/statfs.rs:310-313—to_str().unwrap()on kernel data.- GitHub: No existing issue or PR.
L16. stat::umask() panics on unknown mode bits
src/sys/stat.rs:211—from_bits().expect(...)on kernel return value.- GitHub: No existing issue or PR.
L17. ucontext::sigmask_mut() relies on implicit repr(transparent) of SigSet
src/ucontext.rs:34-39— pointer cast from*mut sigset_tto*mut SigSetwould be UB if SigSet layout changes.- GitHub: No existing issue or PR.
L18. Errno::from_raw maps unknown errno to 0 (UnknownErrno)
src/errno.rs:102— future kernel errnos are silently swallowed, indistinguishable from success.- GitHub: No existing issue or PR.
Dependencies
All dependencies clean:
- cargo audit: 0 vulnerabilities found
- cargo deny: advisories ok
- memoffset 0.9.1: Sound on modern Rust. Has 2 legacy UB paths for pre-1.51 compilers (dead code for nix's MSRV of 1.69).
- pin-utils 0.1.0: Sound. Unmaintained since 2019 but functionally complete.
pin_mut!superseded bystd::pin::pin!since Rust 1.68. - libc, bitflags, cfg-if: No unsafe concerns relevant to nix.
Summary
| Severity | Count | Has existing GitHub issue | Novel findings |
|---|---|---|---|
| Critical | 5 | 2 (C4 partial, C5) | 3 (C1, C2, C3) |
| High | 13 | 4 (H3, H4 partial, H9, H12 partial) | 9 |
| Medium | 30 | 9 (M2, M5, M10, M11, M12, M18/M19, M20, M21, M22) | 21 |
| Low | 18 | 2 (L3, L4) | 16 |
| Total | 66 | 17 | 49 |
Top 12 most actionable fixes:
- C1: Add
Errno::result(duplicated_fd)?;beforeOwnedFd::from_raw_fdindup2_raw - C2: Replace
Errno::result(res)withif res != 0 { return Err(Errno::from_raw(res)); }inSigSet::wait() - C3: Don't iterate addresses from
sendmmsgresults, or initialize addresses before send - C4: Require
&'static CStron non-Linuxopenlog(like the Linux variant already does) - C5: Remove or completely rewrite deprecated
lio_listio— the fat/thin pointer cast is unfixable without a signature change - H1: Validate
cmcred_ngroupsingroups()against array length - H2: Add NUL-termination validation in
AlgAddr::new()or useCStr::from_bytes_until_nul - H4/H9: Use
MaybeUninit::zeroed()instead ofuninit()inSigAction::newandMqAttr::new - H6: Mark
SendfileVec::newselfasunsafe - H8: Clamp
sa_lentosize_of::<sockaddr_storage>()inworkaround_xnu_bug - H11: Remove
AsMut<libc::aiocb>impl or gate it behindunsafe— it breaks AIO safety - M26: Change
then_some(...)tothen(|| ...)inPollTimeout::as_millis()
Metadata
Metadata
Assignees
Labels
No labels
Activity
AlexanderSerbul commentedon Aug 20, 2026
Re: finding C3 (sendmmsg / MultiResults reads uninitialized addresses) — we hit this independently in a code review and can confirm reachability from safe code.
On the send path,
MultiResults::next()executesself.rmm.addresses[self.current_index].assume_init(), butsendmmsg()never writesMultiHeaders.addresses— they stayMaybeUninit::uninit()frompreallocate(). The comment insidenext()even states the invariant only holds for indices "written by recvmmsg", which never happens when the same iterator is returned from a send.Trigger is as trivial as
sendmmsg(...)?.count()— and that's the natural call, because the syscall's return value (how many messages the kernel actually accepted, needed to resend the tail) isn't exposed any other way. Verified against 0.30.1 sources (sys/socket/mod.rs).A non-iterating count accessor on
MultiResults(exposing the raw syscall return) would both remove the only reason send-path callers touch the iterator and give them what they actually need.