diff mbox series

[net] net: bridge: fix corrupted ethernet header on multicast-to-unicast

Message ID 20240505184239.15002-1-nbd@nbd.name (mailing list archive)
State Accepted
Commit 86b29d830ad69eecff25b22dc96c14c6573718e6
Delegated to: Netdev Maintainers
Headers show
Series [net] net: bridge: fix corrupted ethernet header on multicast-to-unicast | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 926 this patch: 926
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 937 this patch: 937
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 937 this patch: 937
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 25 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-05-08--03-00 (tests: 1005)

Commit Message

Felix Fietkau May 5, 2024, 6:42 p.m. UTC
The change from skb_copy to pskb_copy unfortunately changed the data
copying to omit the ethernet header, since it was pulled before reaching
this point. Fix this by calling __skb_push/pull around pskb_copy.

Fixes: 59c878cbcdd8 ("net: bridge: fix multicast-to-unicast with fraglist GSO")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 net/bridge/br_forward.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Nikolay Aleksandrov May 7, 2024, 12:15 p.m. UTC | #1
On 05/05/2024 21:42, Felix Fietkau wrote:
> The change from skb_copy to pskb_copy unfortunately changed the data
> copying to omit the ethernet header, since it was pulled before reaching
> this point. Fix this by calling __skb_push/pull around pskb_copy.
> 
> Fixes: 59c878cbcdd8 ("net: bridge: fix multicast-to-unicast with fraglist GSO")
> Signed-off-by: Felix Fietkau <nbd@nbd.name>
> ---
>   net/bridge/br_forward.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c
> index d7c35f55bd69..d97064d460dc 100644
> --- a/net/bridge/br_forward.c
> +++ b/net/bridge/br_forward.c
> @@ -258,6 +258,7 @@ static void maybe_deliver_addr(struct net_bridge_port *p, struct sk_buff *skb,
>   {
>   	struct net_device *dev = BR_INPUT_SKB_CB(skb)->brdev;
>   	const unsigned char *src = eth_hdr(skb)->h_source;
> +	struct sk_buff *nskb;
>   
>   	if (!should_deliver(p, skb))
>   		return;
> @@ -266,12 +267,16 @@ 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 = pskb_copy(skb, GFP_ATOMIC);
> -	if (!skb) {
> +	__skb_push(skb, ETH_HLEN);
> +	nskb = pskb_copy(skb, GFP_ATOMIC);
> +	__skb_pull(skb, ETH_HLEN);
> +	if (!nskb) {
>   		DEV_STATS_INC(dev, tx_dropped);
>   		return;
>   	}
>   
> +	skb = nskb;
> +	__skb_pull(skb, ETH_HLEN);
>   	if (!is_broadcast_ether_addr(addr))
>   		memcpy(eth_hdr(skb)->h_dest, addr, ETH_ALEN);
>   

This dance is getting ugly, but better to have it correct.
It'd be nice if you could add a selftest that exercises it.

Acked-by: Nikolay Aleksandrov <razor@blackwall.org>
patchwork-bot+netdevbpf@kernel.org May 8, 2024, 9:40 a.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:

On Sun,  5 May 2024 20:42:38 +0200 you wrote:
> The change from skb_copy to pskb_copy unfortunately changed the data
> copying to omit the ethernet header, since it was pulled before reaching
> this point. Fix this by calling __skb_push/pull around pskb_copy.
> 
> Fixes: 59c878cbcdd8 ("net: bridge: fix multicast-to-unicast with fraglist GSO")
> Signed-off-by: Felix Fietkau <nbd@nbd.name>
> 
> [...]

Here is the summary with links:
  - [net] net: bridge: fix corrupted ethernet header on multicast-to-unicast
    https://git.kernel.org/netdev/net/c/86b29d830ad6

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c
index d7c35f55bd69..d97064d460dc 100644
--- a/net/bridge/br_forward.c
+++ b/net/bridge/br_forward.c
@@ -258,6 +258,7 @@  static void maybe_deliver_addr(struct net_bridge_port *p, struct sk_buff *skb,
 {
 	struct net_device *dev = BR_INPUT_SKB_CB(skb)->brdev;
 	const unsigned char *src = eth_hdr(skb)->h_source;
+	struct sk_buff *nskb;
 
 	if (!should_deliver(p, skb))
 		return;
@@ -266,12 +267,16 @@  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 = pskb_copy(skb, GFP_ATOMIC);
-	if (!skb) {
+	__skb_push(skb, ETH_HLEN);
+	nskb = pskb_copy(skb, GFP_ATOMIC);
+	__skb_pull(skb, ETH_HLEN);
+	if (!nskb) {
 		DEV_STATS_INC(dev, tx_dropped);
 		return;
 	}
 
+	skb = nskb;
+	__skb_pull(skb, ETH_HLEN);
 	if (!is_broadcast_ether_addr(addr))
 		memcpy(eth_hdr(skb)->h_dest, addr, ETH_ALEN);