summaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorJason Wang <jasowang@redhat.com>2013-01-11 17:59:33 +0100
committerDavid S. Miller <davem@davemloft.net>2013-01-12 04:42:02 +0100
commit7c0c3b1a8a175437991ccc898ed66ec5e4a96208 (patch)
tree504dde46c8ea52d750ebd5e9e55e8c432beb83db /drivers/net
parenttuntap: switch to use rtnl_dereference() (diff)
downloadlinux-7c0c3b1a8a175437991ccc898ed66ec5e4a96208.tar.xz
linux-7c0c3b1a8a175437991ccc898ed66ec5e4a96208.zip
tuntap: forbid calling TUNSETIFF when detached
Michael points out that even after Stefan's fix the TUNSETIFF is still allowed to create a new tap device. This because we only check tfile->tun but the tfile->detached were introduced. Fix this by failing early in tun_set_iff() if the file is detached. After this fix, there's no need to do the check again in tun_set_iff(), so this patch removes it. Cc: Michael S. Tsirkin <mst@redhat.com> Cc: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/tun.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index aa963c44450a..a36b56f0940b 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -488,8 +488,6 @@ static int tun_attach(struct tun_struct *tun, struct file *file)
err = -EINVAL;
if (rtnl_dereference(tfile->tun))
goto out;
- if (tfile->detached && tun != tfile->detached)
- goto out;
err = -EBUSY;
if (!(tun->flags & TUN_TAP_MQ) && tun->numqueues == 1)
@@ -1543,6 +1541,9 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
struct net_device *dev;
int err;
+ if (tfile->detached)
+ return -EINVAL;
+
dev = __dev_get_by_name(net, ifr->ifr_name);
if (dev) {
if (ifr->ifr_flags & IFF_TUN_EXCL)