From afb1706d363a1b058b38bc4c06c1e31548a73558 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 16:42:06 +0000 Subject: [PATCH 1/6] Initial plan From 79ac9a56abc08c9b616f49c0b677a1682af0ae8a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 16:59:10 +0000 Subject: [PATCH 2/6] Fix UserMsgHdr padding issue: change repr(C, packed) to repr(C) with explicit padding Co-authored-by: CvvT <11675863+CvvT@users.noreply.github.com> --- litebox_common_linux/src/lib.rs | 11 +++++++++-- litebox_shim_linux/src/syscalls/net.rs | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/litebox_common_linux/src/lib.rs b/litebox_common_linux/src/lib.rs index 73ab21d31..600a56a1c 100644 --- a/litebox_common_linux/src/lib.rs +++ b/litebox_common_linux/src/lib.rs @@ -1771,13 +1771,17 @@ pub struct SigSetPack { pub size: usize, } -#[derive(Debug, FromBytes, IntoBytes)] -#[repr(C, packed)] +#[derive(Debug, FromBytes)] +#[repr(C)] pub struct UserMsgHdr { /// ptr to socket address structure pub msg_name: Platform::RawConstPointer, /// size of socket address structure pub msg_namelen: u32, + #[cfg(target_pointer_width = "64")] + #[allow(clippy::pub_underscore_fields)] + #[doc(hidden)] + pub _pad: u32, /// ptr to an array of `iovec` structures pub msg_iov: Platform::RawConstPointer>>, /// number of elements in msg_iov @@ -1795,6 +1799,9 @@ impl Clone for UserMsgHdr Date: Mon, 16 Mar 2026 17:40:24 +0000 Subject: [PATCH 3/6] =?UTF-8?q?Remove=20explicit=20=5Fpad=20field=20from?= =?UTF-8?q?=20UserMsgHdr=20=E2=80=94=20repr(C)=20handles=20padding=20autom?= =?UTF-8?q?atically?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: CvvT <11675863+CvvT@users.noreply.github.com> --- litebox_common_linux/src/lib.rs | 7 ------- litebox_shim_linux/src/syscalls/net.rs | 2 -- 2 files changed, 9 deletions(-) diff --git a/litebox_common_linux/src/lib.rs b/litebox_common_linux/src/lib.rs index 600a56a1c..c837ab4b6 100644 --- a/litebox_common_linux/src/lib.rs +++ b/litebox_common_linux/src/lib.rs @@ -1778,10 +1778,6 @@ pub struct UserMsgHdr { pub msg_name: Platform::RawConstPointer, /// size of socket address structure pub msg_namelen: u32, - #[cfg(target_pointer_width = "64")] - #[allow(clippy::pub_underscore_fields)] - #[doc(hidden)] - pub _pad: u32, /// ptr to an array of `iovec` structures pub msg_iov: Platform::RawConstPointer>>, /// number of elements in msg_iov @@ -1799,9 +1795,6 @@ impl Clone for UserMsgHdr Date: Mon, 16 Mar 2026 17:54:13 +0000 Subject: [PATCH 4/6] Restore IntoBytes and repr(C, packed) with explicit padding on UserMsgHdr Co-authored-by: CvvT <11675863+CvvT@users.noreply.github.com> --- litebox_common_linux/src/lib.rs | 13 +++++++++++-- litebox_shim_linux/src/syscalls/net.rs | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/litebox_common_linux/src/lib.rs b/litebox_common_linux/src/lib.rs index c837ab4b6..6790fa21d 100644 --- a/litebox_common_linux/src/lib.rs +++ b/litebox_common_linux/src/lib.rs @@ -1771,13 +1771,19 @@ pub struct SigSetPack { pub size: usize, } -#[derive(Debug, FromBytes)] -#[repr(C)] +#[derive(Debug, FromBytes, IntoBytes)] +#[repr(C, packed)] pub struct UserMsgHdr { /// ptr to socket address structure pub msg_name: Platform::RawConstPointer, /// size of socket address structure pub msg_namelen: u32, + /// Explicit padding to match the 4-byte gap that Linux's naturally-aligned + /// `struct user_msghdr` has between `msg_namelen` and `msg_iov` on 64-bit. + #[cfg(target_pointer_width = "64")] + #[allow(clippy::pub_underscore_fields)] + #[doc(hidden)] + pub _pad: u32, /// ptr to an array of `iovec` structures pub msg_iov: Platform::RawConstPointer>>, /// number of elements in msg_iov @@ -1795,6 +1801,9 @@ impl Clone for UserMsgHdr Date: Mon, 16 Mar 2026 18:44:54 +0000 Subject: [PATCH 5/6] Add trailing padding to UserMsgHdr and compile-time size check Co-authored-by: CvvT <11675863+CvvT@users.noreply.github.com> --- litebox_common_linux/src/lib.rs | 11 ++++++++--- litebox_shim_linux/src/syscalls/net.rs | 27 ++++++++++++++++---------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/litebox_common_linux/src/lib.rs b/litebox_common_linux/src/lib.rs index 6790fa21d..3c076426a 100644 --- a/litebox_common_linux/src/lib.rs +++ b/litebox_common_linux/src/lib.rs @@ -1781,9 +1781,7 @@ pub struct UserMsgHdr { /// Explicit padding to match the 4-byte gap that Linux's naturally-aligned /// `struct user_msghdr` has between `msg_namelen` and `msg_iov` on 64-bit. #[cfg(target_pointer_width = "64")] - #[allow(clippy::pub_underscore_fields)] - #[doc(hidden)] - pub _pad: u32, + _pad: u32, /// ptr to an array of `iovec` structures pub msg_iov: Platform::RawConstPointer>>, /// number of elements in msg_iov @@ -1794,6 +1792,10 @@ pub struct UserMsgHdr { pub msg_controllen: usize, /// flags on received message pub msg_flags: SendFlags, + /// Explicit trailing padding to match the 4-byte gap after `msg_flags` in + /// Linux's naturally-aligned `struct user_msghdr` on 64-bit (total size 56). + #[cfg(target_pointer_width = "64")] + _pad2: u32, } impl Clone for UserMsgHdr { @@ -1809,6 +1811,9 @@ impl Clone for UserMsgHdr>() == 56); + #[cfg(target_pointer_width = "32")] + const _USER_MSG_HDR_SIZE_32: () = + assert!(core::mem::size_of::>() == 28); + const TUN_IP_ADDR: [u8; 4] = [10, 0, 0, 2]; const TUN_IP_ADDR_STR: &str = "10.0.0.2"; const TUN_DEVICE_NAME: &str = "tun99"; @@ -2044,16 +2052,15 @@ mod tests { iov_len: buf2.len(), }, ]; - let hdr = litebox_common_linux::UserMsgHdr { - msg_name: ConstPtr::from_usize(0), - msg_namelen: 0, - #[cfg(target_pointer_width = "64")] - _pad: 0, - msg_iov: ConstPtr::from_usize(iovec.as_ptr() as usize), - msg_iovlen: iovec.len(), - msg_control: ConstPtr::from_usize(0), - msg_controllen: 0, - msg_flags: SendFlags::empty(), + let hdr = { + use zerocopy::FromZeros as _; + let mut h = litebox_common_linux::UserMsgHdr::::new_zeroed(); + h.msg_name = ConstPtr::from_usize(0); + h.msg_iov = ConstPtr::from_usize(iovec.as_ptr() as usize); + h.msg_iovlen = iovec.len(); + h.msg_control = ConstPtr::from_usize(0); + h.msg_flags = SendFlags::empty(); + h }; assert_eq!( task.do_sendmsg(client_fd, &hdr, SendFlags::empty()) From e8394a325d927aeb7872a1516b5e329004d46a9a Mon Sep 17 00:00:00 2001 From: weitengchen Date: Tue, 17 Mar 2026 22:07:50 +0000 Subject: [PATCH 6/6] fix --- litebox_common_linux/src/lib.rs | 6 ++---- litebox_shim_linux/src/syscalls/net.rs | 13 ++++--------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/litebox_common_linux/src/lib.rs b/litebox_common_linux/src/lib.rs index 3c076426a..abd6eee80 100644 --- a/litebox_common_linux/src/lib.rs +++ b/litebox_common_linux/src/lib.rs @@ -1804,16 +1804,14 @@ impl Clone for UserMsgHdr>() == 56); - #[cfg(target_pointer_width = "32")] - const _USER_MSG_HDR_SIZE_32: () = - assert!(core::mem::size_of::>() == 28); + const _USER_MSG_HDR_SIZE: () = assert!( + core::mem::size_of::>() + == core::mem::size_of::() + ); const TUN_IP_ADDR: [u8; 4] = [10, 0, 0, 2]; const TUN_IP_ADDR_STR: &str = "10.0.0.2"; @@ -2055,11 +2053,8 @@ mod tests { let hdr = { use zerocopy::FromZeros as _; let mut h = litebox_common_linux::UserMsgHdr::::new_zeroed(); - h.msg_name = ConstPtr::from_usize(0); h.msg_iov = ConstPtr::from_usize(iovec.as_ptr() as usize); h.msg_iovlen = iovec.len(); - h.msg_control = ConstPtr::from_usize(0); - h.msg_flags = SendFlags::empty(); h }; assert_eq!(