Skip to contentSkip to conversation

net: bridge: fix multicast-to-unicast with fraglist GSO

PATCH Applied Felix Fietkau 4 participants 5 messages Apr 27, 2024 – May 1, 2024

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

PATCH 1/2 net: bridge: fix multicast-to-unicast with fraglist GSO

Calling skb_copy on a SKB_GSO_FRAGLIST skb is not valid, since it returns an invalid linearized skb. This code only needs to change the ethernet header, so pskb_copy is the right function to call here.

Fixes 6db6f0eae605 ("bridge: multicast to unicast")
---
 net/bridge/br_forward.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_forward.c +1 -1
index 7431f89e897b..d7c35f55bd69 100644
@@ -266,7 +266,7 @@ static void maybe_deliver_addr(struct net_bridge_port *p, struct sk_buff *skb,
 	if (skb->dev == p->dev && ether_addr_equal(src, addr))
 		return;
 
-	skb = skb_copy(skb, GFP_ATOMIC);
+	skb = pskb_copy(skb, GFP_ATOMIC);
 	if (!skb) {
 		DEV_STATS_INC(dev, tx_dropped);
 		return;
Signature · 1 line
2.44.0
#1 lore raw

PATCH 2/2 net: core: reject skb_copy(_expand) for fraglist GSO skbs

SKB_GSO_FRAGLIST skbs must not be linearized, otherwise they become invalid. Return NULL if such an skb is passed to skb_copy or skb_copy_expand, in order to prevent a crash on a potential later call to skb_gso_segment.

Fixes 3a1296a38d0c ("net: Support GRO/GSO fraglist chaining.")
---
 net/core/skbuff.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
net/core/skbuff.c +19 -8
index b99127712e67..4096e679f61c 100644
@@ -2123,11 +2123,17 @@ static inline int skb_alloc_rx_flag(const struct sk_buff *skb)
 
 struct sk_buff *skb_copy(const struct sk_buff *skb, gfp_t gfp_mask)
 {
-	int headerlen = skb_headroom(skb);
-	unsigned int size = skb_end_offset(skb) + skb->data_len;
-	struct sk_buff *n = __alloc_skb(size, gfp_mask,
-					skb_alloc_rx_flag(skb), NUMA_NO_NODE);
+	struct sk_buff *n;
+	unsigned int size;
+	int headerlen;
+
+	if (WARN_ON_ONCE(skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST))
+		return NULL;
 
+	headerlen = skb_headroom(skb);
+	size = skb_end_offset(skb) + skb->data_len;
+	n = __alloc_skb(size, gfp_mask,
+			skb_alloc_rx_flag(skb), NUMA_NO_NODE);
 	if (!n)
 		return NULL;
 
@@ -2455,12 +2461,17 @@ struct sk_buff *skb_copy_expand(const struct sk_buff *skb,
 	/*
 	 *	Allocate the copy buffer
 	 */
-	struct sk_buff *n = __alloc_skb(newheadroom + skb->len + newtailroom,
-					gfp_mask, skb_alloc_rx_flag(skb),
-					NUMA_NO_NODE);
-	int oldheadroom = skb_headroom(skb);
 	int head_copy_len, head_copy_off;
+	struct sk_buff *n;
+	int oldheadroom;
+
+	if (WARN_ON_ONCE(skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST))
+		return NULL;
 
+	oldheadroom = skb_headroom(skb);
+	n = __alloc_skb(newheadroom + skb->len + newtailroom,
+			gfp_mask, skb_alloc_rx_flag(skb),
+			NUMA_NO_NODE);
 	if (!n)
 		return NULL;
 
Signature · 1 line
2.44.0
maintainer Acked-by on v1 1/2
#2 lore raw
In reply to Felix Fietkau
Quoted 15 lines · Felix Fietkau

Calling skb_copy on a SKB_GSO_FRAGLIST skb is not valid, since it returns an invalid linearized skb. This code only needs to change the ethernet header, so pskb_copy is the right function to call here.

Fixes 6db6f0eae605 ("bridge: multicast to unicast")
---
 net/bridge/br_forward.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_forward.c +0 -0
index 7431f89e897b..d7c35f55bd69 100644

net/bridge/br_forward.c static void maybe_deliver_addr(struct net_bridge_port *p, struct sk_buff *skb, · line 272

Quoted 8 lines
net/bridge/br_forward.c +1 -1
@@ -266,7 +266,7 @@ static void maybe_deliver_addr(struct net_bridge_port *p, struct sk_buff *skb,
 	if (skb->dev == p->dev && ether_addr_equal(src, addr))
 		return;
 
-	skb = skb_copy(skb, GFP_ATOMIC);
+	skb = pskb_copy(skb, GFP_ATOMIC);
 	if (!skb) {
 		DEV_STATS_INC(dev, tx_dropped);
 		return;

LGTM, but let's wait a little more time for Nikolay

maintainer Acked-by on v1 1/2
#3 lore raw
In reply to Felix Fietkau
Quoted 15 lines · Felix Fietkau

Calling skb_copy on a SKB_GSO_FRAGLIST skb is not valid, since it returns an invalid linearized skb. This code only needs to change the ethernet header, so pskb_copy is the right function to call here.

Fixes 6db6f0eae605 ("bridge: multicast to unicast")
---
 net/bridge/br_forward.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_forward.c +0 -0
index 7431f89e897b..d7c35f55bd69 100644

net/bridge/br_forward.c static void maybe_deliver_addr(struct net_bridge_port *p, struct sk_buff *skb, · line 272

Quoted 8 lines
net/bridge/br_forward.c +1 -1
@@ -266,7 +266,7 @@ static void maybe_deliver_addr(struct net_bridge_port *p, struct sk_buff *skb,
 	if (skb->dev == p->dev && ether_addr_equal(src, addr))
 		return;
 
-	skb = skb_copy(skb, GFP_ATOMIC);
+	skb = pskb_copy(skb, GFP_ATOMIC);
 	if (!skb) {
 		DEV_STATS_INC(dev, tx_dropped);
 		return;
#4 lore raw
In reply to Felix Fietkau
This series was applied to netdev/net.git (main) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:

Quoted 8 lines · On Sat, 27 Apr 2024 20:24:18 +0200 you wrote:

Calling skb_copy on a SKB_GSO_FRAGLIST skb is not valid, since it returns an invalid linearized skb. This code only needs to change the ethernet header, so pskb_copy is the right function to call here.

Fixes 6db6f0eae605 ("bridge: multicast to unicast")

[...]

Here is the summary with links:
- [net,1/2] net: bridge: fix multicast-to-unicast with fraglist GSO

    https://git.kernel.org/netdev/net/c/59c878cbcdd8
  - [net,2/2] net: core: reject skb_copy(_expand) for fraglist GSO skbs
    https://git.kernel.org/netdev/net/c/d091e579b864

You are awesome, thank you!

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