SockAddr's PartialEq and Hash read uninitialised padding bytes of padded sockaddr types
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 40/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- 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
-
SockAddr::path_len doesn't bound the length by sun_path: as_pathname panics since #691, as_abstract_namespace slices past itEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/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
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