aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2010-03-30 00:33:28 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-04-01 19:02:10 -0400
commita1c9d89a98cbbc52ead6c44bb0c31eaaa37c5770 (patch)
tree5980466b4e252d9082adfce04297ab19138fdf43
parent8c96206544955131f6d7cef09371950f34ebca5a (diff)
net: Potential null skb->dev dereference
[ Upstream commit 0641e4fbf2f824faee00ea74c459a088d94905fd ] When doing "ifenslave -d bond0 eth0", there is chance to get NULL dereference in netif_receive_skb(), because dev->master suddenly becomes NULL after we tested it. We should use ACCESS_ONCE() to avoid this (or rcu_dereference()) Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--include/linux/netdevice.h8
-rw-r--r--net/8021q/vlan_core.c4
-rw-r--r--net/core/dev.c8
3 files changed, 11 insertions, 9 deletions
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 99914e6fa3fd..03e8d81a8391 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2023,12 +2023,12 @@ static inline void skb_bond_set_mac_by_master(struct sk_buff *skb,
2023 * duplicates except for 802.3ad ETH_P_SLOW, alb non-mcast/bcast, and 2023 * duplicates except for 802.3ad ETH_P_SLOW, alb non-mcast/bcast, and
2024 * ARP on active-backup slaves with arp_validate enabled. 2024 * ARP on active-backup slaves with arp_validate enabled.
2025 */ 2025 */
2026static inline int skb_bond_should_drop(struct sk_buff *skb) 2026static inline int skb_bond_should_drop(struct sk_buff *skb,
2027 struct net_device *master)
2027{ 2028{
2028 struct net_device *dev = skb->dev;
2029 struct net_device *master = dev->master;
2030
2031 if (master) { 2029 if (master) {
2030 struct net_device *dev = skb->dev;
2031
2032 if (master->priv_flags & IFF_MASTER_ARPMON) 2032 if (master->priv_flags & IFF_MASTER_ARPMON)
2033 dev->last_rx = jiffies; 2033 dev->last_rx = jiffies;
2034 2034
diff --git a/net/8021q/vlan_core.c b/net/8021q/vlan_core.c
index e75a2f3b10af..152760a487e6 100644
--- a/net/8021q/vlan_core.c
+++ b/net/8021q/vlan_core.c
@@ -11,7 +11,7 @@ int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp,
11 if (netpoll_rx(skb)) 11 if (netpoll_rx(skb))
12 return NET_RX_DROP; 12 return NET_RX_DROP;
13 13
14 if (skb_bond_should_drop(skb)) 14 if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master)))
15 goto drop; 15 goto drop;
16 16
17 __vlan_hwaccel_put_tag(skb, vlan_tci); 17 __vlan_hwaccel_put_tag(skb, vlan_tci);
@@ -82,7 +82,7 @@ vlan_gro_common(struct napi_struct *napi, struct vlan_group *grp,
82{ 82{
83 struct sk_buff *p; 83 struct sk_buff *p;
84 84
85 if (skb_bond_should_drop(skb)) 85 if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master)))
86 goto drop; 86 goto drop;
87 87
88 __vlan_hwaccel_put_tag(skb, vlan_tci); 88 __vlan_hwaccel_put_tag(skb, vlan_tci);
diff --git a/net/core/dev.c b/net/core/dev.c
index ec874218b206..f51f940a077c 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2421,6 +2421,7 @@ int netif_receive_skb(struct sk_buff *skb)
2421{ 2421{
2422 struct packet_type *ptype, *pt_prev; 2422 struct packet_type *ptype, *pt_prev;
2423 struct net_device *orig_dev; 2423 struct net_device *orig_dev;
2424 struct net_device *master;
2424 struct net_device *null_or_orig; 2425 struct net_device *null_or_orig;
2425 int ret = NET_RX_DROP; 2426 int ret = NET_RX_DROP;
2426 __be16 type; 2427 __be16 type;
@@ -2440,11 +2441,12 @@ int netif_receive_skb(struct sk_buff *skb)
2440 2441
2441 null_or_orig = NULL; 2442 null_or_orig = NULL;
2442 orig_dev = skb->dev; 2443 orig_dev = skb->dev;
2443 if (orig_dev->master) { 2444 master = ACCESS_ONCE(orig_dev->master);
2444 if (skb_bond_should_drop(skb)) 2445 if (master) {
2446 if (skb_bond_should_drop(skb, master))
2445 null_or_orig = orig_dev; /* deliver only exact match */ 2447 null_or_orig = orig_dev; /* deliver only exact match */
2446 else 2448 else
2447 skb->dev = orig_dev->master; 2449 skb->dev = master;
2448 } 2450 }
2449 2451
2450 __get_cpu_var(netdev_rx_stat).total++; 2452 __get_cpu_var(netdev_rx_stat).total++;