Skip to contentSkip to conversation

net: guard drivers against shared skbs

RFC In review Jakub Kicinski 2 participants 5 messages Nov 15, 2021 – Nov 16, 2021

Subsystems (2)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

RFC 1/1 net: guard drivers against shared skbs

Commit d8873315065f ("net: add IFF_SKB_TX_SHARED flag to priv_flags") introduced IFF_SKB_TX_SHARED to protect drivers which are not ready for getting shared skbs from pktgen sending such frames.

Some drivers dutifully clear the flag but most don't, even though they modify the skb or call skb helpers which expect private skbs.

syzbot has also discovered more sources of shared skbs than just pktgen (e.g. llc).

I think defaulting to opt-in is doing more harm than good, those who care about fast pktgen should inspect their drivers and opt-in. It's far too risky to enable this flag in ether_setup().

---
 drivers/net/dummy.c | 1 +
 net/core/dev.c      | 4 ++++
 net/ethernet/eth.c  | 1 -
 3 files changed, 5 insertions(+), 1 deletion(-)
drivers/net/dummy.c +1 -0
index f82ad7419508..530eaaee2d25 100644
@@ -123,6 +123,7 @@ static void dummy_setup(struct net_device *dev)
 	dev->flags |= IFF_NOARP;
 	dev->flags &= ~IFF_MULTICAST;
 	dev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_NO_QUEUE;
+	dev->priv_flags |= IFF_TX_SKB_SHARING;
 	dev->features	|= NETIF_F_SG | NETIF_F_FRAGLIST;
 	dev->features	|= NETIF_F_GSO_SOFTWARE;
 	dev->features	|= NETIF_F_HW_CSUM | NETIF_F_HIGHDMA | NETIF_F_LLTX;
net/core/dev.c +4 -0
index 15ac064b5562..476a826bb4f0 100644
@@ -3661,6 +3661,10 @@ static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_device
 	if (unlikely(!skb))
 		goto out_null;
 
+	if (unlikely(skb_shared(skb)) &&
+	    !(dev->priv_flags & IFF_TX_SKB_SHARING))
+		goto out_kfree_skb;
+
 	skb = sk_validate_xmit_skb(skb, dev);
 	if (unlikely(!skb))
 		goto out_null;
net/ethernet/eth.c +0 -1
index c7d9e08107cb..a55a39c77211 100644
@@ -366,7 +366,6 @@ void ether_setup(struct net_device *dev)
 	dev->addr_len		= ETH_ALEN;
 	dev->tx_queue_len	= DEFAULT_TX_QUEUE_LEN;
 	dev->flags		= IFF_BROADCAST|IFF_MULTICAST;
-	dev->priv_flags		|= IFF_TX_SKB_SHARING;
 
 	eth_broadcast_addr(dev->broadcast);
 
Signature · 1 line
2.31.1
#1 lore raw
Quoted 39 lines · Jakub Kicinski

Commit d8873315065f ("net: add IFF_SKB_TX_SHARED flag to priv_flags") introduced IFF_SKB_TX_SHARED to protect drivers which are not ready for getting shared skbs from pktgen sending such frames.

Some drivers dutifully clear the flag but most don't, even though they modify the skb or call skb helpers which expect private skbs.

syzbot has also discovered more sources of shared skbs than just pktgen (e.g. llc).

I think defaulting to opt-in is doing more harm than good, those who care about fast pktgen should inspect their drivers and opt-in. It's far too risky to enable this flag in ether_setup().

---
 drivers/net/dummy.c | 1 +
 net/core/dev.c      | 4 ++++
 net/ethernet/eth.c  | 1 -
 3 files changed, 5 insertions(+), 1 deletion(-)
drivers/net/dummy.c +1 -0
index f82ad7419508..530eaaee2d25 100644
@@ -123,6 +123,7 @@ static void dummy_setup(struct net_device *dev)
 	dev->flags |= IFF_NOARP;
 	dev->flags &= ~IFF_MULTICAST;
 	dev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_NO_QUEUE;
+	dev->priv_flags |= IFF_TX_SKB_SHARING;
 	dev->features	|= NETIF_F_SG | NETIF_F_FRAGLIST;
 	dev->features	|= NETIF_F_GSO_SOFTWARE;
 	dev->features	|= NETIF_F_HW_CSUM | NETIF_F_HIGHDMA | NETIF_F_LLTX;
net/core/dev.c +0 -0
index 15ac064b5562..476a826bb4f0 100644

net/core/dev.c static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_device · line 3666

Quoted 6 lines
net/core/dev.c +3 -0
@@ -3661,6 +3661,10 @@ static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_device
 	if (unlikely(!skb))
 		goto out_null;
 
+	if (unlikely(skb_shared(skb)) &&
+	    !(dev->priv_flags & IFF_TX_SKB_SHARING))
+		goto out_kfree_skb;

So this will break llc, right ?

I am sad we are adding so much tests in fast path.

author maintainer
#2 lore raw
Quoted 23 lines · On Mon, 15 Nov 2021 08:56:10 -0800 Eric Dumazet wrote:
Quoted 22 lines · Jakub Kicinski

Commit d8873315065f ("net: add IFF_SKB_TX_SHARED flag to priv_flags") introduced IFF_SKB_TX_SHARED to protect drivers which are not ready for getting shared skbs from pktgen sending such frames.

Some drivers dutifully clear the flag but most don't, even though they modify the skb or call skb helpers which expect private skbs.

syzbot has also discovered more sources of shared skbs than just pktgen (e.g. llc).

I think defaulting to opt-in is doing more harm than good, those who care about fast pktgen should inspect their drivers and opt-in. It's far too risky to enable this flag in ether_setup().

net/core/dev.c +0 -0
index 15ac064b5562..476a826bb4f0 100644
@@ -3661,6 +3661,10 @@ static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_device
 	if (unlikely(!skb))
 		goto out_null;
 
Quoted 5 lines

net/core/dev.c static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_device · line 3666

Quoted 3 lines
net/core/dev.c +3 -0
+	if (unlikely(skb_shared(skb)) &&
+	    !(dev->priv_flags & IFF_TX_SKB_SHARING))
+		goto out_kfree_skb;  

So this will break llc, right ?

Likely. I haven't checked why LLC thinks it's a good idea to send shared skbs, probably convenience.

Quoted 1 line

I am sad we are adding so much tests in fast path.

What's our general stance on shared skbs in the Tx path? If we think that it's okay maybe it's time to turn the BUG_ON(shared_skb)s in pskb functions into return -EINVALs?

The IFF_TX_SKB_SHARING flag is pretty toothless as it stands.

#3 lore raw
Quoted 30 lines · Jakub Kicinski
Quoted 23 lines · On Mon, 15 Nov 2021 08:56:10 -0800 Eric Dumazet wrote:
Quoted 22 lines · Jakub Kicinski

Commit d8873315065f ("net: add IFF_SKB_TX_SHARED flag to priv_flags") introduced IFF_SKB_TX_SHARED to protect drivers which are not ready for getting shared skbs from pktgen sending such frames.

Some drivers dutifully clear the flag but most don't, even though they modify the skb or call skb helpers which expect private skbs.

syzbot has also discovered more sources of shared skbs than just pktgen (e.g. llc).

I think defaulting to opt-in is doing more harm than good, those who care about fast pktgen should inspect their drivers and opt-in. It's far too risky to enable this flag in ether_setup().

net/core/dev.c +0 -0
index 15ac064b5562..476a826bb4f0 100644
@@ -3661,6 +3661,10 @@ static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_device
 	if (unlikely(!skb))
 		goto out_null;
 
Quoted 5 lines

net/core/dev.c static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_device · line 3666

Quoted 3 lines
net/core/dev.c +3 -0
+	if (unlikely(skb_shared(skb)) &&
+	    !(dev->priv_flags & IFF_TX_SKB_SHARING))
+		goto out_kfree_skb;  

So this will break llc, right ?

Quoted 8 lines

Likely. I haven't checked why LLC thinks it's a good idea to send shared skbs, probably convenience.

Quoted 1 line

I am sad we are adding so much tests in fast path.

What's our general stance on shared skbs in the Tx path? If we think that it's okay maybe it's time to turn the BUG_ON(shared_skb)s in pskb functions into return -EINVALs?

Yes, I think that a WARN_ON_ONCE() should be enough to keep syzbot reports from alerting us, while not crashing regular hosts.

Quoted 3 lines

The IFF_TX_SKB_SHARING flag is pretty toothless as it stands.

skb_padto() needs to be replaced by something better. so that skb can be cloned if needed.

static inline int skb_padto(struct sk_buff *skb, unsigned int len)

->

static inline struct sk_buff *skb_padto(struct sk_buff *skb, unsigned int len) {
}

author maintainer
#4 lore raw
Quoted 11 lines · On Mon, 15 Nov 2021 09:59:56 -0800 Eric Dumazet wrote:
Quoted 1 line

The IFF_TX_SKB_SHARING flag is pretty toothless as it stands.

skb_padto() needs to be replaced by something better. so that skb can be cloned if needed.

static inline int skb_padto(struct sk_buff *skb, unsigned int len)

->

static inline struct sk_buff *skb_padto(struct sk_buff *skb, unsigned int len)

Indeed, that was my first instinct but I wasn't up for fixing up all the drivers which call skb_pad(), skb_cow_head() etc.

Let me leave this be for now..