Skip to content

wireless/ieee802154/i8shark: validate received frame length and offset - #3951

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:fix/i8shark-frame-bounds
Nov 1, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:fix/i8shark-frame-bounds

Conversation

@Swatantra-66

Copy link
Copy Markdown
Contributor

Summary

Fixes a radio-triggered stack buffer overflow and integer underflows in i8shark when receiving IEEE 802.15.4 frames (#3950).

In promiscuous mode, the MAC character driver reports rx->length = io_len + fcslen without clamping to IEEE802154_MAX_PHY_PACKET_SIZE (127). Sizing memcpy(&zepframe[i], ...) with i = 32 into the exact-sized zepframe[159] stack buffer allows frames up to 129 bytes to write past zepframe[158]. Furthermore, CONFIG_IEEE802154_I8SHARK_XBEE_APPHDR had a signed underflow (frame.length - frame.offset - 2), and CONFIG_IEEE802154_I8SHARK_SUPPRESS_FCS had an unsigned underflow when frame.length < fcslen.

Key changes:

  1. Immediately validate frame.length >= 2, frame.length <= IEEE802154_MAX_PHY_PACKET_SIZE, and frame.offset <= frame.length.
  2. In CONFIG_IEEE802154_I8SHARK_XBEE_APPHDR, drop frames where frame.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.
  3. In CONFIG_IEEE802154_I8SHARK_SUPPRESS_FCS, check ieee802154_getfcslen() return value and drop frames where frame.length < fcslen to prevent uint8_t underflow.
  4. Add secondary check (size_t)(i + frame.length) > sizeof(zepframe) before memcpy.
  5. Zero zepframe so 10 reserved ZEP header bytes do not leak uninitialized stack memory over UDP.
  6. Parenthesize #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

  • Prevents stack buffer overflow and crashes in i8shark from malformed or maximal radio frames.
  • Prevents leaking stack data over UDP in reserved ZEP header fields.

Testing

  • Verified with checkpatch.sh -m -g and nxstyle (0 errors, 0 warnings).
  • Validated code paths across default, CONFIG_IEEE802154_I8SHARK_XBEE_APPHDR, and CONFIG_IEEE802154_I8SHARK_SUPPRESS_FCS configurations.

Fixes #3950

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
@Swatantra-66 Swatantra-66 reopened this Nov 1, 2026
@xiaoxiang781216
xiaoxiang781216 merged commit 54374b3 into apache:master Nov 1, 2026
63 of 82 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants