Repository navigation
net/ieee802154: validate msg_iovlen and defer iov dereference in sendmsg/recvmsg - #21681
Merged
GUIDINGLI merged 1 commit intoNov 17, 2026
Merged
Conversation
xiaoxiang781216
approved these changes
Nov 11, 2026
|
Contributor
Author
|
@xiaoxiang781216, It looks like Linux (arm-nxp) hit a transient timeout/flakiness unrelated to net/ieee802154. |
POSIX IEEE Std 1003.1 explicitly mandates for both sendmsg() and recvmsg():
"[EMSGSIZE] The msg_iovlen member of the msghdr structure is less than
or equal to 0 or is greater than {IOV_MAX}."
In net/ieee802154:
1. In ieee802154_sendmsg() and ieee802154_recvmsg(), msg->msg_iov->iov_base
and msg->msg_iov->iov_len were dereferenced during local variable
declarations before validating msg->msg_iovlen or msg->msg_iov. Passing
msg_iovlen == 0 or msg_iov == NULL resulted in an immediate out-of-bounds
pointer dereference (CWE-476 / CWE-125).
2. Passing msg_iovlen <= 0 or msg_iovlen > IOV_MAX returned -ENOTSUP
instead of POSIX-mandated -EMSGSIZE.
3. In ieee802154_recvfrom_rxqueue(), copylen was not clamped to
pstate->ir_buflen, allowing incoming frames larger than the user
receive buffer to cause a buffer overflow (CWE-120).
4. In ieee802154_recvmsg() and ieee802154_recvfrom_eventhandler(), completion
checked (ret > 0). When receiving a zero-length frame or zero-byte read,
ret == 0 was not recognized as completion, causing the calling thread to
sleep indefinitely on state.ir_sem.
This commit:
- Adds upfront validation of msg->msg_iovlen == 0 || msg->msg_iovlen > IOV_MAX,
returning -EMSGSIZE.
- Preserves -ENOTSUP when msg->msg_iovlen > 1 (scatter/gather not supported).
- Validates msg->msg_iov == NULL and non-null buffer pointers for positive
lengths (len > 0 && buf == NULL), returning -EINVAL.
- Defers accessing msg->msg_iov[0] until all bounds and nullity checks pass.
- Clamps copylen to pstate->ir_buflen in ieee802154_recvfrom_rxqueue() and
sets MSG_TRUNC in msg->msg_flags when truncation occurs.
- Changes completion checks to (ret >= 0) to allow zero-byte frames to
complete cleanly.
- Adds #include <limits.h> in both files.
Assisted-by: gemini-3.8-flash
Signed-off-by: Swatantra Yadav <[email protected]>
Swatantra-66
force-pushed
the
fix/ieee802154-iovlen-bounds
branch
from
November 14, 2026 07:26
32d84a3 to
e432e67
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/ieee802154:ieee802154_sendmsg()andieee802154_recvmsg(),msg->msg_iov->iov_baseandmsg->msg_iov->iov_lenwere dereferenced during local variable declarations before validatingmsg->msg_iovlenormsg->msg_iov. Passingmsg_iovlen == 0ormsg_iov == NULLresulted in an immediate out-of-bounds pointer dereference (CWE-476 / CWE-125).msg_iovlen <= 0ormsg_iovlen > IOV_MAXreturned-ENOTSUPinstead of POSIX-mandated-EMSGSIZE.ieee802154_recvfrom_rxqueue(),copylenwas not clamped topstate->ir_buflen, allowing incoming frames larger than the user receive buffer to cause a buffer overflow (CWE-120).ieee802154_recvmsg()andieee802154_recvfrom_eventhandler(), completion checked(ret > 0). When receiving a zero-length frame or zero-byte read,ret == 0was not recognized as completion, causing the calling thread to sleep indefinitely onstate.ir_sem.This patch:
msg->msg_iovlen == 0 || msg->msg_iovlen > IOV_MAX, returning-EMSGSIZE.-ENOTSUPwhenmsg->msg_iovlen > 1(scatter/gather not supported).msg->msg_iov == NULLand non-null buffer pointers for positive lengths (len > 0 && buf == NULL), returning-EINVAL.msg->msg_iov[0]until all bounds and nullity checks pass.copylentopstate->ir_bufleninieee802154_recvfrom_rxqueue()and setsMSG_TRUNCinmsg->msg_flagswhen truncation occurs per datagram semantics.(ret >= 0)to allow zero-byte frames to complete cleanly.#include <limits.h>in both files.Before & After Comparison
msg->msg_iovDereferencemsg_iovlenor NULLmsg_iovlen <= 0or> IOV_MAX-ENOTSUP(POSIX violation)-EMSGSIZEper POSIX IEEE Std 1003.1msg_iov == NULLor(len > 0 && buf == NULL)-EINVALmemcpyofcopylen = iob->io_len - iob->io_offsetintoir_buffer(CWE-120)ir_buflen, flagsMSG_TRUNCinmsg->msg_flagsret > 0, causing 0-byte frames to fail completion check and hang forever onstate.ir_semret >= 0, cleanly completing and returning0Impact
Testing
nuttx-builder)sim:pf_ieee802154Build Command:
./tools/configure.sh -l sim:pf_ieee802154 make -j$(nproc)Build & Link Output:
Code Style & Checkpatch: