Skip to contentSkip to conversation

net: bcmgenet: Add a check for oversized packets

PATCH Applied Florian Fainelli 4 participants 7 messages Jan 27, 2023 – Jan 31, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: bcmgenet: Add a check for oversized packets

Occasionnaly we may get oversized packets from the hardware which exceed the nomimal 2KiB buffer size we allocate SKBs with. Add an early check which drops the packet to avoid invoking skb_over_panic() and move on to processing the next packet.

---
 drivers/net/ethernet/broadcom/genet/bcmgenet.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +8 -0
index 21973046b12b..d937daa8ee88 100644
@@ -2316,6 +2316,14 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
 			  __func__, p_index, ring->c_index,
 			  ring->read_ptr, dma_length_status);
 
+		if (unlikely(len > RX_BUF_LENGTH)) {
+			netif_err(priv, rx_status, dev, "oversized packet\n");
+			dev->stats.rx_length_errors++;
+			dev->stats.rx_errors++;
+			dev_kfree_skb_any(skb);
+			goto next;
+		}
+
 		if (unlikely(!(dma_flag & DMA_EOP) || !(dma_flag & DMA_SOP))) {
 			netif_err(priv, rx_status, dev,
 				  "dropping fragmented packet!\n");
Signature · 1 line
2.25.1
#1 lore raw
Quoted 15 lines · Florian Fainelli

Occasionnaly we may get oversized packets from the hardware which exceed the nomimal 2KiB buffer size we allocate SKBs with. Add an early check which drops the packet to avoid invoking skb_over_panic() and move on to processing the next packet.

---
 drivers/net/ethernet/broadcom/genet/bcmgenet.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +0 -0
index 21973046b12b..d937daa8ee88 100644

drivers/net/ethernet/broadcom/genet/bcmgenet.c static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring, · line 2320

Quoted 5 lines
drivers/net/ethernet/broadcom/genet/bcmgenet.c +2 -0
@@ -2316,6 +2316,14 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
 			  __func__, p_index, ring->c_index,
 			  ring->read_ptr, dma_length_status);
 
+		if (unlikely(len > RX_BUF_LENGTH)) {
+			netif_err(priv, rx_status, dev, "oversized packet\n");

I don't think that it is wise move to print to dmesg something that can be triggered by user over network.

Thanks

Quoted 12 lines
drivers/net/ethernet/broadcom/genet/bcmgenet.c +6 -0
+			dev->stats.rx_length_errors++;
+			dev->stats.rx_errors++;
+			dev_kfree_skb_any(skb);
+			goto next;
+		}
+
 		if (unlikely(!(dma_flag & DMA_EOP) || !(dma_flag & DMA_SOP))) {
 			netif_err(priv, rx_status, dev,
 				  "dropping fragmented packet!\n");
Signature · 1 line
2.25.1
#2 lore raw
Quoted 19 lines · Leon Romanovsky
Quoted 18 lines · Florian Fainelli

Occasionnaly we may get oversized packets from the hardware which exceed the nomimal 2KiB buffer size we allocate SKBs with. Add an early check which drops the packet to avoid invoking skb_over_panic() and move on to processing the next packet.

---
  drivers/net/ethernet/broadcom/genet/bcmgenet.c | 8 ++++++++
  1 file changed, 8 insertions(+)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +0 -0
index 21973046b12b..d937daa8ee88 100644
@@ -2316,6 +2316,14 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
  			  __func__, p_index, ring->c_index,
  			  ring->read_ptr, dma_length_status);
 
Quoted 5 lines

drivers/net/ethernet/broadcom/genet/bcmgenet.c static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring, · line 2320

Quoted 2 lines
drivers/net/ethernet/broadcom/genet/bcmgenet.c +2 -0
+		if (unlikely(len > RX_BUF_LENGTH)) {
+			netif_err(priv, rx_status, dev, "oversized packet\n");

I don't think that it is wise move to print to dmesg something that can be triggered by user over network.

A frame larger than RX_BUF_LENGTH intentionally received would be segmented by the MAC, we have seen this happen however while playing with unsafe clock ratios for instance or when there are insufficient credits given to the Ethernet MAC to write frames into DRAM. The print is consistent with other errors that are captured and is only enabled if the appropriate ethtool message level bitmask is set.

Signature · 1 line
Florian
#3 lore raw
Quoted 27 lines · Florian Fainelli
Quoted 11 lines · Leon Romanovsky
Quoted 10 lines · Florian Fainelli

Occasionnaly we may get oversized packets from the hardware which exceed the nomimal 2KiB buffer size we allocate SKBs with. Add an early check which drops the packet to avoid invoking skb_over_panic() and move on to processing the next packet.

---
  drivers/net/ethernet/broadcom/genet/bcmgenet.c | 8 ++++++++
  1 file changed, 8 insertions(+)
Quoted 12 lines

drivers/net/ethernet/broadcom/genet/bcmgenet.c static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring, · line 2319

Quoted 9 lines
drivers/net/ethernet/broadcom/genet/bcmgenet.c +2 -0
index 21973046b12b..d937daa8ee88 100644
@@ -2316,6 +2316,14 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
  			  __func__, p_index, ring->c_index,
  			  ring->read_ptr, dma_length_status);
+		if (unlikely(len > RX_BUF_LENGTH)) {
+			netif_err(priv, rx_status, dev, "oversized packet\n");

I don't think that it is wise move to print to dmesg something that can be triggered by user over network.

Quoted 6 lines

A frame larger than RX_BUF_LENGTH intentionally received would be segmented by the MAC, we have seen this happen however while playing with unsafe clock ratios for instance or when there are insufficient credits given to the Ethernet MAC to write frames into DRAM. The print is consistent with other errors that are captured and is only enabled if the appropriate ethtool message level bitmask is set.

I saw other prints in that function, but you add new one. Won't netif_err() be printed by default in almost all distro?

Thanks

Quoted 2 lines
Signature · 1 line
Florian
maintainer
#4 lore raw
Quoted 35 lines · Leon Romanovsky
Quoted 27 lines · Florian Fainelli
Quoted 11 lines · Leon Romanovsky
Quoted 10 lines · Florian Fainelli

Occasionnaly we may get oversized packets from the hardware which exceed the nomimal 2KiB buffer size we allocate SKBs with. Add an early check which drops the packet to avoid invoking skb_over_panic() and move on to processing the next packet.

---
   drivers/net/ethernet/broadcom/genet/bcmgenet.c | 8 ++++++++
   1 file changed, 8 insertions(+)
Quoted 12 lines

drivers/net/ethernet/broadcom/genet/bcmgenet.c static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring, · line 2319

Quoted 9 lines
drivers/net/ethernet/broadcom/genet/bcmgenet.c +2 -0
index 21973046b12b..d937daa8ee88 100644
@@ -2316,6 +2316,14 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
   			  __func__, p_index, ring->c_index,
   			  ring->read_ptr, dma_length_status);
+		if (unlikely(len > RX_BUF_LENGTH)) {
+			netif_err(priv, rx_status, dev, "oversized packet\n");

I don't think that it is wise move to print to dmesg something that can be triggered by user over network.

Quoted 6 lines

A frame larger than RX_BUF_LENGTH intentionally received would be segmented by the MAC, we have seen this happen however while playing with unsafe clock ratios for instance or when there are insufficient credits given to the Ethernet MAC to write frames into DRAM. The print is consistent with other errors that are captured and is only enabled if the appropriate ethtool message level bitmask is set.

Quoted 2 lines

I saw other prints in that function, but you add new one. Won't netif_err() be printed by default in almost all distro?

Do distributions alter the drive default message level:

#define GENET_MSG_DEFAULT (NETIF_MSG_DRV | NETIF_MSG_PROBE | \
NETIF_MSG_LINK)
?

Signature · 1 line
Florian
#5 lore raw
Quoted 36 lines · Florian Fainelli
Quoted 35 lines · Leon Romanovsky
Quoted 33 lines · Florian Fainelli
Quoted 11 lines · Leon Romanovsky
Quoted 10 lines · Florian Fainelli

Occasionnaly we may get oversized packets from the hardware which exceed the nomimal 2KiB buffer size we allocate SKBs with. Add an early check which drops the packet to avoid invoking skb_over_panic() and move on to processing the next packet.

---
   drivers/net/ethernet/broadcom/genet/bcmgenet.c | 8 ++++++++
   1 file changed, 8 insertions(+)
Quoted 12 lines

drivers/net/ethernet/broadcom/genet/bcmgenet.c static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring, · line 2319

Quoted 9 lines
drivers/net/ethernet/broadcom/genet/bcmgenet.c +2 -0
index 21973046b12b..d937daa8ee88 100644
@@ -2316,6 +2316,14 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
   			  __func__, p_index, ring->c_index,
   			  ring->read_ptr, dma_length_status);
+		if (unlikely(len > RX_BUF_LENGTH)) {
+			netif_err(priv, rx_status, dev, "oversized packet\n");

I don't think that it is wise move to print to dmesg something that can be triggered by user over network.

A frame larger than RX_BUF_LENGTH intentionally received would be segmented by the MAC, we have seen this happen however while playing with unsafe clock ratios for instance or when there are insufficient credits given to the Ethernet MAC to write frames into DRAM. The print is consistent with other errors that are captured and is only enabled if the appropriate ethtool message level bitmask is set.

Quoted 8 lines
Quoted 2 lines

I saw other prints in that function, but you add new one. Won't netif_err() be printed by default in almost all distro?

Do distributions alter the drive default message level:

#define GENET_MSG_DEFAULT (NETIF_MSG_DRV | NETIF_MSG_PROBE | \
NETIF_MSG_LINK)
?

Ohh, I didn't know about per-driver defaults.

Thanks for the explanation.

Quoted 3 lines
Signature · 1 line
Florian
#6 lore raw
In reply to Florian Fainelli
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 8 lines · On Thu, 26 Jan 2023 16:08:19 -0800 you wrote:

Occasionnaly we may get oversized packets from the hardware which exceed the nomimal 2KiB buffer size we allocate SKBs with. Add an early check which drops the packet to avoid invoking skb_over_panic() and move on to processing the next packet.

[...]

Here is the summary with links:
- [net-next] net: bcmgenet: Add a check for oversized packets

    https://git.kernel.org/netdev/net-next/c/5c0862c2c962

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html