* tun: add IFF_TUN_EXCL flag to avoid opening a persistent device.
@ 2009-04-23 17:04 David Woodhouse
2009-04-27 10:24 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: David Woodhouse @ 2009-04-23 17:04 UTC (permalink / raw)
To: netdev
When creating a certain types of VPN, NetworkManager will first attempt
to find an available tun device by iterating through 'vpn%d' until it
finds one that isn't already busy. Then it'll set that to be persistent
and owned by the otherwise unprivileged user that the VPN dæmon itself
runs as.
There's a race condition here -- during the period where the vpn%d
device is created and we're waiting for the VPN dæmon to actually
connect and use it, if we try to create _another_ device we could end up
re-using the same one -- because trying to open it again doesn't get
-EBUSY as it would while it's _actually_ busy.
So solve this, we add an IFF_TUN_EXCL flag which causes tun_set_iff() to
fail if it would be opening an existing persistent tundevice -- so that
we can make sure we're getting an entirely _new_ device.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 16716ae..0488380 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -867,6 +867,8 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
dev = __dev_get_by_name(net, ifr->ifr_name);
if (dev) {
+ if (ifr->ifr_flags & IFF_TUN_EXCL)
+ return -EBUSY;
if ((ifr->ifr_flags & IFF_TUN) && dev->netdev_ops == &tun_netdev_ops)
tun = netdev_priv(dev);
else if ((ifr->ifr_flags & IFF_TAP) && dev->netdev_ops == &tap_netdev_ops)
diff --git a/include/linux/if_tun.h b/include/linux/if_tun.h
index 049d6c9..915ba57 100644
--- a/include/linux/if_tun.h
+++ b/include/linux/if_tun.h
@@ -55,6 +55,7 @@
#define IFF_NO_PI 0x1000
#define IFF_ONE_QUEUE 0x2000
#define IFF_VNET_HDR 0x4000
+#define IFF_TUN_EXCL 0x8000
/* Features for GSO (TUNSETOFFLOAD). */
#define TUN_F_CSUM 0x01 /* You can hand me unchecksummed packets. */
--
David Woodhouse Open Source Technology Centre
David.Woodhouse@intel.com Intel Corporation
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: tun: add IFF_TUN_EXCL flag to avoid opening a persistent device.
2009-04-23 17:04 tun: add IFF_TUN_EXCL flag to avoid opening a persistent device David Woodhouse
@ 2009-04-27 10:24 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2009-04-27 10:24 UTC (permalink / raw)
To: dwmw2; +Cc: netdev
From: David Woodhouse <dwmw2@infradead.org>
Date: Thu, 23 Apr 2009 18:04:18 +0100
> When creating a certain types of VPN, NetworkManager will first attempt
> to find an available tun device by iterating through 'vpn%d' until it
> finds one that isn't already busy. Then it'll set that to be persistent
> and owned by the otherwise unprivileged user that the VPN dæmon itself
> runs as.
>
> There's a race condition here -- during the period where the vpn%d
> device is created and we're waiting for the VPN dæmon to actually
> connect and use it, if we try to create _another_ device we could end up
> re-using the same one -- because trying to open it again doesn't get
> -EBUSY as it would while it's _actually_ busy.
>
> So solve this, we add an IFF_TUN_EXCL flag which causes tun_set_iff() to
> fail if it would be opening an existing persistent tundevice -- so that
> we can make sure we're getting an entirely _new_ device.
>
> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Applied to net-next-2.6, thanks David.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-04-27 10:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-23 17:04 tun: add IFF_TUN_EXCL flag to avoid opening a persistent device David Woodhouse
2009-04-27 10:24 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).