]> git.baikalelectronics.ru Git - kernel.git/commit
macvlan: fix passthru mode race between dev removal and rx path
authorJiri Pirko <jiri@resnulli.us>
Thu, 9 May 2013 04:23:40 +0000 (04:23 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sat, 11 May 2013 23:25:00 +0000 (16:25 -0700)
commit1b355a687e8220fe7e8dc7d23d169ca60757c935
tree3a384d69d266b382a700e87334cb6b40355511bd
parent2a8353e834dc65396017d4a2ea3ff31f47badc8e
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 716c00dbd7781c1 "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>
drivers/net/macvlan.c