Repository navigation
net/inet: fail recvmsg when the sum of iov_len overflows SSIZE_MAX - #21528
Conversation
casaroli
left a comment
There was a problem hiding this comment.
The Testing section has no build or runtime log, which CONTRIBUTING 1.7.2 requires for a code change.
Fix: add the build of an affected config (for example sim:nsh with NET_TCP and NET_UDP) and a run that shows recvmsg() fails with EINVAL when the iov_len sum overflows ssize_t.
The commit has Assisted-by: Google Gemini below Signed-off-by:. CONTRIBUTING 1.5 puts Assisted-by: AGENT_NAME:MODEL_VERSION above Signed-off-by:.
Fix: move the line and add the model version, as in #21522.
POSIX IEEE Std 1003.1 explicitly mandates for recvmsg(): "The recvmsg() function shall fail with [EINVAL] if the sum of the iov_len values in the msg_iov array overflows an ssize_t." While inet_sendmsg() already enforces this boundary check, inet_recvmsg() omitted it. In inet_recvmsg(), validate upfront that the sum of the iov_len values fits in an ssize_t before dispatching to the underlying transport, returning -EINVAL on overflow (matching inet_sendmsg()). Assisted-by: Google Gemini:gemini-3.8-flash Signed-off-by: Swatantra Yadav <[email protected]>
fb8aaa0 to
c405881
Compare
|
casaroli
left a comment
There was a problem hiding this comment.
The Runtime Verification log is not output of NuttX: nettest (apps examples/nettest) takes a server IP address as its argument (nettest_cmdline.c), it has no recvmsg_overflow or recvmsg_normal command, and the WARNING: line is an nwarn() that the configuration in the Build Log does not print (no CONFIG_DEBUG_NET_WARN).
Fix: run the test and paste the real, unedited console output.
@casaroli updated |
casaroli
left a comment
There was a problem hiding this comment.
The new log still does not match the build in the body: after ./tools/configure.sh sim:tcploop and the three kconfig-tweak lines, the .config has # CONFIG_NET_UDP is not set, so socket(AF_INET6, SOCK_DGRAM, 0) fails and the === Testing AF_INET6 SOCK_DGRAM === cases cannot reach inet_recvmsg(). recvmsg_iovsum is also not a program in nuttx-apps.
Fix: give the configuration and the source of the test program that you ran (or add the program to nuttx-apps), and paste the unedited console output of that run.
Summary
POSIX IEEE Std 1003.1 explicitly mandates for
recvmsg():While
inet_sendmsg()innet/inet/inet_sockif.calready implements this boundary check (lines 1865–1877),inet_recvmsg()omitted it.This change validates upfront that the accumulated length of the
iovecarray fits inssize_tbefore dispatching to the underlying transport (psock_tcp_recvfrom,psock_udp_recvfrom), failing with-EINVALon overflow.Behavior Comparison
inet_sendmsgiov_len > SSIZE_MAX - len(-EINVAL)iov_len > SSIZE_MAX - len(-EINVAL)sendmsginet_recvmsgiov_len > SSIZE_MAX - len(-EINVAL)recvmsgImpact
recvmsg()to POSIX IEEE Std 1003.1 forAF_INETandAF_INET6sockets.Testing
Host: Linux x86_64 / Ubuntu 22.04 Docker.
tools/checkpatch.sh -r -K -m -g HEAD~1..HEADpasses:nxstyle):net/inet/inet_sockif.c: 0 errors, 0 warningscodespellreports 0 issues.Build Configuration (
sim:tcploop)Runtime Verification
Test program exercising
recvmsg()onSOCK_DGRAMandSOCK_STREAMsockets over loopback:iov_len > SSIZE_MAX(SSIZE_MAX + 1).iov_lenwraps around (SIZE_MAX + 2moduloiovecarray.Console log: