* [PATCH] net: sparx5/lan969x: do not read past skb->len when injecting a frame
@ 2026-10-21 10:48 Daniel Machon
2026-10-21 11:25 ` Daniel Machon
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Machon @ 2026-10-21 10:48 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Steen Hegelund, UNGLinuxDriver, Bjarni Jonasson,
Lars Povlsen
Cc: Steen Hegelund, netdev, linux-arm-kernel, linux-kernel
sparx5_inject() writes the frame to the injection FIFO one 32-bit word
at a time, and pads frames shorter than 60 bytes with zero words.
Before this patch, the last word is loaded whole even when skb->len is
not a multiple of four, so 1 to 3 bytes past the end of the frame are
read. For a frame shorter than 60 bytes those bytes are also
transmitted, as VLD_BYTES marks the whole last word valid and the
padding starts at the next word.
Write the trailing bytes from a zeroed word. The number of words written
and VLD_BYTES are unchanged.
Found by an AI code review agent, and reproduced on lan969x and sparx5
with register injection: bytes 57 to 59 of a 57 byte frame were not
zero. With the fix they are zero, and traffic still passes on both
chips.
Fixes: f3cad2611a77 ("net: sparx5: add hostmode with phylink support")
Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
drivers/net/ethernet/microchip/sparx5/sparx5_packet.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c b/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c
index f713656f1fae..14c9ae673e35 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c
@@ -169,8 +169,8 @@ static int sparx5_inject(struct sparx5 *sparx5,
struct sk_buff *skb,
struct net_device *ndev)
{
+ u32 val, w, count, last;
int grp = INJ_QUEUE;
- u32 val, w, count;
u8 *buf;
val = spx5_rd(sparx5, QS_INJ_STATUS);
@@ -189,14 +189,23 @@ static int sparx5_inject(struct sparx5 *sparx5,
for (w = 0; w < IFH_LEN; w++)
spx5_wr(ifh[w], sparx5, QS_INJ_WR(grp));
- /* Write words, round up */
- count = DIV_ROUND_UP(skb->len, 4);
+ /* Write the whole words of the frame */
+ count = skb->len / 4;
buf = skb->data;
for (w = 0; w < count; w++, buf += 4) {
val = get_unaligned((const u32 *)buf);
spx5_wr(val, sparx5, QS_INJ_WR(grp));
}
+ /* Write the last 1 to 3 bytes, zero padded to a whole word */
+ last = skb->len % 4;
+ if (last) {
+ val = 0;
+ memcpy(&val, buf, last);
+ spx5_wr(val, sparx5, QS_INJ_WR(grp));
+ w++;
+ }
+
/* Add padding */
while (w < (60 / 4)) {
spx5_wr(0, sparx5, QS_INJ_WR(grp));
---
base-commit: d06ae66516e1aaf023808912af6292aef09d46c3
change-id: 20261020-sparx5-inject-tail-bytes-e81cffc5b065
Best regards,
--
Daniel Machon <daniel.machon@microchip.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] net: sparx5/lan969x: do not read past skb->len when injecting a frame
2026-10-21 10:48 [PATCH] net: sparx5/lan969x: do not read past skb->len when injecting a frame Daniel Machon
@ 2026-10-21 11:25 ` Daniel Machon
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Machon @ 2026-10-21 11:25 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Steen Hegelund, UNGLinuxDriver, Bjarni Jonasson,
Lars Povlsen
Cc: netdev, linux-arm-kernel, linux-kernel
> sparx5_inject() writes the frame to the injection FIFO one 32-bit word
> at a time, and pads frames shorter than 60 bytes with zero words.
>
> Before this patch, the last word is loaded whole even when skb->len is
> not a multiple of four, so 1 to 3 bytes past the end of the frame are
> read. For a frame shorter than 60 bytes those bytes are also
> transmitted, as VLD_BYTES marks the whole last word valid and the
> padding starts at the next word.
>
> Write the trailing bytes from a zeroed word. The number of words written
> and VLD_BYTES are unchanged.
>
> Found by an AI code review agent, and reproduced on lan969x and sparx5
> with register injection: bytes 57 to 59 of a 57 byte frame were not
> zero. With the fix they are zero, and traffic still passes on both
> chips.
>
> Fixes: f3cad2611a77 ("net: sparx5: add hostmode with phylink support")
> Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
I somehow forgot to include the target tree. This one goes to net.
/Daniel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-21 11:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-21 10:48 [PATCH] net: sparx5/lan969x: do not read past skb->len when injecting a frame Daniel Machon
2026-10-21 11:25 ` Daniel Machon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®