Skip to content

Commit 17adf2d

Browse files
gibbz00tgross35
authored andcommitted
linux, emscripten, android, l4re: handle zero-sized payload differences 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
1 parent befc34b commit 17adf2d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/unix/linux_like/emscripten/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ f! {
12571257
}
12581258
let next = (cmsg as usize + super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr;
12591259
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
1260-
if (next.offset(1)) as usize > max {
1260+
if (next.offset(1)) as usize >= max {
12611261
core::ptr::null_mut::<cmsghdr>()
12621262
} else {
12631263
next as *mut cmsghdr

src/unix/linux_like/linux_l4re_shared.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,14 @@ f! {
15061506
return core::ptr::null_mut();
15071507
}
15081508

1509-
let max_addr = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
1509+
let mut max_addr = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
1510+
1511+
if cfg!(any(target_env = "musl", target_env = "ohos")) {
1512+
// musl and some of its descendants do `>= max_addr`
1513+
// comparisons in the if statement below.
1514+
// https://www.openwall.com/lists/musl/2025/12/27/1
1515+
max_addr -= 1;
1516+
}
15101517

15111518
if next_cmsg as usize + size_of::<crate::cmsghdr>() > max_addr {
15121519
core::ptr::null_mut::<crate::cmsghdr>()

0 commit comments

Comments
 (0)