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

Đang mở
#5,723 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

  • #5724 của @ci4ic4 — đã đóng, không merge

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
rust
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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).

Ngôn ngữ chính
Rust
Star
2.7k
Fork
1.4k
Merge trung bình
3 ngày 2 giờ
Pull request đã merge (30 ngày)
45

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rust-lang/libc

Tất cả issue của rust-lang/libc

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.