Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

UEFI: TCP receive returns firmware-reported data_length without clamping to buffer size

Chiusa Adatta ai principianti
#164,946 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Leggi library/std/src/sys/net/connection/uefi/tcp4.rs, in particolare i percorsi di ricezione alle righe 269-350, e segui come vengono usati la lunghezza del buffer richiesta e data_length riportato dal firmware. Controlla sia le letture scalari sia quelle vettoriali; il lavoro è terminato quando nessuna delle due può riportare più byte di quanti ne possa contenere il buffer del chiamante. L’issue non indica un percorso di test, quindi cerca prima test UEFI TCP esistenti o copertura nelle vicinanze.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

C-bug I-prioritize I-unsound needs-triage O-UEFI T-libs

The UEFI TCPv4 receive path returns the firmware-reported data_length directly
as the number of bytes read, without clamping it to the caller's buffer size. A
non-conformant network driver can report more bytes than the buffer holds, making
TcpStream::read violate the Read contract and causing upper layers to treat
uninitialized/out-of-bounds memory as initialized. This is the most
attacker-exposed input in a pre-boot environment.

I tried this code:

use std::io::Read;
use std::net::TcpStream;

let mut stream = TcpStream::connect("127.0.0.1:8080").unwrap();
let mut buf = [0u8; 1024];
let n = stream.read(&mut buf).unwrap(); // n may exceed 1024 if the driver over-reports

I expected to see this happen: read returns a count <= the buffer length, or
errors if the firmware reports an invalid length.

Instead, this happened: the driver-reported data_length is returned unchecked
(library/std/src/sys/net/connection/uefi/tcp4.rs:325-350):

if completion_token.status.is_error() {
    Err(...)
} else {
    let data_length = unsafe { (*rx_data).data_length }; // firmware/driver-reported
    Ok(data_length as usize)                             // never clamped to buffer size
}

If the driver reports data_length greater than the requested length
(data_len, established at lines 269-279), read/read_vectored claim more bytes
are initialized than the buffer contains. default_read_buf / read_to_end then
read out of bounds. The same pattern exists in the vectored path (lines 285-323).
Clamping fixes it:

Ok(core::cmp::min(data_length as usize, data_len as usize))
Meta

Found by static analysis of main @ dc44e7f. Requires a misbehaving UEFI
network driver to trigger. Related: #100499.

rustc --version --verbose:

rustc 1.101.0-dev
binary: rustc
commit-hash: dc44e7f2c436b6041742e138b9c2176f093196d5
commit-date: 2026-10-24
host: x86_64-unknown-linux-gnu
release: 1.101.0-dev
Backtrace

(static analysis; no runtime backtrace — requires a non-conformant UEFI network driver)

@rustbot label +I-unsound +T-libs +O-uefi +C-bug

Lingua principale
Rust
Stelle
121k
Fork
18.7k
Merge medio
2g 21h
PR unite (30g)
536

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/rust

Tutte le issue di rust-lang/rust

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.