Repository navigation
net/icmpv6: validate msg_iovlen and defer iov dereference - #21707
Merged
Merged
Conversation
xiaoxiang781216
approved these changes
Nov 11, 2026
|
Contributor
|
ci fixed by #21771. |
POSIX IEEE Std 1003.1 requires sendmsg() and recvmsg() to validate msg_iovlen and fail with -EMSGSIZE when msg_iovlen is 0 or greater than IOV_MAX. Furthermore, dereferencing msg->msg_iov in local variable initializations prior to validating msg_iovlen and msg_iov != NULL risks NULL pointer dereference or out-of-bounds access. This patch addresses these issues in net/icmpv6: 1. Defer dereferencing msg->msg_iov until after validating msg_iovlen and confirming msg->msg_iov != NULL. 2. Return -EMSGSIZE when msg_iovlen == 0 or msg_iovlen > IOV_MAX. 3. Reject invalid buffers where len > 0 && buf == NULL with -EINVAL. 4. Set MSG_TRUNC in msg->msg_flags when received data exceeds the user buffer in both icmpv6_readahead() and recvfrom_eventhandler(). 5. Widen recv_buflen to size_t and recv_result to ssize_t in struct icmpv6_recvfrom_s to prevent 16-bit integer wraparound on >=64KiB buffers. 6. Remove artificial len < ICMPv6_HDRLEN rejection to allow short and zero-length buffers to reach truncation paths per POSIX. 7. Use iob_copyout() in recvfrom_eventhandler() to safely copy across chained I/O buffers (dev->d_iob) without out-of-bounds heap read. Assisted-by: gemini-3.8-flash Signed-off-by: Swatantra Yadav <[email protected]>
Swatantra-66
force-pushed
the
fix/icmpv6-iovlen-bounds
branch
from
November 14, 2026 07:26
a4cf606 to
70f1c2b
Compare
GUIDINGLI
approved these changes
Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
POSIX IEEE Std 1003.1 explicitly mandates for both
sendmsg()andrecvmsg():In
net/icmpv6(icmpv6_sendmsg.candicmpv6_recvmsg.c), sister vulnerabilities to merged PR #21649 (net/bluetooth) and PR #21698 (net/icmp) existed:msg->msg_iov->iov_baseandmsg->msg_iov->iov_lenwere dereferenced in local variable initializations before validatingmsg->msg_iovlenormsg->msg_iov. Passingmsg_iovlen == 0ormsg_iov == NULLresulted in immediate NULL pointer / out-of-bounds dereferences (CWE-476 / CWE-125).msg_iovlen <= 0ormsg_iovlen > IOV_MAXreturned-ENOTSUPinstead of POSIX-mandated-EMSGSIZE.msg_flagswas never updated withMSG_TRUNC.struct icmpv6_recvfrom_s,recv_buflenwas typed asuint16_tandrecv_resultasint16_t. Providing a standard 64 KiB (65,536 bytes) buffer wrappedrecv_buflento 0, prematurely discarding valid replies.icmpv6_recvmsg(), an artificial checkif (len < ICMPv6_HDRLEN) return -EINVAL;prevented callers from providing short or zero-length buffers to receive truncated prefixes or probe datagram arrival.recvfrom_eventhandler(), large replies spanning chained I/O buffers (dev->d_iob) were copied usingmemcpy(pstate->recv_buf, IPBUF(IPv6_HDRLEN), recvsize);. BecauseIPBUF(IPv6_HDRLEN)points only into the first IOB buffer, copying past the first IOB resulted in heap out-of-bounds reads (CWE-125).Before & After Comparison
msg->msg_iovlen == 0-EMSGSIZEper POSIXmsg->msg_iovlen > IOV_MAX-ENOTSUP-EMSGSIZEper POSIXmsg->msg_iov == NULL-EINVALlen > 0 && buf == NULL-EINVALuint16_t), packet discardedsize_t, accepted properlymsg->msg_flags |= MSG_TRUNCin both readahead & eventhandler< ICMPv6_HDRLEN)-EINVALMSG_TRUNCmemcpy(..., IPBUF(IPv6_HDRLEN), ...)reads past 1st IOB (Heap OOB read)iob_copyout(...)safely traverses the chained IOB segmentsImpact
-EMSGSIZE) and truncation reporting (MSG_TRUNC) forIPPROTO_ICMP6sockets; support fornet/icmpv6.Testing
Host & Configuration
nuttx-builder) on Windows 11sim:vpnkit(CONFIG_NET_ICMPv6=y,CONFIG_NET_ICMPv6_SOCKET=y)1. Coding Style Verification (
nxstyle)2. Patch Check (
checkpatch.sh)3. Compilation & Link Log (
sim:vpnkit)Clean build and link with 0 compiler warnings and 0 errors.
What Was Not Tested
Physical hardware target architectures (ARM, RISC-V, Xtensa boards) or protected/kernel build modes; verified on simulator (
sim:vpnkit).