Skip to contentSkip to conversation

bridge: Fix crash with vlan filtering and tcpdump

PATCH Superseded Vlad Yasevich 2 participants 3 messages Jan 22, 2014 – Jan 23, 2014

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

PATCH v2 1/1 bridge: Fix crash with vlan filtering and tcpdump

When the vlan filtering is enabled on the bridge, but the filter is not configured on the bridge device itself, running tcpdump on the bridge device will result in a an Oops with NULL pointer dereference. The reason is that br_pass_frame_up() will bypass the vlan check because promisc flag is set. It will then try to get the table pointer and process the packet based on the table. Since the table pointer is NULL, we oops. Catch this special condition in br_handle_vlan().

---
Changes since v1:
- Do not use a BUG or BUG_ON as it is possible to trigger the false BUG condition when thrashing the vlan_enable toggle. Instead just drop the skb.

 net/bridge/br_input.c | 11 ++++++-----
 net/bridge/br_vlan.c  | 14 ++++++++++++++
 2 files changed, 20 insertions(+), 5 deletions(-)
net/bridge/br_input.c +6 -5
index 7e73c32..67fbea0 100644
@@ -29,6 +29,7 @@ static int br_pass_frame_up(struct sk_buff *skb)
 	struct net_device *indev, *brdev = BR_INPUT_SKB_CB(skb)->brdev;
 	struct net_bridge *br = netdev_priv(brdev);
 	struct br_cpu_netstats *brstats = this_cpu_ptr(br->stats);
+	struct net_port_vlans *pv;
 
 	u64_stats_update_begin(&brstats->syncp);
 	brstats->rx_packets++;
@@ -39,18 +40,18 @@ static int br_pass_frame_up(struct sk_buff *skb)
 	 * packet is allowed except in promisc modue when someone
 	 * may be running packet capture.
 	 */
+	pv = br_get_vlan_info(br);
 	if (!(brdev->flags & IFF_PROMISC) &&
-	    !br_allowed_egress(br, br_get_vlan_info(br), skb)) {
+	    !br_allowed_egress(br, pv, skb)) {
 		kfree_skb(skb);
 		return NET_RX_DROP;
 	}
 
-	skb = br_handle_vlan(br, br_get_vlan_info(br), skb);
-	if (!skb)
-		return NET_RX_DROP;
-
 	indev = skb->dev;
 	skb->dev = brdev;
+	skb = br_handle_vlan(br, pv, skb);
+	if (!skb)
+		return NET_RX_DROP;
 
 	return NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
 		       netif_receive_skb);
net/bridge/br_vlan.c +14 -0
index af5ebd1..abc841c 100644
@@ -144,6 +144,20 @@ struct sk_buff *br_handle_vlan(struct net_bridge *br,
 	if (!br->vlan_enabled)
 		goto out;
 
+	/* Vlan filter table must be configured at this point.  The
+	 * only exception is the bridge is set in promisc mode and the
+	 * packet is destined for the bridge device.  In this case
+	 * pass the packet as is.
+	 */
+	if (!pv) {
+		if ((br->dev->flags & IFF_PROMISC) && skb->dev == br->dev)
+			goto out;
+		else {
+			kfree_skb_list(skb);
+			return NULL;
+		}
+	}
+
 	/* At this point, we know that the frame was filtered and contains
 	 * a valid vlan id.  If the vlan id is set in the untagged bitmap,
 	 * send untagged; otherwise, send taged.
Signature · 1 line
1.8.4.2
#1 lore raw
Quoted 10 lines · Vlad Yasevich

When the vlan filtering is enabled on the bridge, but the filter is not configured on the bridge device itself, running tcpdump on the bridge device will result in a an Oops with NULL pointer dereference. The reason is that br_pass_frame_up() will bypass the vlan check because promisc flag is set. It will then try to get the table pointer and process the packet based on the table. Since the table pointer is NULL, we oops. Catch this special condition in br_handle_vlan().

Quoted 8 lines

---
Changes since v1:
- Do not use a BUG or BUG_ON as it is possible to trigger the false BUG condition when thrashing the vlan_enable toggle. Instead just drop the skb.

Maybe that frame went through should_deliver() while vlan_filtering was disabled?
I hope it doesn't affect other codes in an adverse way...

Quoted 5 lines
 net/bridge/br_input.c | 11 ++++++-----
 net/bridge/br_vlan.c  | 14 ++++++++++++++
 2 files changed, 20 insertions(+), 5 deletions(-)

...

Quoted 8 lines
net/bridge/br_vlan.c +0 -0
index af5ebd1..abc841c 100644
@@ -144,6 +144,20 @@ struct sk_buff *br_handle_vlan(struct net_bridge *br,
 	if (!br->vlan_enabled)
 		goto out;
 

net/bridge/br_vlan.c struct sk_buff *br_handle_vlan(struct net_bridge *br, · line 156

Quoted 10 lines
net/bridge/br_vlan.c +10 -0
+	/* Vlan filter table must be configured at this point.  The
+	 * only exception is the bridge is set in promisc mode and the
+	 * packet is destined for the bridge device.  In this case
+	 * pass the packet as is.
+	 */
+	if (!pv) {
+		if ((br->dev->flags & IFF_PROMISC) && skb->dev == br->dev)
+			goto out;
+		else {
+			kfree_skb_list(skb);

Why is this not kfree_skb() but kfree_skb_list()? I haven't seen kfree_skb_list() in the bridge code.

Thanks,
Toshiaki Makita

Quoted 7 lines
net/bridge/br_vlan.c +4 -0
+			return NULL;
+		}
+	}
+
 	/* At this point, we know that the frame was filtered and contains
 	 * a valid vlan id.  If the vlan id is set in the untagged bitmap,
 	 * send untagged; otherwise, send taged.
#2 lore raw
Quoted 20 lines · Toshiaki Makita
Quoted 10 lines · Vlad Yasevich

When the vlan filtering is enabled on the bridge, but the filter is not configured on the bridge device itself, running tcpdump on the bridge device will result in a an Oops with NULL pointer dereference. The reason is that br_pass_frame_up() will bypass the vlan check because promisc flag is set. It will then try to get the table pointer and process the packet based on the table. Since the table pointer is NULL, we oops. Catch this special condition in br_handle_vlan().

Quoted 8 lines

---
Changes since v1:
- Do not use a BUG or BUG_ON as it is possible to trigger the false BUG condition when thrashing the vlan_enable toggle. Instead just drop the skb.

Quoted 2 lines

Maybe that frame went through should_deliver() while vlan_filtering was disabled?

yes. That's what happend.

Quoted 1 line

I hope it doesn't affect other codes in an adverse way...

I didn't see any adverse conditions while running the while(1) loop changing vlan_flitering, but I didn't run it for all that long (about a minute).

I am working on a series to reduce the possible races that involves marking the skb (in the cb) and using that marking in later invocations.

Quoted 15 lines
Quoted 6 lines

 net/bridge/br_input.c | 11 ++++++-----
 net/bridge/br_vlan.c  | 14 ++++++++++++++
 2 files changed, 20 insertions(+), 5 deletions(-)

...

Quoted 8 lines
net/bridge/br_vlan.c +0 -0
index af5ebd1..abc841c 100644
@@ -144,6 +144,20 @@ struct sk_buff *br_handle_vlan(struct net_bridge *br,
 	if (!br->vlan_enabled)
 		goto out;
 
Quoted 13 lines

net/bridge/br_vlan.c struct sk_buff *br_handle_vlan(struct net_bridge *br, · line 156

Quoted 10 lines
net/bridge/br_vlan.c +10 -0
+	/* Vlan filter table must be configured at this point.  The
+	 * only exception is the bridge is set in promisc mode and the
+	 * packet is destined for the bridge device.  In this case
+	 * pass the packet as is.
+	 */
+	if (!pv) {
+		if ((br->dev->flags & IFF_PROMISC) && skb->dev == br->dev)
+			goto out;
+		else {
+			kfree_skb_list(skb);

Why is this not kfree_skb() but kfree_skb_list()? I haven't seen kfree_skb_list() in the bridge code.

I thought it is possible to get a list here, but upon further inspection
I don't see that happening. I'll change that to kfree_skb().

Thanks
-vlad

Quoted 13 lines

Thanks,
Toshiaki Makita

Quoted 7 lines
net/bridge/br_vlan.c +4 -0
+			return NULL;
+		}
+	}
+
 	/* At this point, we know that the frame was filtered and contains
 	 * a valid vlan id.  If the vlan id is set in the untagged bitmap,
 	 * send untagged; otherwise, send taged.