ioctl_tiocsctty passes the address of a zero instead of the documented 0 argument
I maintainer di solito rispondono entro 11 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 68/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- linux, rust
- Ambito
- operating-systems
Direzione di ricerca
Il bug è in src/process/ioctl.rs: la chiamata documentata è alla riga 13, e l'adattatore degli argomenti alle righe 45-47 passa l'indirizzo di una variabile locale sullo stack 0u32 invece del valore 0. Inizia leggendo quell'adattatore e il commento di documentazione di ioctl_tiocsctty, poi esegui il repro strace dell'issue per confermare l'argomento errato. È completato quando l'adattatore passa il letterale 0, il commento cita ioctl_tty(2) e l'output di strace mostra TIOCSCTTY, 0.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
rustix::process::ioctl_tiocsctty is documented as performing ioctl(fd, TIOCSCTTY, 0):
but the argument adapter passes the address of a stack-local 0u32:
Linux from 2.6.12 requires the third arg to be exactly 1 for the option to steal the terminal, and only uses that arg anyway when CAP_SYS_ADMIN. On BSDs the arg is ignored. The Linux manpage says to use 0 otherwise; the comment in the code has tty_ioctl(4) but that's since been renamed to ioctl_tty(2) and TIOCSCTTY(2const) has the detail:
Make the given terminal the controlling terminal of the
calling process. The calling process must be a session
leader and not have a controlling terminal already. For
this case, arg should be specified as zero.
If this terminal is already the controlling terminal of a
different session group, then the ioctl fails with EPERM,
unless the caller has the CAP_SYS_ADMIN capability and arg
equals 1, in which case the terminal is stolen, and all
processes that had it as controlling terminal lose it.
From kernel source:
static int tiocsctty(struct tty_struct *tty,
struct file *file, int arg)
{
// ...
if (tty->ctrl.session) {
if (arg == 1 && capable(CAP_SYS_ADMIN)) {
session_clear_tty(tty->ctrl.session);
} else {
ret = -EPERM;
goto unlock;
}
}
// ...
}
This isn't unsafe exactly, but it's still confusing. Also, it might be worth exposing the steal variant.
Tiny repro:
#!/usr/bin/env -S cargo +nightly -Zscript
---cargo
package.edition = "2024"
dependencies.rustix = { version = "1.1.5", features = ["process"] }
---
fn main() {
let _ = rustix::process::ioctl_tiocsctty(std::io::stdin());
}
With strace:
$ ./repro.rs >/dev/null # compile
$ sudo strace -e ioctl ~/.cargo/build/*/*/target/debug/repro # run with CAP_SYS_ADMIN
ioctl(0, TIOCSCTTY, -527932840) = -1 ENOTTY (Inappropriate ioctl for device)
The return may vary and isn't relevant: -527932840 is an address and is neither 0 nor 1, the two permitted values. A silver lining is that it's also impossible for arg to be 1 under the current code, so it's technically harmless.
- Lingua principale
- Rust
- Stelle
- 2.1k
- Fork
- 308
- Merge medio
- 14g 5h
- PR unite (30g)
- 5
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
-
rustix::termios::Termios::OutputModes does not expost some const e.g. OLCUC for musl and macOSAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
bytecodealliance/rustix#1706 · 1 commento ·
I maintainer di solito rispondono entro 11 giorni
-
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 11 giorni
-
Wrong flag used for (set_)ipv6_multicast_hopsForse già presa @RajaBabu15 l’ha presa 62 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
bytecodealliance/rustix#1660 ·
I maintainer di solito rispondono entro 11 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
bytecodealliance/rustix#1635 ·
I maintainer di solito rispondono entro 11 giorni
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
bytecodealliance/rustix#1068 ·
I maintainer di solito rispondono entro 11 giorni
Tutte le issue di bytecodealliance/rustix
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
wormhole-foundation/wormhole#5062 ·
I maintainer di solito rispondono entro 1 giorno
-
RUSTSEC-2026-0348: Brotli certificate decompression can allocate up to 1 GiB before authenticationAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 60/100
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 62/100
-
core: Amount::from_str panics on values above 21M BTC instead of returning an errorForse già presa @bhuvan-somisetty l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
crate: spate-s3
Difficoltà 2/5 Mezza giornata Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno