Skip to content

Conversation

gibbz00 and others added 14 commits January 8, 2026 10:35
This change makes sure that the header of `next` is within max,
returning null if not. This is similar to how `glibc` does it.

No checks were previously being done to assert that `next as usize +
size_of::<cmsghdr>() < max`. Wrapping offset calculations could then
lead to buffer over-reads in the following `(*next).cmsg_len`.

[glibc ref](https://github.com/bminor/glibc/blob/b71d59074b98ad4abd23c136ec9ad4c26e29ee6d/sysdeps/unix/sysv/linux/cmsg_nxthdr.c#L49-L51)

(backport <rust-lang#4903>)
(cherry picked from commit cdc2077)
Likely written to make assertions in the unsound CMSG_NXTHDR implementations
introduced in rust-lang#1235. CMSG_NXTHDR(mhdr, current_cmsghdr) should not be concerned
with the value next_cmsghdr.cmsg_len, which the previous implementation did.

(backport <rust-lang#4903>)
(cherry picked from commit 1e43edb)
Setting `(*pcmsghdr).cmsg_len = cmsg_len as _;` when cmsg_len ranges
from 0 to 64 is invalid as it must always be `>= size_of::<cmsghdr>()`,
rounded up to the nearest alignment boundary.

Some implementations (notably glbic) do check that `cmsg_len >=
size_of::<cmsghdr>()` in `CMSG_NXTHDR`, returning null if so. But
this is more so an extra precaution that is not mentioned in the POSIX
1003.1-2024. It can therefore not be relied on for tests executed on
multiple platforms.

The change also removes the ignoring of some testvalues when targeting AIX.

(backport <rust-lang#4903>)
(cherry picked from commit f391df3)
…es in CMSG_NXTHDR

musl and its descendants check `next_addr >= max_addr` whilst the rest
do `next_addr > max_addr`. This was previously not reflected in the
implementations, coming to light only after testing was extended to
execute at the controllen boundary.

[musl_ref]: https://www.openwall.com/lists/musl/2025/12/27/1

(backport <rust-lang#4903>)
(cherry picked from commit 17adf2d)
 * Use the same type names as used by the native libc, to allow
   more self-tests to succeed
 * Remove un-needed imports, uncovered by libc's "cargo test"
 * Compute _ALIGNBYTES the same way gcc does.

Verified by

 * Running (and passing) the libc self-tests "natively"
   on an emulated NetBSD/riscv64 system.
 * Cross-built rust 1.92.0 with this file in place for riscv64
   in the vendored libc-0.2.17{5,6,7} versions, targeting
   NetBSD/riscv64.

[ extracted this commit from the two in the PR - Trevor ]

(backport <rust-lang#4886>)
(cherry picked from commit e9b8fa5)
Resolves a uclibc build error introduced in the "Fixes" commit.

Fixes: 2fe1d91 ("Separate L4Re from Linux code and enable tests")

(backport <rust-lang#4915>)
(cherry picked from commit 3dad489)
Move netlink types defined in UAPI to the `new` module. This resolves
the following build error on uclibc platforms:

    error[E0425]: cannot find value `NLMSG_MIN_TYPE` in the crate root
        --> /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libc-0.2.179/src/unix/linux_like/linux/mod.rs:1999:48
         |
    1999 | pub const NFNL_MSG_BATCH_BEGIN: c_int = crate::NLMSG_MIN_TYPE;
         |                                                ^^^^^^^^^^^^^^ not found in the crate root
         |
    note: found an item that was configured out
        --> /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libc-0.2.179/src/unix/linux_like/linux_l4re_shared.rs:1222:19
         |
    1200 |     if #[cfg(not(target_env = "uclibc"))] {
         |                 ----------------------- the item is gated here
    ...
    1222 |         pub const NLMSG_MIN_TYPE: c_int = 0x10;
         |                   ^^^^^^^^^^^^^^

Fixes: 2fe1d91 ("Separate L4Re from Linux code and enable tests")

(backport <rust-lang#4915>)
(cherry picked from commit e0ed72d)
(backport <rust-lang#4917>)
(cherry picked from commit b4995f3)
@rustbot
Copy link
Collaborator

rustbot commented Jan 8, 2026

⚠️ Warning ⚠️

  • Pull requests are usually filed against the main branch for this repo, but this one is against libc-0.2. Please double check that you specified the right target!

@tgross35 tgross35 enabled auto-merge January 8, 2026 10:47
@tgross35 tgross35 added this pull request to the merge queue Jan 8, 2026
Merged via the queue into rust-lang:libc-0.2 with commit 12fd831 Jan 8, 2026
50 checks passed
@tgross35 tgross35 deleted the backport-urad branch January 8, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants