Skip to content

drivers/net/ftmac100: Validate RX frame length before memcpy - #21304

Merged
acassis merged 1 commit into
apache:masterfrom
Swatantra-66:net/ftmac100-rx-bounds
Nov 1, 2026
Merged

acassis merged 1 commit into
apache:masterfrom
Swatantra-66:net/ftmac100-rx-bounds

Conversation

@Swatantra-66

Copy link
Copy Markdown
Contributor

Summary

Fixes #21111

In ftmac100_receive(), the device-reported frame length was read directly from the DMA descriptor status word (FTMAC100_RXDES0_RFL(rxdes->rxdes0), 0..2047) and copied into priv->ft_dev.d_buf without checking if it exceeds CONFIG_NET_ETH_PKTSIZE or satisfies the minimum Ethernet frame header length ETH_HDRLEN.

Because g_pktbuf is sized to PKTBUF_SIZE (MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE, ~592 or ~1518 bytes depending on configuration), an incoming oversized frame (or malfunctioning/compromised MAC) could trigger an out-of-bounds write past the packet buffer into adjacent BSS variables.

This change adds an input bounds check:

  1. Drops frames where len < ETH_HDRLEN or len > CONFIG_NET_ETH_PKTSIZE.
  2. Increments NETDEV_RXERRORS(&priv->ft_dev).
  3. Safely recycles the RX descriptor back to DMA ownership (FTMAC100_RXDES0_RXDMA_OWN) and advances rx_pointer, preventing descriptor ring stalling or memory leaks without performing the memcpy.

Matches the pattern in sibling network drivers (dm90x0.c, enc28j60.c, encx24j600.c, lan91c111.c, w5500.c).

Impact

  • Is new feature added? No.
  • Is existing feature changed? Yes, drops oversized or truncated/runt RX frames in FTMAC100.
  • User impact: None for normal traffic; protects systems from heap/BSS memory corruption caused by malformed or oversized wire frames.
  • Build impact: None.
  • Hardware impact: FTMAC100 10/100 Ethernet Controller (CONFIG_NET_FTMAC100).
  • Security impact: Resolves CWE-120 / CWE-787 (Buffer Copy without Checking Size of Input / Out-of-bounds Write).
  • Compatibility: Fully backward compatible.

Testing

  • Code style verified with tools/nxstyle drivers/net/ftmac100.c:
    0 errors, 0 warnings
    
  • Commit message format and guidelines verified with tools/checkpatch.sh -m -g:
    ✔️ All checks pass
    
  • Git diff whitespace check verified with git diff --check:
    0 errors
    
  • Make / CMake build-system parity verified: no build files modified

@github-actions github-actions Bot added Area: Networking Effects networking subsystem Size: S The size of the change in this PR is small labels Oct 31, 2026
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

In ftmac100_receive(), the device-reported frame length was read
directly from the DMA descriptor (FTMAC100_RXDES0_RFL, 0..2047)
and copied into priv->ft_dev.d_buf without verifying that it fits
within CONFIG_NET_ETH_PKTSIZE or satisfies the minimum Ethernet
frame header length ETH_HDRLEN.

An oversized packet could trigger an out-of-bounds write past the
fixed packet buffer into adjacent BSS memory.

Add a bounds check to drop frames with invalid lengths (< ETH_HDRLEN
or > CONFIG_NET_ETH_PKTSIZE), increment NETDEV_RXERRORS, and return
the descriptor to hardware DMA ownership without performing memcpy.

Fixes apache#21111.

Signed-off-by: Swatantra Yadav <[email protected]>
Assisted-by: Google Gemini
@Swatantra-66
Swatantra-66 force-pushed the net/ftmac100-rx-bounds branch from 71baf6c to 9b0048f Compare October 31, 2026 13:55
@acassis
acassis merged commit a8f6014 into apache:master Nov 1, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Networking Effects networking subsystem Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] drivers/net/ftmac100.c: device-reported RX frame length drives an unbounded memcpy into the fixed packet buffer (OOB write)

3 participants