Thread (3 messages) flat view 3 messages, 3 authors, 2015-11-05

Re: [PATCH 1/1] packet: race condition in packet_bind

From: William Dauchy <hidden>
Date: 2015-11-05 21:20:36

Hi Francesco,

On Thu, Nov 5, 2015 at 5:16 PM, Francesco Ruggeri
[off-list ref] wrote:
There is a race conditions between packet_notifier and packet_bind{_spkt}.

It happens if packet_notifier(NETDEV_UNREGISTER) executes between the
time packet_bind{_spkt} takes a reference on the new netdevice and the
time packet_do_bind sets po->ifindex.
In this case the notification can be missed.
If this happens during a dev_change_net_namespace this can result in the
netdevice to be moved to the new namespace while the packet_sock in the
old namespace still holds a reference on it. When the netdevice is later
deleted in the new namespace the deletion hangs since the packet_sock
is not found in the new namespace' &net->packet.sklist.
It can be reproduced with the script below.

This patch makes packet_do_bind check again for the presence of the
netdevice in the packet_sock's namespace after the synchronize_net
in unregister_prot_hook.
More in general it also uses the rcu lock for the duration of the bind
to stop dev_change_net_namespace/rollback_registered_many from
going past the synchronize_net following unlist_netdevice, so that
no NETDEV_UNREGISTER notifications can happen on the new netdevice
while the bind is executing. In order to do this some code from
packet_bind{_spkt} is consolidated into packet_do_dev.
I was triggering the same kind of race but was unable to reproduce it reliably.

Tested on both v3.14.x and v4.1.x, looks good to me as well.

Thanks a lot for this work (and the attached test),
-- 
William
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help