SockAddr's PartialEq and Hash read uninitialised padding bytes of padded sockaddr types
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start in src/sockaddr.rs around line 485, where PartialEq/Hash compare as_bytes() over the first len bytes, and trace how SockAddr::new, try_init, set_length and SockAddrStorage::view_as establish that length without checking padding initialisation. Reproduce with the posted sockaddr_can example under Miri to confirm the uninitialised range at offsets 2..4. Done means either init-checking in those constructors or a family-aware comparison/hash that never touches padding, with the reproducer no longer reporting UB.
由索引模型根据 Issue 内容生成。
描述
SockAddr's PartialEq and Hash impls go through as_bytes, which views the first
len bytes of the storage as &[u8]. They assume every one of those bytes is initialised.
A caller can follow the documented unsafe API exactly and still leave some uninitialised.
SockAddrStorage::view_as::<T>() accepts any of the platform's sockaddr_* types, and a
typed write of a T leaves T's padding uninitialised. SockAddr::new asks only that the
family and length match the type. On Linux, libc::sockaddr_can has padding at offsets 2..4,
so comparing such an address reads uninitialised memory:
use std::mem::size_of;
use socket2::{SockAddr, SockAddrStorage, socklen_t};
fn main() {
let mut storage = SockAddrStorage::zeroed();
let can = unsafe { storage.view_as::<libc::sockaddr_can>() };
let mut value: libc::sockaddr_can = unsafe { std::mem::zeroed() };
value.can_family = libc::AF_CAN as libc::sa_family_t;
value.can_ifindex = 1;
*can = value;
let addr = unsafe { SockAddr::new(storage, size_of::<libc::sockaddr_can>() as socklen_t) };
assert!(addr == addr);
}
error: Undefined Behavior: reading memory at alloc263[0x0..0x18], but memory is uninitialized at [0x2..0x4], and this operation requires initialized memory
3: <socket2::SockAddr as std::cmp::PartialEq>::eq
at src/sockaddr.rs:485:9: 485:44
This was run under Miri with socket2 0.6.5 (8b8b96f) and current master (b6c3b8e), libc
0.2.191 and rustc 1.102.0-nightly (2026-11-12), on x86_64-unknown-linux-gnu.
A possible fix is to require, in SockAddr::new, try_init, set_length and view_as, that
every byte below len is initialised, padding included. Another is to compare and hash by
family rather than by raw bytes.
Found by Crustify, an experimental UB/soundness auditing agent developed at UC Berkeley and running on Claude Opus 5.5, then manually reviewed and independently reproduced.
- 主要语言
- Rust
- 星标
- 885
- 派生
- 328
- 平均合并
- 6 天 12 小时
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rust-lang/socket2 的其他 Issue
-
Commit lockfile未关闭
难度 2/5 1-3 小时 新手友好度 65/100
rust-lang/socket2#703 · 1 条评论 ·
维护者通常 1 天内回复
-
windows-sys 0.101.0可能已有人在做 @xtqqczze 于 3 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
SockAddr::path_len doesn't bound the length by sun_path: as_pathname panics since #691, as_abstract_namespace slices past it可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
`from_timeval` overflows on a non-normalised `tv_usec`可能已有人在做 @pederbe 于 18 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
Build fails on 32-bit glibc (i686, armv7) with libc's `--cfg=libc_unstable_time64`: `tv_usec` is cast to `suseconds_t` (i32) for an i64 field可能已有人在做 @omrzk 于 28 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
rust-lang/socket2#684 · 1 条评论 ·
维护者通常 1 天内回复
查看 rust-lang/socket2 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
infra
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
available bug good first issue tooling
难度 2/5 1-3 小时 新手友好度 78/100
Nixitov/Riptide-Native#817 ·
维护者通常 1 天内回复