SockAddr::path_len doesn't bound the length by sun_path: as_pathname panics since #691, as_abstract_namespace slices past it
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 72/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- rust
- Bereich
- networking
Rechercherichtung
Beginne in src/sys/unix.rs etwa bei den Zeilen 944-966 bei path_len, das as_pathname und as_abstract_namespace speist; das Issue legt den Panic auf storage.sun_path[len - 1] fest. Reproduziere mit dem eingefügten sockaddr_storage-Beispiel unter cargo +nightly miri run und nativ, begrenze dann die Länge auf sun_path.len(), sodass beide Fälle 107 Bytes ergeben. Fertig, wenn beide Pfade unter Miri begrenzte Slices zurückgeben und cargo test --features all durchläuft; erwarte, den umgebenden unsafe Pointer-/Retag-Code zu lesen, bevor du ihn anfasst.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Rust
- Sterne
- 885
- Forks
- 328
- Ø Merge
- 6 T. 12 Std.
- Gemergte PRs (30 T.)
- 2
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus rust-lang/socket2
-
Commit lockfileOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
rust-lang/socket2#703 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
windows-sys 0.101.0Evtl. vergeben @xtqqczze hat das vor 3 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Maintainer antworten meist innerhalb von 1 Tag
-
`from_timeval` overflows on a non-normalised `tv_usec`Evtl. vergeben @pederbe hat das vor 18 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
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 fieldEvtl. vergeben @omrzk hat das vor 28 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
rust-lang/socket2#684 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
rust-lang/socket2#683 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in rust-lang/socket2
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
infra
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
-
available bug good first issue tooling
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Nixitov/Riptide-Native#817 ·
Maintainer antworten meist innerhalb von 1 Tag