bytecodealliance / bytecodealliance/rustix
UB if noreturn syscall actually returns
- Lingua principale
- Rust
- Stelle
- 2.1k
- Fork
- 294
- Merge medio
- 6g 22h
- PR unite (30g)
- 4
Descrizione
https://github.com/bytecodealliance/rustix/blob/cb01fbe4660844b67fdd4eee2a5f769518f6a655/src/backend/linux_raw/arch/x86_64.rs#L55-L63
https://github.com/bytecodealliance/rustix/blob/cb01fbe4660844b67fdd4eee2a5f769518f6a655/src/backend/linux_raw/runtime/syscalls.rs#L143-L146
## Every syscall may return
***Every syscall may return** with any value* because of seccomp-bpf.
This includes pure syscalls like `getuid` that may return the current uid as 4294967295_u32 (`-EPERM`) or `exit`/`exit_group` returning. While such seccomp-bpf filters will have huge compatibility problems and are unlikely in real-world, they must be handled in a safe way.
In the case of `exit`/`exit_group` there are two safe possibilities that maintain `-> !` to the caller:
1. Infinity loop
```rust
// Note that this is a pseudo example. If the `sys_exit` function is `-> !`,
// Rust is free to remove the loop because returning from `-> !` is UB.
// The loop must be implemented in assembly with a backward jump
// if the `asm!` is marked `noreturn` as return from the `noreturn`-`asm!`
// is already UB.
loop {
sys_exit(code)
}
```
2. Segfault, i.e. `ud2` (x86-64) after the `syscall`.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia con il codice del syscall noreturn collegato in src/backend/linux_raw/arch/x86_64.rs e src/backend/linux_raw/runtime/syscalls.rs. Traccia come exit e exit_group preservano il tipo di ritorno !, quindi valuta i due comportamenti sicuri descritti per un syscall che restituisce sotto seccomp-bpf. Il lavoro è completo quando il percorso di ritorno è definito senza introdurre UB.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust
- Ambito
- operating-systems, security
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100