summaryrefslogtreecommitdiffstats
path: root/drivers/net/tun.c
diff options
context:
space:
mode:
authorKirill Tkhai <ktkhai@virtuozzo.com>2019-03-20 05:16:42 -0400
committerDavid S. Miller <davem@davemloft.net>2019-03-21 16:19:15 -0400
commit0c3e0e3bb623c3735b8c9ab8aa8332f944f83a9f (patch)
treea0bf65cefd6045f9942a5f010121d4a73964b1b8 /drivers/net/tun.c
parent28b18b39c5a7df75ff657bd9e09f3b8091651e61 (diff)
tun: Add ioctl() TUNGETDEVNETNS cmd to allow obtaining real net ns of tun device
In commit f2780d6d7475 "tun: Add ioctl() SIOCGSKNS cmd to allow obtaining net ns of tun device" it was missed that tun may change its net ns, while net ns of socket remains the same as it was created initially. SIOCGSKNS returns net ns of socket, so it is not suitable for obtaining net ns of device. We may have two tun devices with the same names in two net ns, and in this case it's not possible to determ, which of them fd refers to (TUNGETIFF will return the same name). This patch adds new ioctl() cmd for obtaining net ns of a device. Reported-by: Harald Albrecht <harald.albrecht@gmx.net> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/tun.c')
-rw-r--r--drivers/net/tun.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index ef3b65514976..60d0a4e60ec5 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -3102,6 +3102,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
3102 3102
3103 tun_debug(KERN_INFO, tun, "tun_chr_ioctl cmd %u\n", cmd); 3103 tun_debug(KERN_INFO, tun, "tun_chr_ioctl cmd %u\n", cmd);
3104 3104
3105 net = dev_net(tun->dev);
3105 ret = 0; 3106 ret = 0;
3106 switch (cmd) { 3107 switch (cmd) {
3107 case TUNGETIFF: 3108 case TUNGETIFF:
@@ -3327,6 +3328,13 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
3327 ret = tun_net_change_carrier(tun->dev, (bool)carrier); 3328 ret = tun_net_change_carrier(tun->dev, (bool)carrier);
3328 break; 3329 break;
3329 3330
3331 case TUNGETDEVNETNS:
3332 ret = -EPERM;
3333 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
3334 goto unlock;
3335 ret = open_related_ns(&net->ns, get_net_ns);
3336 break;
3337
3330 default: 3338 default:
3331 ret = -EINVAL; 3339 ret = -EINVAL;
3332 break; 3340 break;