]> git.baikalelectronics.ru Git - kernel.git/commitdiff
bridge: Fix br_forward crash in promiscuous mode
authorMichael Braun <michael-dev@fami-braun.de>
Tue, 16 Mar 2010 07:26:22 +0000 (00:26 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 16 Mar 2010 07:26:22 +0000 (00:26 -0700)
From: Michael Braun <michael-dev@fami-braun.de>

bridge: Fix br_forward crash in promiscuous mode

It's a linux-next kernel from 2010-03-12 on an x86 system and it
OOPs in the bridge module in br_pass_frame_up (called by
br_handle_frame_finish) because brdev cannot be dereferenced (its set to
a non-null value).

Adding some BUG_ON statements revealed that
 BR_INPUT_SKB_CB(skb)->brdev == br-dev
(as set in br_handle_frame_finish first)
only holds until br_forward is called.
The next call to br_pass_frame_up then fails.

Digging deeper it seems that br_forward either frees the skb or passes
it to NF_HOOK which will in turn take care of freeing the skb. The
same is holds for br_pass_frame_ip. So it seems as if two independent
skb allocations are required. As far as I can see, commit
f449608154ebb29c7ffc5c893e6d9e040216b52c ("bridge: Avoid unnecessary
clone on forward path") removed skb duplication and so likely causes
this crash. This crash does not happen on 2.6.33.

I've therefore modified br_forward the same way br_flood has been
modified so that the skb is not freed if skb0 is going to be used
and I can confirm that the attached patch resolves the issue for me.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/bridge/br_forward.c
net/bridge/br_input.c
net/bridge/br_private.h

index d61e6f741125bbd510d20237a8e76e4292802b77..8347916efe88544b50f27a440ca975065a189e0e 100644 (file)
 #include <linux/netfilter_bridge.h>
 #include "br_private.h"
 
+static int deliver_clone(struct net_bridge_port *prev, struct sk_buff *skb,
+                        void (*__packet_hook)(const struct net_bridge_port *p,
+                                              struct sk_buff *skb));
+
 /* Don't forward packets to originating port or forwarding diasabled */
 static inline int should_deliver(const struct net_bridge_port *p,
                                 const struct sk_buff *skb)
@@ -94,14 +98,18 @@ void br_deliver(const struct net_bridge_port *to, struct sk_buff *skb)
 }
 
 /* called with rcu_read_lock */
-void br_forward(const struct net_bridge_port *to, struct sk_buff *skb)
+void br_forward(const struct net_bridge_port *to, struct sk_buff *skb, struct sk_buff *skb0)
 {
        if (should_deliver(to, skb)) {
-               __br_forward(to, skb);
+               if (skb0)
+                       deliver_clone(to, skb, __br_forward);
+               else
+                       __br_forward(to, skb);
                return;
        }
 
-       kfree_skb(skb);
+       if (!skb0)
+               kfree_skb(skb);
 }
 
 static int deliver_clone(struct net_bridge_port *prev, struct sk_buff *skb,
index 53b39851d87d475ecdbfbf9b94fa6eb8072d5f40..08a72e63fb8e99cfaefc8c6b58c9809b62cfeba7 100644 (file)
@@ -90,7 +90,7 @@ int br_handle_frame_finish(struct sk_buff *skb)
 
        if (skb) {
                if (dst)
-                       br_forward(dst->dst, skb);
+                       br_forward(dst->dst, skb, skb2);
                else
                        br_flood_forward(br, skb, skb2);
        }
index fef0384e3c0b78ad09074487200cb08747fc46b4..bfb8feb310a6e46a4cb146d54eefbfcabf5cb3cc 100644 (file)
@@ -252,7 +252,7 @@ extern void br_deliver(const struct net_bridge_port *to,
                struct sk_buff *skb);
 extern int br_dev_queue_push_xmit(struct sk_buff *skb);
 extern void br_forward(const struct net_bridge_port *to,
-               struct sk_buff *skb);
+               struct sk_buff *skb, struct sk_buff *skb0);
 extern int br_forward_finish(struct sk_buff *skb);
 extern void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb);
 extern void br_flood_forward(struct net_bridge *br, struct sk_buff *skb,