SockAddr::path_len doesn't bound the length by sun_path: as_pathname panics since #691, as_abstract_namespace slices past it
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 72/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- rust
- 领域
- networking
调研方向
从 src/sys/unix.rs 第 944-966 行附近、path_len 开始,它供给 as_pathname 和 as_abstract_namespace;该 issue 将 panic 定位到 storage.sun_path[len - 1]。用粘贴的 sockaddr_storage 示例在 cargo +nightly miri run 下以及原生环境下复现,然后把长度限制到 sun_path.len(),使两种情况都得到 107 字节。当两条路径在 Miri 下都返回有界切片且 cargo test --features all 通过时完成;预期在动手修改前先阅读周边的 unsafe 指针/retag 代码。
由索引模型根据 Issue 内容生成。
描述
SockAddr::path_len computes the path length from self.len() without bounding it by sun_path's 108 bytes. SockAddrStorage::view_as's documentation example copies a received sockaddr_storage whole and passes size_of::<sockaddr_storage>() as the length, and for an AF_UNIX address built that way len is 126:
- Since #691,
as_pathname()(andas_unix()) panics, becausepath_lennow indexesstorage.sun_path[len - 1]. as_abstract_namespace()returns a 125-byte slice that runs 17 bytes pastsun_path. Miri's Stacked Borrows rejects it, because the pointer comes from a reference tosun_pathalone. Tree Borrows accepts it. Before #691,as_pathname()did the same.
use std::mem::size_of;
use socket2::{SockAddr, SockAddrStorage, socklen_t};
fn main() {
let mut received: libc::sockaddr_storage = unsafe { std::mem::zeroed() };
let un = unsafe { &mut *(&mut received as *mut _ as *mut libc::sockaddr_un) };
un.sun_family = libc::AF_UNIX as libc::sa_family_t;
un.sun_path[1] = b'a' as libc::c_char; // abstract name; set sun_path[0] instead for a pathname
let mut storage = SockAddrStorage::zeroed();
unsafe { *storage.view_as::<libc::sockaddr_storage>() = received };
let addr = unsafe { SockAddr::new(storage, size_of::<libc::sockaddr_storage>() as socklen_t) };
println!("{}", addr.as_abstract_namespace().unwrap().len()); // 125
}
cargo +nightly miri run:
error: Undefined Behavior: trying to retag from <736> for SharedReadOnly permission at alloc263[0x6e], but that tag does not exist in the borrow stack for this location
--> src/sys/unix.rs:966:13
help: <736> was created by a SharedReadOnly retag at offsets [0x2..0x6e]
With un.sun_path[0] = b'a' and as_pathname(), natively and under Miri:
thread 'main' panicked at src/sys/unix.rs:944:19:
index out of bounds: the len is 108 but the index is 125
This was run on master at b6c3b8e with libc 0.2.191 and rustc 1.102.0-nightly (2026-11-12), on x86_64-unknown-linux-gnu.
A possible fix is to bound the length in path_len:
let len = (self.len() as usize - offset_of_path(storage)).min(storage.sun_path.len());
I tested it on master: both cases then return 107 bytes, natively and under Miri, and cargo test --features all passes.
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 天内回复
-
`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 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
rust-lang/socket2#683 · 2 条评论 ·
维护者通常 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 天内回复