فهرست منبع

tun: Do SIOCGSKNS out of rtnl_lock()

Since net ns of tun device is assigned on the device creation,
and it never changes, we do not need to use any lock to get it
from alive tun.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Kirill Tkhai 7 سال پیش
والد
کامیت
f663706a33
1فایلهای تغییر یافته به همراه7 افزوده شده و 11 حذف شده
  1. 7 11
      drivers/net/tun.c

+ 7 - 11
drivers/net/tun.c

@@ -2850,10 +2850,10 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
 			    unsigned long arg, int ifreq_len)
 			    unsigned long arg, int ifreq_len)
 {
 {
 	struct tun_file *tfile = file->private_data;
 	struct tun_file *tfile = file->private_data;
+	struct net *net = sock_net(&tfile->sk);
 	struct tun_struct *tun;
 	struct tun_struct *tun;
 	void __user* argp = (void __user*)arg;
 	void __user* argp = (void __user*)arg;
 	struct ifreq ifr;
 	struct ifreq ifr;
-	struct net *net;
 	kuid_t owner;
 	kuid_t owner;
 	kgid_t group;
 	kgid_t group;
 	int sndbuf;
 	int sndbuf;
@@ -2877,14 +2877,18 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
 		 */
 		 */
 		return put_user(IFF_TUN | IFF_TAP | TUN_FEATURES,
 		return put_user(IFF_TUN | IFF_TAP | TUN_FEATURES,
 				(unsigned int __user*)argp);
 				(unsigned int __user*)argp);
-	} else if (cmd == TUNSETQUEUE)
+	} else if (cmd == TUNSETQUEUE) {
 		return tun_set_queue(file, &ifr);
 		return tun_set_queue(file, &ifr);
+	} else if (cmd == SIOCGSKNS) {
+		if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
+			return -EPERM;
+		return open_related_ns(&net->ns, get_net_ns);
+	}
 
 
 	ret = 0;
 	ret = 0;
 	rtnl_lock();
 	rtnl_lock();
 
 
 	tun = tun_get(tfile);
 	tun = tun_get(tfile);
-	net = sock_net(&tfile->sk);
 	if (cmd == TUNSETIFF) {
 	if (cmd == TUNSETIFF) {
 		ret = -EEXIST;
 		ret = -EEXIST;
 		if (tun)
 		if (tun)
@@ -2914,14 +2918,6 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
 		tfile->ifindex = ifindex;
 		tfile->ifindex = ifindex;
 		goto unlock;
 		goto unlock;
 	}
 	}
-	if (cmd == SIOCGSKNS) {
-		ret = -EPERM;
-		if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
-			goto unlock;
-
-		ret = open_related_ns(&net->ns, get_net_ns);
-		goto unlock;
-	}
 
 
 	ret = -EBADFD;
 	ret = -EBADFD;
 	if (!tun)
 	if (!tun)