diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2009-04-18 14:15:52 +0000 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-04-20 03:01:47 -0700 |
commit | 9c3fea6ab04a7bd9298e635bf29b4a5379f6c476 (patch) | |
tree | 2b9977d85dc5f4de230a2d556e692cb30a6d945a /scripts | |
parent | 5db8765a86a4cbaf45adaf8c231cf9a6ca2dcfaf (diff) | |
download | talos-obmc-linux-9c3fea6ab04a7bd9298e635bf29b4a5379f6c476.tar.gz talos-obmc-linux-9c3fea6ab04a7bd9298e635bf29b4a5379f6c476.zip |
tun: Only free a netdev when all tun descriptors are closed
The commit c70f182940f988448f3c12a209d18b1edc276e33 ("tun: Fix
races between tun_net_close and free_netdev") fixed a race where
an asynchronous deletion of a tun device can hose a poll(2) on
a tun fd attached to that device.
However, this came at the cost of moving the tun wait queue into
the tun file data structure. The problem with this is that it
imposes restrictions on when and where the tun device can access
the wait queue since the tun file may change at any time due to
detaching and reattaching.
In particular, now that we need to use the wait queue on the
receive path it becomes difficult to properly synchronise this
with the detachment of the tun device.
This patch solves the original race in a different way. Since
the race is only because the underlying memory gets freed, we
can prevent it simply by ensuring that we don't do that until
all tun descriptors ever attached to the device (even if they
have since be detached because they may still be sitting in poll)
have been closed.
This is done by using reference counting the attached tun file
descriptors. The refcount in tun->sk has been reappropriated
for this purpose since it was already being used for that, albeit
from the opposite angle.
Note that we no longer zero tfile->tun since tun_get will return
NULL anyway after the refcount on tfile hits zero. Instead it
represents whether this device has ever been attached to a device.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'scripts')
0 files changed, 0 insertions, 0 deletions