Skip to content

Support recvmsg#777

Open
CvvT wants to merge 11 commits into
mainfrom
weiteng/add_recvmsg
Open

Support recvmsg#777
CvvT wants to merge 11 commits into
mainfrom
weiteng/add_recvmsg

Conversation

@CvvT
Copy link
Copy Markdown
Contributor

@CvvT CvvT commented Apr 15, 2026

Support syscall recvmsg.

Some flags like MSG_PEEK is not supported yet but can be added when needed.

Also fix a message boundary issue for datagram unix socket, i.e., one read should only read one message.

@CvvT CvvT marked this pull request as ready for review April 15, 2026 22:49
Comment thread litebox_shim_linux/src/syscalls/net.rs
Comment thread litebox_shim_linux/src/syscalls/net.rs Outdated
@CvvT CvvT force-pushed the weiteng/add_recvmsg branch from 5441699 to 0d5cb58 Compare May 9, 2026 01:04
Copy link
Copy Markdown
Member

@wdcui wdcui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

Comment on lines +1589 to +1603
let size = self.do_recvfrom(
sockfd,
recv_buf,
flags,
if want_source {
Some(&mut source_addr)
} else {
None
},
)?;

// Set MSG_TRUNC if the received message was larger than the total buffer.
if size > total_iov_capacity {
ret_flags |= ReceiveFlags::TRUNC;
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correctness bug — MSG_TRUNC not set for truncated INET datagrams
litebox_shim_linux/src/syscalls/net.rs:1600-1603. The unix path now reports the full message size, so the size > total_iov_capacity check works. The INET path (DatagramSocketChannel::try_read) already caps return to min(buf.len(), data.len()), so the comparison
can never trigger and MSG_TRUNC is never set for inet UDP. Suggested: always pass ReceiveFlags::TRUNC to do_recvfrom so the proxy reports the real datagram size, then derive output flags from the comparison.

I only fixed unix datagram socket previously. I updated udp socket as well to return the actual size of the message instead of the length of the copied data. Tests are also updated to cover udp.


if msg_controllen != 0 {
log_unsupported!("ancillary data is not supported");
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correctness — msg_controllen never zeroed on return
net.rs:1565-1567. Linux always writes back msg_controllen (to the cmsg bytes written, 0 otherwise). The shim only logs and proceeds. Same for MSG_CTRUNC: if ancillary data was requested but not delivered, the kernel signals truncation; the shim silently drops the request.

We don't support ancillary data or control message yet. For now, just set msg_controllen to zero.

Comment thread litebox_shim_linux/src/syscalls/net.rs Outdated
Comment on lines +1594 to +1595
// Heap-allocate the recv buffer to avoid stack overflow for large iovecs.
let mut buffer = alloc::vec![0u8; total_iov_capacity];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correctness — MAX_LEN = 65536 silently caps user iov capacity
net.rs:1552, 1574-1579. For unix-datagram messages between 64 KiB and sum(iov_len), the code sets MSG_TRUNC even though everything would fit. Either remove the cap, return EMSGSIZE, or document it.

Copilot suggested to use try_reserve_exact which returns an error when OOM.

@github-actions
Copy link
Copy Markdown

🤖 SemverChecks 🤖 ⚠️ Potential breaking API changes detected ⚠️

Click for details
--- failure enum_no_repr_variant_discriminant_changed: enum variant had its discriminant change value ---

Description:
The enum's variant had its discriminant value change. This breaks downstream code that used its value via a numeric cast like `as isize`.
        ref: https://doc.rust-lang.org/reference/items/enumerations.html#assigning-discriminant-values
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/enum_no_repr_variant_discriminant_changed.ron

Failed in:
  variant SyscallRequest::Bind 38 -> 39 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1919
  variant SyscallRequest::Listen 39 -> 40 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1924
  variant SyscallRequest::Setsockopt 40 -> 41 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1928
  variant SyscallRequest::Getsockopt 41 -> 42 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1935
  variant SyscallRequest::Getsockname 42 -> 43 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1942
  variant SyscallRequest::Getpeername 43 -> 44 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1947
  variant SyscallRequest::Uname 44 -> 45 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1952
  variant SyscallRequest::Fcntl 45 -> 46 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1955
  variant SyscallRequest::Getcwd 46 -> 47 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1959
  variant SyscallRequest::EpollCtl 47 -> 48 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1963
  variant SyscallRequest::EpollPwait 48 -> 49 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1969
  variant SyscallRequest::EpollCreate 49 -> 50 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1977
  variant SyscallRequest::Ppoll 50 -> 51 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1981
  variant SyscallRequest::Pselect 51 -> 52 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1988
  variant SyscallRequest::ArchPrctl 52 -> 53 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1996
  variant SyscallRequest::Readlink 53 -> 54 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1999
  variant SyscallRequest::Readlinkat 54 -> 55 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2004
  variant SyscallRequest::Openat 55 -> 56 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2010
  variant SyscallRequest::Ftruncate 56 -> 57 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2016
  variant SyscallRequest::Unlinkat 57 -> 58 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2020
  variant SyscallRequest::Newfstatat 58 -> 59 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2026
  variant SyscallRequest::Eventfd2 59 -> 60 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2032
  variant SyscallRequest::Pipe2 60 -> 61 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2036
  variant SyscallRequest::Clone 61 -> 62 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2040
  variant SyscallRequest::Clone3 62 -> 63 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2043
  variant SyscallRequest::SetThreadArea 63 -> 64 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2048
  variant SyscallRequest::ClockGettime 64 -> 65 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2051
  variant SyscallRequest::ClockGetres 65 -> 66 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2055
  variant SyscallRequest::ClockNanosleep 66 -> 67 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2059
  variant SyscallRequest::Gettimeofday 67 -> 68 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2065
  variant SyscallRequest::Time 68 -> 69 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2069
  variant SyscallRequest::Getrlimit 69 -> 70 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2072
  variant SyscallRequest::Setrlimit 70 -> 71 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2076
  variant SyscallRequest::Prlimit 71 -> 72 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2080
  variant SyscallRequest::SetTidAddress 72 -> 73 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2091
  variant SyscallRequest::Gettid 73 -> 74 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2094
  variant SyscallRequest::SetRobustList 74 -> 75 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2095
  variant SyscallRequest::GetRobustList 75 -> 76 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2098
  variant SyscallRequest::GetRandom 76 -> 77 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2103
  variant SyscallRequest::Getpid 77 -> 78 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2108
  variant SyscallRequest::Getppid 78 -> 79 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2109
  variant SyscallRequest::Getuid 79 -> 80 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2110
  variant SyscallRequest::Geteuid 80 -> 81 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2111
  variant SyscallRequest::Getgid 81 -> 82 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2112
  variant SyscallRequest::Getegid 82 -> 83 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2113
  variant SyscallRequest::Sysinfo 83 -> 84 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2114
  variant SyscallRequest::CapGet 84 -> 85 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2117
  variant SyscallRequest::GetDirent64 85 -> 86 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2121
  variant SyscallRequest::SchedGetAffinity 86 -> 87 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2126
  variant SyscallRequest::SchedYield 87 -> 88 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2131
  variant SyscallRequest::Futex 88 -> 89 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2132
  variant SyscallRequest::Execve 89 -> 90 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2135
  variant SyscallRequest::Umask 90 -> 91 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2140
  variant SyscallRequest::Prctl 91 -> 92 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2143
  variant SyscallRequest::Alarm 92 -> 93 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2146
  variant SyscallRequest::SetITimer 93 -> 94 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2149

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants