Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [PATCH] net: fec: reject oversized fragments before bounce-buffer memcpy
@ 2026-09-23 14:11 Aldo Ariel Panzardo
  2026-09-23 18:59 ` Andrew Lunn
  2026-09-24 14:12 ` sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: Aldo Ariel Panzardo @ 2026-09-23 14:11 UTC (permalink / raw)
  To: wei.fang
  Cc: frank.li, shenwei.wang, imx, netdev, linux-kernel, stable,
	Aldo Ariel Panzardo, Sashiko

fec_enet_txq_submit_frag_skb() and fec_enet_txq_submit_skb() copy
transmit data into a per-ring bounce buffer when the source address is
misaligned or the FEC_QUIRK_SWAP_FRAME quirk is active. The bounce
buffers are allocated as kmalloc(FEC_ENET_TX_FRSIZE) where
FEC_ENET_TX_FRSIZE is 2048 bytes.

However, skb_frag_size() can return up to PAGE_SIZE (4096 on most
architectures) for scatter-gather fragments, and skb_headlen() can
exceed 2048 for certain GSO packets. When this happens the memcpy
overflows the bounce buffer by up to 2048 bytes, corrupting adjacent
heap objects.

Add a length check before each bounce-buffer copy. If the data exceeds
the bounce buffer capacity, fall through to the error path rather than
performing the out-of-bounds write.

Fixes: 6605b730c061 ("FEC: Add alignment handling for FEC driver")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
---
 drivers/net/ethernet/freescale/fec_main.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 794ec42..8614984 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -558,6 +558,8 @@ fec_enet_txq_submit_frag_skb(struct fec_enet_priv_tx_q *txq,
 		index = fec_enet_get_bd_index(bdp, &txq->bd);
 		if (((unsigned long) bufaddr) & fep->tx_align ||
 			fep->quirks & FEC_QUIRK_SWAP_FRAME) {
+			if (frag_len > FEC_ENET_TX_FRSIZE)
+				goto dma_mapping_error;
 			memcpy(txq->tx_bounce[index], bufaddr, frag_len);
 			bufaddr = txq->tx_bounce[index];
 
@@ -634,6 +636,8 @@ static int fec_enet_txq_submit_skb(struct fec_enet_priv_tx_q *txq,
 	index = fec_enet_get_bd_index(bdp, &txq->bd);
 	if (((unsigned long) bufaddr) & fep->tx_align ||
 		fep->quirks & FEC_QUIRK_SWAP_FRAME) {
+		if (buflen > FEC_ENET_TX_FRSIZE)
+			goto release;
 		memcpy(txq->tx_bounce[index], skb->data, buflen);
 		bufaddr = txq->tx_bounce[index];
 
-- 
2.43.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: fec: reject oversized fragments before bounce-buffer memcpy
  2026-09-23 14:11 [PATCH] net: fec: reject oversized fragments before bounce-buffer memcpy Aldo Ariel Panzardo
@ 2026-09-23 18:59 ` Andrew Lunn
  2026-09-24 14:12 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2026-09-23 18:59 UTC (permalink / raw)
  To: Aldo Ariel Panzardo
  Cc: wei.fang, frank.li, shenwei.wang, imx, netdev, linux-kernel,
	stable, Sashiko

> Fixes: 6605b730c061 ("FEC: Add alignment handling for FEC driver")

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

Please set the Subject: line correctly.

    Andrew

---
pw-bot: cr

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: fec: reject oversized fragments before bounce-buffer memcpy
  2026-09-23 14:11 [PATCH] net: fec: reject oversized fragments before bounce-buffer memcpy Aldo Ariel Panzardo
  2026-09-23 18:59 ` Andrew Lunn
@ 2026-09-24 14:12 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-09-24 14:12 UTC (permalink / raw)
  To: Aldo Ariel Panzardo; +Cc: imx, Frank.Li

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] net: fec: undefined label 'release' causes build failure
--

commit 6a879b984d90eaab6d6db0210d5b4b63b7aaceff
Author: Aldo Ariel Panzardo <qwe.aldo@gmail.com>

net: fec: reject oversized fragments before bounce-buffer memcpy

This commit adds bounds checks before copying transmit data into the per-ring
bounce buffer to prevent memory corruption when fragment sizes exceed the
buffer capacity.

> diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
> index 794ec427b0ee6..861498448fe36 100644
> --- a/drivers/net/ethernet/freescale/fec_main.c
> +++ b/drivers/net/ethernet/freescale/fec_main.c
[ ... ]
> @@ -634,6 +636,8 @@ static int fec_enet_txq_submit_skb(struct fec_enet_priv_tx_q *txq,
>  	index = fec_enet_get_bd_index(bdp, &txq->bd);
>  	if (((unsigned long) bufaddr) & fep->tx_align ||
>  		fep->quirks & FEC_QUIRK_SWAP_FRAME) {
> +		if (buflen > FEC_ENET_TX_FRSIZE)
> +			goto release;

[Severity: Low]
Does this code introduce a build failure? The label release appears to be
undefined in fec_enet_txq_submit_skb(), which causes compilation to fail
with an undefined label error.

>  		memcpy(txq->tx_bounce[index], skb->data, buflen);
>  		bufaddr = txq->tx_bounce[index];
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260923141154.2415545-1-qwe.aldo@gmail.com?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-24 14:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-23 14:11 [PATCH] net: fec: reject oversized fragments before bounce-buffer memcpy Aldo Ariel Panzardo
2026-09-23 18:59 ` Andrew Lunn
2026-09-24 14:12 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox