NetBSD aarch64: wrong `_ALIGNBYTES` breaks `CMSG_*` (CMSG_NXTHDR loops forever)

Aperta
#5,723 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #5724 di @ci4ic4 — chiusa senza merge

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
backend

Direzione di ricerca

Start in src/unix/bsd/netbsdlike/netbsd/aarch64.rs and compare _ALIGNBYTES with the AAPCS64 definition cited in the issue. The issue proposes using size_of::<u128>() - 1; done means the CMSG offsets and lengths match the reported NetBSD values and CMSG_NXTHDR advances correctly. Pull request #5724 is already open for this issue.

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

Descrizione

src/unix/bsd/netbsdlike/netbsd/aarch64.rs defines

pub(crate) const _ALIGNBYTES: usize = size_of::<c_int>() - 1; // 3

but NetBSD/aarch64 uses the AAPCS64 branch of sys/arch/arm/include/cdefs.h:

#if defined(__ARM_PCS_AAPCS64)
#define __ALIGNBYTES		(sizeof(__int128_t) - 1)   /* 15 */
#elif defined(__ARM_EABI__)
#define __ALIGNBYTES		(sizeof(long long) - 1)
#else
#define __ALIGNBYTES		(sizeof(int) - 1)
#endif

_ALIGNBYTES is only used by CMSG_DATA, CMSG_LEN, CMSG_NXTHDR and CMSG_SPACE, and all four come out wrong:

NetBSD 11.99.10 evbarm (aarch64) C (<sys/socket.h>) libc 0.2.191
sizeof(struct cmsghdr) 12 12
CMSG_DATA offset 16 12
CMSG_LEN(4) 20 16
CMSG_SPACE(4) 32 16

C values came from a small program built with the system cc. The libc values follow from _ALIGN(12) == 12 with _ALIGNBYTES == 3.

Impact

Code that parses control messages from the kernel reads them at the wrong offsets. CMSG_NXTHDR steps into padding, reads cmsg_len == 0, and returns the same header again, so a loop like while !cmsg.is_null() never ends. I hit this with sendme / iroh (noq-udp, which is a fork of quinn-udp): the first received UDP datagram puts a tokio worker into a 100% CPU loop with no syscalls. quinn-udp should be affected the same way. Building control messages with CMSG_SPACE/CMSG_LEN is also wrong, so the kernel will reject or misread them.

x86_64 is unaffected, because both C and the crate use sizeof(long) - 1. I haven't checked NetBSD arm (32-bit) or riscv64 on real hardware. Their crate values (c_longlong, __BIGGEST_ALIGNMENT__) look consistent with the C headers.

Fix
pub(crate) const _ALIGNBYTES: usize = size_of::<u128>() - 1;

With this change (as a vendored patch in pkgsrc), sendme works on NetBSD/aarch64 (transfers in both directions with NetBSD/amd64, hashes verified).

Lingua principale
Rust
Stelle
2.7k
Fork
1.4k
Merge medio
3g 2h
PR unite (30g)
45

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/libc

Tutte le issue di rust-lang/libc

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.