提交 7c0c3b1a 编写于 作者: J Jason Wang 提交者: David S. Miller

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: NJason Wang <jasowang@redhat.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 b8deabd3
...@@ -488,8 +488,6 @@ static int tun_attach(struct tun_struct *tun, struct file *file) ...@@ -488,8 +488,6 @@ static int tun_attach(struct tun_struct *tun, struct file *file)
err = -EINVAL; err = -EINVAL;
if (rtnl_dereference(tfile->tun)) if (rtnl_dereference(tfile->tun))
goto out; goto out;
if (tfile->detached && tun != tfile->detached)
goto out;
err = -EBUSY; err = -EBUSY;
if (!(tun->flags & TUN_TAP_MQ) && tun->numqueues == 1) 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,6 +1541,9 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
struct net_device *dev; struct net_device *dev;
int err; int err;
if (tfile->detached)
return -EINVAL;
dev = __dev_get_by_name(net, ifr->ifr_name); dev = __dev_get_by_name(net, ifr->ifr_name);
if (dev) { if (dev) {
if (ifr->ifr_flags & IFF_TUN_EXCL) if (ifr->ifr_flags & IFF_TUN_EXCL)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册