diff options
author | Jason Wang <jasowang@redhat.com> | 2013-01-11 11:59:33 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-01-11 22:42:02 -0500 |
commit | 7c0c3b1a8a175437991ccc898ed66ec5e4a96208 (patch) | |
tree | 504dde46c8ea52d750ebd5e9e55e8c432beb83db /drivers/net | |
parent | b8deabd3eebaa96cf8d6e290d67b03f36c7f7a41 (diff) |
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.c | 5 |
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) | |||
488 | err = -EINVAL; | 488 | err = -EINVAL; |
489 | if (rtnl_dereference(tfile->tun)) | 489 | if (rtnl_dereference(tfile->tun)) |
490 | goto out; | 490 | goto out; |
491 | if (tfile->detached && tun != tfile->detached) | ||
492 | goto out; | ||
493 | 491 | ||
494 | err = -EBUSY; | 492 | err = -EBUSY; |
495 | if (!(tun->flags & TUN_TAP_MQ) && tun->numqueues == 1) | 493 | 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) | |||
1543 | struct net_device *dev; | 1541 | struct net_device *dev; |
1544 | int err; | 1542 | int err; |
1545 | 1543 | ||
1544 | if (tfile->detached) | ||
1545 | return -EINVAL; | ||
1546 | |||
1546 | dev = __dev_get_by_name(net, ifr->ifr_name); | 1547 | dev = __dev_get_by_name(net, ifr->ifr_name); |
1547 | if (dev) { | 1548 | if (dev) { |
1548 | if (ifr->ifr_flags & IFF_TUN_EXCL) | 1549 | if (ifr->ifr_flags & IFF_TUN_EXCL) |