diff options
author | Jiri Pirko <jiri@resnulli.us> | 2013-05-09 00:23:40 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-05-11 19:25:00 -0400 |
commit | 233c7df0821c4190e2d3f4be0f2ca0ab40a5ed8c (patch) | |
tree | 3a384d69d266b382a700e87334cb6b40355511bd /drivers/net/macvlan.c | |
parent | fb863b8beaf8121199c3dc32ab0126e8ce9cb34a (diff) |
macvlan: fix passthru mode race between dev removal and rx path
Currently, if macvlan in passthru mode is created and data are rxed and
you remove this device, following panic happens:
NULL pointer dereference at 0000000000000198
IP: [<ffffffffa0196058>] macvlan_handle_frame+0x153/0x1f7 [macvlan]
I'm using following script to trigger this:
<script>
while [ 1 ]
do
ip link add link e1 name macvtap0 type macvtap mode passthru
ip link set e1 up
ip link set macvtap0 up
IFINDEX=`ip link |grep macvtap0 | cut -f 1 -d ':'`
cat /dev/tap$IFINDEX >/dev/null &
ip link del dev macvtap0
done
</script>
I run this script while "ping -f" is running on another machine to send
packets to e1 rx.
Reason of the panic is that list_first_entry() is blindly called in
macvlan_handle_frame() even if the list was empty. vlan is set to
incorrect pointer which leads to the crash.
I'm fixing this by protecting port->vlans list by rcu and by preventing
from getting incorrect pointer in case the list is empty.
Introduced by: commit eb06acdc85585f2 "macvlan: Introduce 'passthru' mode to takeover the underlying device"
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/macvlan.c')
-rw-r--r-- | drivers/net/macvlan.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index d5a141c7c4e7..1c502bb0c916 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c | |||
@@ -229,7 +229,8 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb) | |||
229 | } | 229 | } |
230 | 230 | ||
231 | if (port->passthru) | 231 | if (port->passthru) |
232 | vlan = list_first_entry(&port->vlans, struct macvlan_dev, list); | 232 | vlan = list_first_or_null_rcu(&port->vlans, |
233 | struct macvlan_dev, list); | ||
233 | else | 234 | else |
234 | vlan = macvlan_hash_lookup(port, eth->h_dest); | 235 | vlan = macvlan_hash_lookup(port, eth->h_dest); |
235 | if (vlan == NULL) | 236 | if (vlan == NULL) |
@@ -814,7 +815,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev, | |||
814 | if (err < 0) | 815 | if (err < 0) |
815 | goto upper_dev_unlink; | 816 | goto upper_dev_unlink; |
816 | 817 | ||
817 | list_add_tail(&vlan->list, &port->vlans); | 818 | list_add_tail_rcu(&vlan->list, &port->vlans); |
818 | netif_stacked_transfer_operstate(lowerdev, dev); | 819 | netif_stacked_transfer_operstate(lowerdev, dev); |
819 | 820 | ||
820 | return 0; | 821 | return 0; |
@@ -842,7 +843,7 @@ void macvlan_dellink(struct net_device *dev, struct list_head *head) | |||
842 | { | 843 | { |
843 | struct macvlan_dev *vlan = netdev_priv(dev); | 844 | struct macvlan_dev *vlan = netdev_priv(dev); |
844 | 845 | ||
845 | list_del(&vlan->list); | 846 | list_del_rcu(&vlan->list); |
846 | unregister_netdevice_queue(dev, head); | 847 | unregister_netdevice_queue(dev, head); |
847 | netdev_upper_dev_unlink(vlan->lowerdev, dev); | 848 | netdev_upper_dev_unlink(vlan->lowerdev, dev); |
848 | } | 849 | } |