Skip to content

Nix 0.31.2 Security & Soundness Audit findings #2797

Open

Description

@SteveLauC

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::dup2 returns -1 on error. The code never checks for this and unconditionally wraps the return value in OwnedFd::from_raw_fd(duplicated_fd). This creates an OwnedFd holding fd -1. When dropped, close(-1) is called. Compare with dup3_raw (line 710) which correctly calls Errno::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 uses Errno::result(res), which only checks for -1. Since sigwait never returns -1, errors (e.g. EINVAL) are treated as success, and the code proceeds to signum.assume_init() on an uninitialized MaybeUninit<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() returns MultiResults whose .next() calls self.rmm.addresses[i].assume_init(). But sendmmsg never writes to MultiHeaders.addresses — they remain MaybeUninit::uninit() from preallocate(). The comment on line 1989 says "written by recvmmsg" but this code path is sendmmsg.
  • 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 openlog variant passes a temporary CStr pointer (from with_nix_path closure) to libc::openlog. Per POSIX, openlog stores the ident pointer and dereferences it later during syslog() calls. The temporary is freed when the closure returns. Any subsequent syslog() 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_suspend and deprecated lio_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 as aiocb* 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 length cmcred_ngroups as usize. The From<libc::cmsgcred> impl (line 508-511) allows safe code to construct UnixCredentials with arbitrary cmcred_ngroups. A negative c_short wraps to a huge usize; a value larger than CMCRED_MAX_GROUPS reads 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_ptr to 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-byte alg_type or 64-byte alg_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() for ControlMessage::AlgSetIv(iv) returns mem::size_of::<&[u8]>() + iv.len(). A &[u8] is 16 bytes on 64-bit (fat pointer). But the actual data written in copy_to_cmsg_data is size_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 mention SigAction/sa_restorer.
  • Creates MaybeUninit::<libc::sigaction>::uninit(), only initializes sa_sigaction, sa_flags, sa_mask. On Linux, sa_restorer (a function pointer) is left uninitialized. The struct is then passed to libc::sigaction(). Reading uninitialized bytes is UB.
  • Fix: Use MaybeUninit::zeroed() instead of uninit().

H5. SigAction::handler() pointer type-punning through local variable

  • File: src/sys/signal.rs:879-909
  • GitHub: No existing issue or PR.
  • Converts usize back 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 on SigAction returned from unsafe sigaction(), where the kernel-supplied sa_sigaction value 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_t with sfv_fd = SFV_FD_SELF. When passed to safe sendfilev(), the kernel reads len bytes from address off in the process's address space and sends them to a socket. This allows reading arbitrary process memory without any unsafe block.
  • 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) — "From impls that take libc types are unsound". That issue covers the reverse direction (From<libc::passwd> for User), not the leak in From<User> for libc::passwd.
  • Calls .into_raw() on multiple CString values to produce raw *mut c_char pointers for libc::passwd struct fields. These leaked heap allocations can never be reclaimed since libc::passwd has no Drop impl.
  • 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_nonoverlapping copies (*src_sock).sa_len bytes (u8, max 255) into a MaybeUninit<sockaddr_storage> (128 bytes). No bounds check. If kernel returns sa_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_attr at src/mqueue.rs#L111-L121 as "the most problematic" instance.
  • MaybeUninit::<libc::mq_attr>::uninit() is used, then only 4 of the fields are set. On Linux/glibc, mq_attr has additional padding fields (__pad1 through __pad4) left uninitialized. assume_init() on partially-initialized memory is UB. The struct also derives Eq, Hash, PartialEq which 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-freebsd passes with a repro crate that drops bufs while AioReadv survives.
  • AioReadv::new stores bufs.as_mut_ptr() (a pointer into the caller's &mut [IoSliceMut] slice) in aio_buf. But the outer borrow of bufs is NOT tied to lifetime 'a of the returned struct. After new returns, the caller can drop the bufs slice, and aio_buf becomes a dangling pointer. Same issue for AioWritev. 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::aiocb to safe code. A caller can overwrite aio_buf to 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() returns libc::sigevent by value. &mut sigev.sigevent() as *mut creates a pointer to a temporary that is dropped at the end of the statement. sigevp is dangling when passed to libc::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-freebsd passes with a repro crate that calls nmount() twice.
  • nmount() pushes iov entries pointing to a local errmsg Vec. When the function returns, errmsg is dropped but the iov entries remain in self.iov. A second call to nmount() passes dangling pointers to the kernel. Also desynchronizes iov and is_owned vectors (missing push to is_owned at line 367), potentially causing Drop to call CString::from_raw on wrong pointers. Triggerable from safe code (nmount takes &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_len with itself instead of other.svm_len. Two VsockAddr values with different svm_len but 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::getregset may lead to UB of uninitialized data read".
  • Kernel may write fewer bytes than size_of::<S::Regs>() (sets iov.iov_len to actual). Code unconditionally calls data.assume_init(). Tail bytes may be uninitialized.
  • Fix: Zero-init buffer or check iov.iov_len after 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 usize can underflow (wrap to huge value) if cmsg_len is corrupted. Result is used for slice::from_raw_parts length.

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 to gid_t*. Gid is struct 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 the OwnedFd. If fdopendir fails, 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 checks nlen + 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) — "SockaddrStorage broken for variable-length addresses". Also PR #1871 (closed).
  • Casts *mut sockaddr_storage to *mut UnixAddr to write sun_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 ngroups elements before set_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_indextoname returns NULL on error. But Errno::result for *mut c_void checks against -1isize as *mut c_void (the sentinel), not NULL. Errors silently pass through as success, returning a CString from 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.
  • TsClock socket option uses GetStruct<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> like SockType does.

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::uninit pattern).
  • self.val.assume_init() is called on the full buffer, but kernel only wrote self.len bytes. CStr::from_bytes_until_nul then 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_bits unwrap 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() and FilterFlag::from_bits().unwrap().

M20. Deprecated signalfd() double-close on borrowed fd

  • File: src/sys/signalfd.rs:50-68
  • GitHub: #2116 (closed) — "SignalFd::set_mask closes the signal file descriptor". Reports the exact double-close bug.
  • When called with Some(&existing_fd), signalfd syscall returns the same fd number. Code wraps it in a new OwnedFd. 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() does num_seconds() * 1_000_000_000 without checked arithmetic. TimeSpec::new() accepts arbitrary values bypassing bounds checks. Add/Sub impls 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_sec cast to u64 wraps to near-max value. Non-normalized tv_nsec >= 1_000_000_000 causes Duration::new to 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_nsec without normalization. Ord impl assumes tv_nsec is 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 a Pthread for a joined/exited thread is UB per POSIX. On platforms where pthread_t is 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_some eagerly evaluates its argument. When self.0 == -1 (PollTimeout::NONE), u32::try_from(-1).unwrap() panics even though is_some() returned false. Also affects duration() (line 33) and TryFrom<PollTimeout> for Duration. Also aliased as EpollTimeout.
  • Fix: Change then_some(...) to then(|| ...).

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_progress before 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 = false is set BEFORE the aio_return syscall. 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 and in_progress is 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_unaligned without checking that len is >= the type size. A truncated or corrupted cmsg_len would 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 — if init fails after destroy, 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 with socket()/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 be Vec<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 above i32::MAX silently 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-max usize.
  • GitHub: No existing issue or PR.

L12. Inconsistent from_bits_truncate vs from_bits_retain for ControlFlags

  • src/sys/termios.rs:224 vs 240 — tcgetattr loses unknown bits, cfmakeraw preserves 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 in BaudRate enum.
  • 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 if event_len is 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_t to *mut SigSet would 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 by std::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:

  1. C1: Add Errno::result(duplicated_fd)?; before OwnedFd::from_raw_fd in dup2_raw
  2. C2: Replace Errno::result(res) with if res != 0 { return Err(Errno::from_raw(res)); } in SigSet::wait()
  3. C3: Don't iterate addresses from sendmmsg results, or initialize addresses before send
  4. C4: Require &'static CStr on non-Linux openlog (like the Linux variant already does)
  5. C5: Remove or completely rewrite deprecated lio_listio — the fat/thin pointer cast is unfixable without a signature change
  6. H1: Validate cmcred_ngroups in groups() against array length
  7. H2: Add NUL-termination validation in AlgAddr::new() or use CStr::from_bytes_until_nul
  8. H4/H9: Use MaybeUninit::zeroed() instead of uninit() in SigAction::new and MqAttr::new
  9. H6: Mark SendfileVec::newself as unsafe
  10. H8: Clamp sa_len to size_of::<sockaddr_storage>() in workaround_xnu_bug
  11. H11: Remove AsMut<libc::aiocb> impl or gate it behind unsafe — it breaks AIO safety
  12. M26: Change then_some(...) to then(|| ...) in PollTimeout::as_millis()

Activity

  1. AlexanderSerbul commented on Aug 20, 2026

    @AlexanderSerbul

    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() executes self.rmm.addresses[self.current_index].assume_init(), but sendmmsg() never writes MultiHeaders.addresses — they stay MaybeUninit::uninit() from preallocate(). The comment inside next() 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions