Repository navigation
wireless/ieee802154/i8shark: validate received frame length and offset - #3951
Merged
xiaoxiang781216 merged 1 commit intoNov 1, 2026
Merged
Conversation
i8shark copies frames from the MAC character driver into a fixed 159-byte stack buffer using frame.length and frame.offset without validation. In promiscuous mode the driver does not clamp the length, so a frame transmitted over the air could overflow zepframe, and the XBEE_APPHDR and SUPPRESS_FCS variants could underflow their length arithmetic. - Drop frames with length < 2, length > IEEE802154_MAX_PHY_PACKET_SIZE or offset > length. - With XBEE_APPHDR, drop frames shorter than offset + 4 (app header plus FCS are both stripped). - With SUPPRESS_FCS, check the getfcslen() result and drop frames shorter than the FCS to avoid uint8_t underflow. - Check the final copy size against sizeof(zepframe). - Zero zepframe so reserved ZEP header bytes do not leak stack contents. - Parenthesize I8SHARK_MAX_ZEPFRAME. Fixes apache#3950 Signed-off-by: Swatantra Yadav <[email protected]> Assisted-by: Google Gemini
xiaoxiang781216
approved these changes
Nov 1, 2026
casaroli
approved these changes
Nov 1, 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
Fixes a radio-triggered stack buffer overflow and integer underflows in
i8sharkwhen receiving IEEE 802.15.4 frames (#3950).In promiscuous mode, the MAC character driver reports
rx->length = io_len + fcslenwithout clamping toIEEE802154_MAX_PHY_PACKET_SIZE(127). Sizingmemcpy(&zepframe[i], ...)withi = 32into the exact-sizedzepframe[159]stack buffer allows frames up to 129 bytes to write pastzepframe[158]. Furthermore,CONFIG_IEEE802154_I8SHARK_XBEE_APPHDRhad a signed underflow (frame.length - frame.offset - 2), andCONFIG_IEEE802154_I8SHARK_SUPPRESS_FCShad an unsigned underflow whenframe.length < fcslen.Key changes:
frame.length >= 2,frame.length <= IEEE802154_MAX_PHY_PACKET_SIZE, andframe.offset <= frame.length.CONFIG_IEEE802154_I8SHARK_XBEE_APPHDR, drop frames whereframe.length < frame.offset + 4(since 2-byte app header + 2-byte FCS are stripped). In XBEE mode, frames too short to contain the app header plus FCS (e.g. ACKs) are now dropped instead of being forwarded as malformed packets.CONFIG_IEEE802154_I8SHARK_SUPPRESS_FCS, checkieee802154_getfcslen()return value and drop frames whereframe.length < fcslento preventuint8_tunderflow.(size_t)(i + frame.length) > sizeof(zepframe)beforememcpy.zepframeso 10 reserved ZEP header bytes do not leak uninitialized stack memory over UDP.#define I8SHARK_MAX_ZEPFRAME (IEEE802154_MAX_PHY_PACKET_SIZE + ZEP_MAX_HDRSIZE).Note: Frames with length 128 or 129 bytes are discarded by this userspace clamp to prevent buffer overflow. Clamping in the kernel MAC character driver is out of scope and can be addressed separately in
nuttx.Impact
i8sharkfrom malformed or maximal radio frames.Testing
checkpatch.sh -m -gandnxstyle(0 errors, 0 warnings).CONFIG_IEEE802154_I8SHARK_XBEE_APPHDR, andCONFIG_IEEE802154_I8SHARK_SUPPRESS_FCSconfigurations.Fixes #3950