bridge: Fix double free and memory leak around br_allowed_ingress
authorToshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
Wed, 9 Apr 2014 08:00:30 +0000 (17:00 +0900)
committerDavid S. Miller <davem@davemloft.net>
Fri, 11 Apr 2014 19:12:47 +0000 (15:12 -0400)
br_allowed_ingress() has two problems.

1. If br_allowed_ingress() is called by br_handle_frame_finish() and
vlan_untag() in br_allowed_ingress() fails, skb will be freed by both
vlan_untag() and br_handle_frame_finish().

2. If br_allowed_ingress() is called by br_dev_xmit() and
br_allowed_ingress() fails, the skb will not be freed.

Fix these two problems by freeing the skb in br_allowed_ingress()
if it fails.

Signed-off-by: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/bridge/br_input.c
net/bridge/br_vlan.c

index d0cca3c65f0174ab8c6522b5f54ab2ad33b66dca..7985deaff52f81cb98e665aaf3e913754b5a671b 100644 (file)
@@ -73,7 +73,7 @@ int br_handle_frame_finish(struct sk_buff *skb)
                goto drop;
 
        if (!br_allowed_ingress(p->br, nbp_get_vlan_info(p), skb, &vid))
-               goto drop;
+               goto out;
 
        /* insert into forwarding database after filtering to avoid spoofing */
        br = p->br;
index 91510712c7a729df3d57c3f118ece9eb3da3fe20..4a37161027899ab12d0f2dd5f4c5d69a1ed98716 100644 (file)
@@ -170,7 +170,7 @@ bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
         * rejected.
         */
        if (!v)
-               return false;
+               goto drop;
 
        /* If vlan tx offload is disabled on bridge device and frame was
         * sent from vlan device on the bridge device, it does not have
@@ -193,7 +193,7 @@ bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
                 * vlan untagged or priority-tagged traffic belongs to.
                 */
                if (pvid == VLAN_N_VID)
-                       return false;
+                       goto drop;
 
                /* PVID is set on this port.  Any untagged or priority-tagged
                 * ingress frame is considered to belong to this vlan.
@@ -216,7 +216,8 @@ bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
        /* Frame had a valid vlan tag.  See if vlan is allowed */
        if (test_bit(*vid, v->vlan_bitmap))
                return true;
-
+drop:
+       kfree_skb(skb);
        return false;
 }