Re: [PATCH net v3] net: bgmac: fix RX frame length check

From: Florian Fainelli

Date: Fri Nov 20 2026 - 13:26:44 EST


On 10/29/26 10:31, Rosen Penev wrote:
While reviewing commit 77dac783f113
("net: bgmac: rate limit RX error messages"), Florian spotted that the RX
length sanity check compares the length reported in the RX header against
BGMAC_RX_ALLOC_SIZE. That is the size of the whole fragment, including the
space reserved for struct skb_shared_info. The data area handed to the
hardware is only BGMAC_RX_BUF_SIZE bytes, and the frame starts
BGMAC_RX_FRAME_OFFSET bytes into it, so at most BGMAC_RX_MAX_FRAME_SIZE
bytes of a frame fit in one RX buffer.

A corrupted length between those two limits passes the check, and the
following skb_put() runs past the skb tailroom and calls
skb_over_panic() instead of dropping the frame.

The check has no lower bound either. A length below ETH_FCS_LEN wraps
when the FCS is subtracted, so skb_put() asks for almost 64 KiB and hits
the same skb_over_panic(). A length that leaves less than an Ethernet
header makes eth_type_trans() parse bytes the hardware never wrote.

Reject lengths below ETH_HLEN + ETH_FCS_LEN or above
BGMAC_RX_MAX_FRAME_SIZE, and print the bad length.

Only compile tested. Not tested on hardware.

Fixes: 6a6c708469c9 ("bgmac: add check for oversized packets")
Signed-off-by: Rosen Penev <rosenp@xxxxxxxxx>
Reviewed-by: Florian Fainelli <florian.fainelli@xxxxxxxxxxxx>

Rosen, can you address Sashiko's feedback and resubmit? This patch conflicts with one I have in my tree to support flow accelerator and I would prefer to get yours in because it's a tad more complete than mine, and yours has precedence.

Thanks!
--
Florian