Skip to contentSkip to conversation

vlan: Fix crash when hwaccel rx pkt for non-existant vlan.

PATCH In review Ben Greear 2 participants 3 messages Oct 26, 2010 – Oct 28, 2010

Subsystems (2)
lore
Share & tools
lore

Ben Greear

author
#0 lore raw

PATCH v2 1/1 vlan: Fix crash when hwaccel rx pkt for non-existant vlan.

The vlan_hwaccel_do_receive code expected skb->dev to always be a vlan device, but if the NIC was promisc, and the VLAN for a particular VID was not configured, then this method could receive a packet where skb->dev was NOT a vlan device. This caused access of bad memory and a crash.

---
v1 -> v2: Simplify patch..no need for setting pkt-type, etc.

:100644 100644 0eb96f7... 0687b6c... M net/8021q/vlan_core.c
:100644 100644 660dd41... 5dc45b9... M net/core/dev.c

 net/8021q/vlan_core.c |    3 +++
 net/core/dev.c        |    5 +++--
 2 files changed, 6 insertions(+), 2 deletions(-)
net/8021q/vlan_core.c +3 -0
index 0eb96f7..0687b6c 100644
@@ -43,6 +43,9 @@ int vlan_hwaccel_do_receive(struct sk_buff *skb)
 	struct net_device *dev = skb->dev;
 	struct vlan_rx_stats     *rx_stats;
 
+	if (!is_vlan_dev(dev))
+		return 0;
+
 	skb->dev = vlan_dev_info(dev)->real_dev;
 	netif_nit_deliver(skb);
 
net/core/dev.c +3 -2
index 660dd41..5dc45b9 100644
@@ -2828,8 +2828,9 @@ static int __netif_receive_skb(struct sk_buff *skb)
 	if (!netdev_tstamp_prequeue)
 		net_timestamp_check(skb);
 
-	if (vlan_tx_tag_present(skb) && vlan_hwaccel_do_receive(skb))
-		return NET_RX_SUCCESS;
+	if (vlan_tx_tag_present(skb))
+		/* This method cannot fail at this time. */
+		vlan_hwaccel_do_receive(skb);
 
 	/* if we've gotten here through NAPI, check netpoll */
 	if (netpoll_receive_skb(skb))
Signature · 1 line
1.6.2.5
#1 lore raw
Quoted 21 lines · Ben Greear

The vlan_hwaccel_do_receive code expected skb->dev to always be a vlan device, but if the NIC was promisc, and the VLAN for a particular VID was not configured, then this method could receive a packet where skb->dev was NOT a vlan device.  This caused access of bad memory and a crash.

---
v1 -> v2:  Simplify patch..no need for setting pkt-type, etc.

:100644 100644 0eb96f7... 0687b6c... M  net/8021q/vlan_core.c :100644 100644 660dd41... 5dc45b9... M  net/core/dev.c net/8021q/vlan_core.c |    3 +++
 net/core/dev.c        |    5 +++--

 2 files changed, 6 insertions(+), 2 deletions(-)
net/8021q/vlan_core.c +0 -0
index 0eb96f7..0687b6c 100644

net/8021q/vlan_core.c int vlan_hwaccel_do_receive(struct sk_buff *skb) · line 51

Quoted 9 lines
net/8021q/vlan_core.c +3 -0
@@ -43,6 +43,9 @@ int vlan_hwaccel_do_receive(struct sk_buff *skb)
        struct net_device *dev = skb->dev;
        struct vlan_rx_stats     *rx_stats;
 
+       if (!is_vlan_dev(dev))
+               return 0;
+
        skb->dev = vlan_dev_info(dev)->real_dev;
        netif_nit_deliver(skb);
 

What if we dropped any packet with a tag in skb->vlan_tci before it gets to the bridge hooks? That would accomplish the original goal of getting packets to tcpdump while preventing them from making it to places where they aren't expected, It will provide the same behavior as earlier kernels.

net/core/dev.c static int __netif_receive_skb(struct sk_buff *skb) · line 2833

Quoted 13 lines
net/core/dev.c +3 -2
index 660dd41..5dc45b9 100644
@@ -2828,8 +2828,9 @@ static int __netif_receive_skb(struct sk_buff *skb)
        if (!netdev_tstamp_prequeue)
                net_timestamp_check(skb);
 
-       if (vlan_tx_tag_present(skb) && vlan_hwaccel_do_receive(skb))
-               return NET_RX_SUCCESS;
+       if (vlan_tx_tag_present(skb))
+               /* This method cannot fail at this time. */
+               vlan_hwaccel_do_receive(skb);

This is correct but it's not a bugfix, so I'm not sure that it should go to -stable. It's already been fixed for 2.6.37.

author
#2 lore raw
Quoted 25 lines · Jesse Gross
Quoted 24 lines · Ben Greear

The vlan_hwaccel_do_receive code expected skb->dev to always be a vlan device, but if the NIC was promisc, and the VLAN for a particular VID was not configured, then this method could receive a packet where skb->dev was NOT a vlan device. This caused access of bad memory and a crash.

---
v1 -> v2: Simplify patch..no need for setting pkt-type, etc.

:100644 100644 0eb96f7... 0687b6c... M net/8021q/vlan_core.c :100644 100644 660dd41... 5dc45b9... M net/core/dev.c

  net/8021q/vlan_core.c |    3 +++
  net/core/dev.c        |    5 +++--
  2 files changed, 6 insertions(+), 2 deletions(-)
net/8021q/vlan_core.c +0 -0
index 0eb96f7..0687b6c 100644
@@ -43,6 +43,9 @@ int vlan_hwaccel_do_receive(struct sk_buff *skb)
        struct net_device *dev = skb->dev;
        struct vlan_rx_stats     *rx_stats;
 
Quoted 12 lines

net/8021q/vlan_core.c int vlan_hwaccel_do_receive(struct sk_buff *skb) · line 51

Quoted 6 lines
net/8021q/vlan_core.c +3 -0
+       if (!is_vlan_dev(dev))
+               return 0;
+
        skb->dev = vlan_dev_info(dev)->real_dev;
        netif_nit_deliver(skb);
 

What if we dropped any packet with a tag in skb->vlan_tci before it gets to the bridge hooks? That would accomplish the original goal of getting packets to tcpdump while preventing them from making it to places where they aren't expected, It will provide the same behavior as earlier kernels.

The VLAN code has changed a lot since I messed with it last, so there very well may be better ways to fix this than what I came up with. Please propose a patch if you have a suggestion.

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com