Miri reports UB on MacOS when using fstat
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- rust
- Ambito
- operating-systems
Direzione di ricerca
Riprodurre il fallimento di macOS Miri con l’esempio tempfile, quindi esaminare src/backend/libc/fs/syscalls.rs intorno alla riga 1570 e confrontarlo con il Unix filesystem shim di Miri e libc-fstat-non-file.rs. Determinare se i campi riservati non validi richiedono una modifica a rustix o Miri e verificare la correzione scelta con la riproduzione e la copertura fstat pertinente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Reproduction, testing via tempfile (3.27.0):
#[test]
fn test123() {
let a = tempfile::NamedTempFile::new().unwrap();
a.reopen().unwrap();
}
- For reference this is on macOS 26.5.2
Running test:
test123 (main)$ MIRIFLAGS="-Zmiri-disable-isolation" cargo +nightly miri test
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.00s
Running unittests src/main.rs (/Users/jeffrey/.cargo_target_cache/miri/aarch64-apple-darwin/debug/deps/test123-9a724f3234e25023)
running 1 test
test tests::test123 ... error: Undefined Behavior: constructing invalid value of type libc::unix::bsd::apple::stat: at .st_lspare, encountered uninitialized memory, but expected an integer
--> /Users/jeffrey/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustix-1.1.4/src/backend/libc/fs/syscalls.rs:1570:20
|
1570 | let stat = stat.assume_init();
| ^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: this is on thread `tests::test123`
= note: stack backtrace:
0: rustix::backend::fs::syscalls::fstat
at /Users/jeffrey/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustix-1.1.4/src/backend/libc/fs/syscalls.rs:1570:20: 1570:38
1: rustix::fs::fd::fstat::<&std::fs::File>
at /Users/jeffrey/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustix-1.1.4/src/fs/fd.rs:157:5: 157:45
2: tempfile::file::imp::platform::reopen
at /Users/jeffrey/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tempfile-3.27.0/src/file/imp/unix.rs:83:20: 83:43
3: tempfile::NamedTempFile::reopen
at /Users/jeffrey/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tempfile-3.27.0/src/file/mod.rs:952:9: 952:63
4: tests::test123
at src/main.rs:10:9: 10:19
5: tests::test123::{closure#0}
at src/main.rs:8:17: 8:17
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
error: aborting due to 1 previous error
error: test failed, to rerun pass `--bin test123`
Caused by:
process didn't exit successfully: `/Users/jeffrey/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/cargo-miri runner /Users/jeffrey/.cargo_target_cache/miri/aarch64-apple-darwin/debug/deps/test123-9a724f3234e25023` (exit status: 1)
note: test exited abnormally; to see the full output pass --no-capture to the harness.
It seems at this stat call:
In the Miri shim they don't initialize fields st_lspare and st_qspare:
- https://github.com/rust-lang/miri/blob/2b466864cf2e0c6301854461b857b6ece8be7349/src/shims/unix/fs.rs#L261-L319
- https://github.com/rust-lang/miri/blob/2b466864cf2e0c6301854461b857b6ece8be7349/tests/pass-dep/libc/libc-fstat-non-file.rs#L19-L26
- This test suggests its intentional
As the man page states they are reserved:
struct stat { /* when _DARWIN_FEATURE_64_BIT_INODE is defined */
dev_t st_dev; /* ID of device containing file */
mode_t st_mode; /* Mode of file (see below) */
nlink_t st_nlink; /* Number of hard links */
ino_t st_ino; /* File serial number */
uid_t st_uid; /* User ID of the file */
gid_t st_gid; /* Group ID of the file */
dev_t st_rdev; /* Device ID */
struct timespec st_atimespec; /* time of last access */
struct timespec st_mtimespec; /* time of last data modification */
struct timespec st_ctimespec; /* time of last status change */
struct timespec st_birthtimespec; /* time of file creation(birth) */
off_t st_size; /* file size, in bytes */
blkcnt_t st_blocks; /* blocks allocated for file */
blksize_t st_blksize; /* optimal blocksize for I/O */
uint32_t st_flags; /* user defined flags for file */
uint32_t st_gen; /* file generation number */
int32_t st_lspare; /* RESERVED: DO NOT USE! */
int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */
};
- https://man.freebsd.org/cgi/man.cgi?query=fstat&sektion=2&manpath=macOS+13.6.5
- https://docs.rs/libc/latest/aarch64-apple-darwin/libc/struct.stat.html
But above code assumes the struct (and all fields) are initialized
- Lingua principale
- Rust
- Stelle
- 2.1k
- Fork
- 322
- Merge medio
- 5g 16h
- PR unite (30g)
- 9
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di bytecodealliance/rustix
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 69/100
bytecodealliance/rustix#1736 ·
I maintainer di solito rispondono entro 1 giorno
-
termios::Termios::OutputModes does not expose some const for muslForse già presa @xtqqczze l’ha presa 13 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
bytecodealliance/rustix#1706 · 31 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
net feature alone fails to compile in 1.1.5: sockopt uses crate::timespec, which net does not gate inForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
bytecodealliance/rustix#1689 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Wrong flag used for (set_)ipv6_multicast_hopsForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
bytecodealliance/rustix#1660 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
bytecodealliance/rustix#1635 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di bytecodealliance/rustix
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
longbridge/gpui-kit#3871 ·
I maintainer di solito rispondono entro 1 giorno
-
area:models enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
I maintainer di solito rispondono entro 1 giorno
-
fix v1 repository metadataApertagood first issue help wanted
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
servo/rust-smallvec#864 ·
-
bug frontend ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno