Skip to contentSkip to conversation

net: dpaa: Pad packets to ETH_ZLEN

PATCH Superseded Sean Anderson 2 participants 6 messages Sep 9, 2024 – Sep 10, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: dpaa: Pad packets to ETH_ZLEN

When sending packets under 60 bytes, up to three bytes of the buffer following the data may be leaked. Avoid this by extending all packets to ETH_ZLEN, ensuring nothing is leaked in the padding. This bug can be reproduced by running

	$ ping -s 11 destination
Fixes 9ad1a3749333 ("dpaa_eth: add support for DPAA Ethernet")

---

 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +6 -0
index cfe6b57b1da0..e4e8ee8b7356 100644
@@ -2322,6 +2322,12 @@ dpaa_start_xmit(struct sk_buff *skb, struct net_device *net_dev)
 	}
 #endif
 
+	/* Packet data is always read as 32-bit words, so zero out any part of
+	 * the skb which might be sent if we have to pad the packet
+	 */
+	if (__skb_put_padto(skb, ETH_ZLEN, false))
+		goto enomem;
+
 	if (nonlinear) {
 		/* Just create a S/G fd based on the skb */
 		err = skb_to_sg_fd(priv, skb, &fd);
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#1 lore raw
Quoted 20 lines · Sean Anderson

When sending packets under 60 bytes, up to three bytes of the buffer following the data may be leaked. Avoid this by extending all packets to ETH_ZLEN, ensuring nothing is leaked in the padding. This bug can be reproduced by running

        $ ping -s 11 destination
Fixes 9ad1a3749333 ("dpaa_eth: add support for DPAA Ethernet")

---

 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +0 -0
index cfe6b57b1da0..e4e8ee8b7356 100644

drivers/net/ethernet/freescale/dpaa/dpaa_eth.c dpaa_start_xmit(struct sk_buff *skb, struct net_device *net_dev) · line 2330

Quoted 9 lines
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +6 -0
@@ -2322,6 +2322,12 @@ dpaa_start_xmit(struct sk_buff *skb, struct net_device *net_dev)
        }
 #endif
 
+       /* Packet data is always read as 32-bit words, so zero out any part of
+        * the skb which might be sent if we have to pad the packet
+        */
+       if (__skb_put_padto(skb, ETH_ZLEN, false))
+               goto enomem;
+

This call might linearize the packet.

@nonlinear variable might be wrong after this point.

Quoted 6 lines
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +0 -1
        if (nonlinear) {
                /* Just create a S/G fd based on the skb */
                err = skb_to_sg_fd(priv, skb, &fd);
--

2.35.1.1320.gc452695387.dirty

Perhaps this instead ?

(quoted diff) +0 -0

b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
index cfe6b57b1da0e45613ac1bbf32ddd6ace329f4fd..5763d2f1bf8dd31b80fda0681361514dad1dc307 100644

drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +1 -1
@@ -2272,12 +2272,12 @@ static netdev_tx_t
 dpaa_start_xmit(struct sk_buff *skb, struct net_device *net_dev)
 {
        const int queue_mapping = skb_get_queue_mapping(skb);
-       bool nonlinear = skb_is_nonlinear(skb);
        struct rtnl_link_stats64 *percpu_stats;
        struct dpaa_percpu_priv *percpu_priv;
        struct netdev_queue *txq;
        struct dpaa_priv *priv;
        struct qm_fd fd;
+       bool nonlinear;
        int offset = 0;
        int err = 0;
 
@@ -2287,6 +2287,10 @@ dpaa_start_xmit(struct sk_buff *skb, struct

net_device *net_dev)

        qm_fd_clear_fd(&fd);

+ if (__skb_put_padto(skb, ETH_ZLEN, false))
+ goto enomem;
+

+       nonlinear = skb_is_nonlinear(skb);
        if (!nonlinear) {
                /* We're going to store the skb backpointer at the beginning
                 * of the data buffer, so we need a privately owned skb
#2 lore raw
Quoted 75 lines · Eric Dumazet
Quoted 20 lines · Sean Anderson

When sending packets under 60 bytes, up to three bytes of the buffer following the data may be leaked. Avoid this by extending all packets to ETH_ZLEN, ensuring nothing is leaked in the padding. This bug can be reproduced by running

        $ ping -s 11 destination
Fixes 9ad1a3749333 ("dpaa_eth: add support for DPAA Ethernet")

---

 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +0 -0
index cfe6b57b1da0..e4e8ee8b7356 100644

drivers/net/ethernet/freescale/dpaa/dpaa_eth.c dpaa_start_xmit(struct sk_buff *skb, struct net_device *net_dev) · line 2330

Quoted 9 lines
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +6 -0
@@ -2322,6 +2322,12 @@ dpaa_start_xmit(struct sk_buff *skb, struct net_device *net_dev)
        }
 #endif
 
+       /* Packet data is always read as 32-bit words, so zero out any part of
+        * the skb which might be sent if we have to pad the packet
+        */
+       if (__skb_put_padto(skb, ETH_ZLEN, false))
+               goto enomem;
+

This call might linearize the packet.

@nonlinear variable might be wrong after this point.

Quoted 6 lines
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +0 -1
        if (nonlinear) {
                /* Just create a S/G fd based on the skb */
                err = skb_to_sg_fd(priv, skb, &fd);
--

2.35.1.1320.gc452695387.dirty

Perhaps this instead ?

drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +0 -0
index cfe6b57b1da0e45613ac1bbf32ddd6ace329f4fd..5763d2f1bf8dd31b80fda0681361514dad1dc307

100644

drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +5 -1
@@ -2272,12 +2272,12 @@ static netdev_tx_t
 dpaa_start_xmit(struct sk_buff *skb, struct net_device *net_dev)
 {
        const int queue_mapping = skb_get_queue_mapping(skb);
-       bool nonlinear = skb_is_nonlinear(skb);
        struct rtnl_link_stats64 *percpu_stats;
        struct dpaa_percpu_priv *percpu_priv;
        struct netdev_queue *txq;
        struct dpaa_priv *priv;
        struct qm_fd fd;
+       bool nonlinear;
        int offset = 0;
        int err = 0;
 
@@ -2287,6 +2287,10 @@ dpaa_start_xmit(struct sk_buff *skb, struct
 net_device *net_dev)
 
        qm_fd_clear_fd(&fd);
 
+       if (__skb_put_padto(skb, ETH_ZLEN, false))
+               goto enomem;
+
+       nonlinear = skb_is_nonlinear(skb);
        if (!nonlinear) {
                /* We're going to store the skb backpointer at the beginning
Quoted 1 line

* of the data buffer, so we need a privately owned skb

Thanks for the suggestion; I was having a hard time figuring out where to call this.

Do you have any hints for how to test this for correctness? I'm not sure how to generate a non-linear packet under 60 bytes.

--Sean

#3 lore raw
Quoted 82 lines · Sean Anderson
Quoted 75 lines · Eric Dumazet
Quoted 20 lines · Sean Anderson

When sending packets under 60 bytes, up to three bytes of the buffer following the data may be leaked. Avoid this by extending all packets to ETH_ZLEN, ensuring nothing is leaked in the padding. This bug can be reproduced by running

        $ ping -s 11 destination
Fixes 9ad1a3749333 ("dpaa_eth: add support for DPAA Ethernet")

---

 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +0 -0
index cfe6b57b1da0..e4e8ee8b7356 100644

drivers/net/ethernet/freescale/dpaa/dpaa_eth.c dpaa_start_xmit(struct sk_buff *skb, struct net_device *net_dev) · line 2330

Quoted 9 lines
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +6 -0
@@ -2322,6 +2322,12 @@ dpaa_start_xmit(struct sk_buff *skb, struct net_device *net_dev)
        }
 #endif
 
+       /* Packet data is always read as 32-bit words, so zero out any part of
+        * the skb which might be sent if we have to pad the packet
+        */
+       if (__skb_put_padto(skb, ETH_ZLEN, false))
+               goto enomem;
+

This call might linearize the packet.

@nonlinear variable might be wrong after this point.

Quoted 6 lines
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +0 -1
        if (nonlinear) {
                /* Just create a S/G fd based on the skb */
                err = skb_to_sg_fd(priv, skb, &fd);
--

2.35.1.1320.gc452695387.dirty

Perhaps this instead ?

drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +0 -0
index cfe6b57b1da0e45613ac1bbf32ddd6ace329f4fd..5763d2f1bf8dd31b80fda0681361514dad1dc307

100644

drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +5 -1
@@ -2272,12 +2272,12 @@ static netdev_tx_t
 dpaa_start_xmit(struct sk_buff *skb, struct net_device *net_dev)
 {
        const int queue_mapping = skb_get_queue_mapping(skb);
-       bool nonlinear = skb_is_nonlinear(skb);
        struct rtnl_link_stats64 *percpu_stats;
        struct dpaa_percpu_priv *percpu_priv;
        struct netdev_queue *txq;
        struct dpaa_priv *priv;
        struct qm_fd fd;
+       bool nonlinear;
        int offset = 0;
        int err = 0;
 
@@ -2287,6 +2287,10 @@ dpaa_start_xmit(struct sk_buff *skb, struct
 net_device *net_dev)
 
        qm_fd_clear_fd(&fd);
 
+       if (__skb_put_padto(skb, ETH_ZLEN, false))
+               goto enomem;
+
+       nonlinear = skb_is_nonlinear(skb);
        if (!nonlinear) {
                /* We're going to store the skb backpointer at the beginning
Quoted 1 line

* of the data buffer, so we need a privately owned skb

Thanks for the suggestion; I was having a hard time figuring out where to call this.

Quoted 2 lines

Do you have any hints for how to test this for correctness? I'm not sure how to generate a non-linear packet under 60 bytes.

I think pktgen can do this, with its frags parameter.

#4 lore raw
Quoted 83 lines · Eric Dumazet
Quoted 82 lines · Sean Anderson
Quoted 75 lines · Eric Dumazet
Quoted 20 lines · Sean Anderson

When sending packets under 60 bytes, up to three bytes of the buffer following the data may be leaked. Avoid this by extending all packets to ETH_ZLEN, ensuring nothing is leaked in the padding. This bug can be reproduced by running

        $ ping -s 11 destination
Fixes 9ad1a3749333 ("dpaa_eth: add support for DPAA Ethernet")

---

 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +0 -0
index cfe6b57b1da0..e4e8ee8b7356 100644

drivers/net/ethernet/freescale/dpaa/dpaa_eth.c dpaa_start_xmit(struct sk_buff *skb, struct net_device *net_dev) · line 2330

Quoted 9 lines
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +6 -0
@@ -2322,6 +2322,12 @@ dpaa_start_xmit(struct sk_buff *skb, struct net_device *net_dev)
        }
 #endif
 
+       /* Packet data is always read as 32-bit words, so zero out any part of
+        * the skb which might be sent if we have to pad the packet
+        */
+       if (__skb_put_padto(skb, ETH_ZLEN, false))
+               goto enomem;
+

This call might linearize the packet.

@nonlinear variable might be wrong after this point.

Quoted 6 lines
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +0 -1
        if (nonlinear) {
                /* Just create a S/G fd based on the skb */
                err = skb_to_sg_fd(priv, skb, &fd);
--

2.35.1.1320.gc452695387.dirty

Perhaps this instead ?

drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +0 -0
index cfe6b57b1da0e45613ac1bbf32ddd6ace329f4fd..5763d2f1bf8dd31b80fda0681361514dad1dc307

100644

drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +5 -1
@@ -2272,12 +2272,12 @@ static netdev_tx_t
 dpaa_start_xmit(struct sk_buff *skb, struct net_device *net_dev)
 {
        const int queue_mapping = skb_get_queue_mapping(skb);
-       bool nonlinear = skb_is_nonlinear(skb);
        struct rtnl_link_stats64 *percpu_stats;
        struct dpaa_percpu_priv *percpu_priv;
        struct netdev_queue *txq;
        struct dpaa_priv *priv;
        struct qm_fd fd;
+       bool nonlinear;
        int offset = 0;
        int err = 0;
 
@@ -2287,6 +2287,10 @@ dpaa_start_xmit(struct sk_buff *skb, struct
 net_device *net_dev)
 
        qm_fd_clear_fd(&fd);
 
+       if (__skb_put_padto(skb, ETH_ZLEN, false))
+               goto enomem;
+
+       nonlinear = skb_is_nonlinear(skb);
        if (!nonlinear) {
                /* We're going to store the skb backpointer at the beginning
Quoted 1 line

* of the data buffer, so we need a privately owned skb

Thanks for the suggestion; I was having a hard time figuring out where to call this.

Quoted 4 lines
Quoted 2 lines

Do you have any hints for how to test this for correctness? I'm not sure how to generate a non-linear packet under 60 bytes.

I think pktgen can do this, with its frags parameter.

OK, I tested both and was able to use

./pktgen/pktgen_sample01_simple.sh -i net5 -m 7e:de:97:38:53:b9 -d 10.0.0.2 -n 3 -s 59

with a call to pg_set $DEV "frags 2" added manually.

This results in the following result

OK: 109(c13+d95) usec, 1 (59byte,0frags)

The original patch causes the nonlinear path to be taken (see with the "tx S/G [TOTAL]" statistic) while your suggestion uses the linear path. Both work, since there's no problem using the nonlinear path with a linear skb.

--Sen

#5 lore raw
Quoted 6 lines · Sean Anderson

OK, I tested both and was able to use

./pktgen/pktgen_sample01_simple.sh -i net5 -m 7e:de:97:38:53:b9 -d 10.0.0.2 -n 3 -s 59

with a call to pg_set $DEV "frags 2" added manually.

Quoted 8 lines

This results in the following result

OK: 109(c13+d95) usec, 1 (59byte,0frags)

The original patch causes the nonlinear path to be taken (see with the "tx S/G [TOTAL]" statistic) while your suggestion uses the linear path. Both work, since there's no problem using the nonlinear path with a linear skb.

Maybe it works today, but this allocates an extra page for nothing, this is an extra burden.

Vast majority of skb_padto() users call it early in ndo_start_xmit(), let's follow this pattern.