Repository navigation
drivers/net/ftmac100: Validate RX frame length before memcpy - #21304
Merged
Merged
Conversation
|
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
force-pushed
the
net/ftmac100-rx-bounds
branch
from
October 31, 2026 13:55
71baf6c to
9b0048f
Compare
xiaoxiang781216
approved these changes
Oct 31, 2026
acassis
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 #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 intopriv->ft_dev.d_bufwithout checking if it exceedsCONFIG_NET_ETH_PKTSIZEor satisfies the minimum Ethernet frame header lengthETH_HDRLEN.Because
g_pktbufis sized toPKTBUF_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:
len < ETH_HDRLENorlen > CONFIG_NET_ETH_PKTSIZE.NETDEV_RXERRORS(&priv->ft_dev).FTMAC100_RXDES0_RXDMA_OWN) and advancesrx_pointer, preventing descriptor ring stalling or memory leaks without performing thememcpy.Matches the pattern in sibling network drivers (
dm90x0.c,enc28j60.c,encx24j600.c,lan91c111.c,w5500.c).Impact
CONFIG_NET_FTMAC100).Testing
tools/nxstyle drivers/net/ftmac100.c:tools/checkpatch.sh -m -g:git diff --check: