Support recvmsg#777
Conversation
| 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; | ||
| } |
There was a problem hiding this comment.
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"); | ||
| } |
There was a problem hiding this comment.
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.
| // Heap-allocate the recv buffer to avoid stack overflow for large iovecs. | ||
| let mut buffer = alloc::vec![0u8; total_iov_capacity]; |
There was a problem hiding this comment.
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.
|
🤖 SemverChecks 🤖 Click for details |
Support syscall
recvmsg.Some flags like
MSG_PEEKis 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.