aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/tun.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-10-02 14:11:09 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-02 14:11:09 -0400
commit437589a74b6a590d175f86cf9f7b2efcee7765e7 (patch)
tree37bf8635b1356d80ef002b00e84f3faf3d555a63 /drivers/net/tun.c
parent68d47a137c3bef754923bccf73fb639c9b0bbd5e (diff)
parent72235465864d84cedb2d9f26f8e1de824ee20339 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace
Pull user namespace changes from Eric Biederman: "This is a mostly modest set of changes to enable basic user namespace support. This allows the code to code to compile with user namespaces enabled and removes the assumption there is only the initial user namespace. Everything is converted except for the most complex of the filesystems: autofs4, 9p, afs, ceph, cifs, coda, fuse, gfs2, ncpfs, nfs, ocfs2 and xfs as those patches need a bit more review. The strategy is to push kuid_t and kgid_t values are far down into subsystems and filesystems as reasonable. Leaving the make_kuid and from_kuid operations to happen at the edge of userspace, as the values come off the disk, and as the values come in from the network. Letting compile type incompatible compile errors (present when user namespaces are enabled) guide me to find the issues. The most tricky areas have been the places where we had an implicit union of uid and gid values and were storing them in an unsigned int. Those places were converted into explicit unions. I made certain to handle those places with simple trivial patches. Out of that work I discovered we have generic interfaces for storing quota by projid. I had never heard of the project identifiers before. Adding full user namespace support for project identifiers accounts for most of the code size growth in my git tree. Ultimately there will be work to relax privlige checks from "capable(FOO)" to "ns_capable(user_ns, FOO)" where it is safe allowing root in a user names to do those things that today we only forbid to non-root users because it will confuse suid root applications. While I was pushing kuid_t and kgid_t changes deep into the audit code I made a few other cleanups. I capitalized on the fact we process netlink messages in the context of the message sender. I removed usage of NETLINK_CRED, and started directly using current->tty. Some of these patches have also made it into maintainer trees, with no problems from identical code from different trees showing up in linux-next. After reading through all of this code I feel like I might be able to win a game of kernel trivial pursuit." Fix up some fairly trivial conflicts in netfilter uid/git logging code. * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: (107 commits) userns: Convert the ufs filesystem to use kuid/kgid where appropriate userns: Convert the udf filesystem to use kuid/kgid where appropriate userns: Convert ubifs to use kuid/kgid userns: Convert squashfs to use kuid/kgid where appropriate userns: Convert reiserfs to use kuid and kgid where appropriate userns: Convert jfs to use kuid/kgid where appropriate userns: Convert jffs2 to use kuid and kgid where appropriate userns: Convert hpfs to use kuid and kgid where appropriate userns: Convert btrfs to use kuid/kgid where appropriate userns: Convert bfs to use kuid/kgid where appropriate userns: Convert affs to use kuid/kgid wherwe appropriate userns: On alpha modify linux_to_osf_stat to use convert from kuids and kgids userns: On ia64 deal with current_uid and current_gid being kuid and kgid userns: On ppc convert current_uid from a kuid before printing. userns: Convert s390 getting uid and gid system calls to use kuid and kgid userns: Convert s390 hypfs to use kuid and kgid where appropriate userns: Convert binder ipc to use kuids userns: Teach security_path_chown to take kuids and kgids userns: Add user namespace support to IMA userns: Convert EVM to deal with kuids and kgids in it's hmac computation ...
Diffstat (limited to 'drivers/net/tun.c')
-rw-r--r--drivers/net/tun.c46
1 files changed, 32 insertions, 14 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 9336b829cc81..0873cdcf39be 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -121,8 +121,8 @@ struct tun_sock;
121struct tun_struct { 121struct tun_struct {
122 struct tun_file *tfile; 122 struct tun_file *tfile;
123 unsigned int flags; 123 unsigned int flags;
124 uid_t owner; 124 kuid_t owner;
125 gid_t group; 125 kgid_t group;
126 126
127 struct net_device *dev; 127 struct net_device *dev;
128 netdev_features_t set_features; 128 netdev_features_t set_features;
@@ -1032,8 +1032,8 @@ static void tun_setup(struct net_device *dev)
1032{ 1032{
1033 struct tun_struct *tun = netdev_priv(dev); 1033 struct tun_struct *tun = netdev_priv(dev);
1034 1034
1035 tun->owner = -1; 1035 tun->owner = INVALID_UID;
1036 tun->group = -1; 1036 tun->group = INVALID_GID;
1037 1037
1038 dev->ethtool_ops = &tun_ethtool_ops; 1038 dev->ethtool_ops = &tun_ethtool_ops;
1039 dev->destructor = tun_free_netdev; 1039 dev->destructor = tun_free_netdev;
@@ -1156,14 +1156,20 @@ static ssize_t tun_show_owner(struct device *dev, struct device_attribute *attr,
1156 char *buf) 1156 char *buf)
1157{ 1157{
1158 struct tun_struct *tun = netdev_priv(to_net_dev(dev)); 1158 struct tun_struct *tun = netdev_priv(to_net_dev(dev));
1159 return sprintf(buf, "%d\n", tun->owner); 1159 return uid_valid(tun->owner)?
1160 sprintf(buf, "%u\n",
1161 from_kuid_munged(current_user_ns(), tun->owner)):
1162 sprintf(buf, "-1\n");
1160} 1163}
1161 1164
1162static ssize_t tun_show_group(struct device *dev, struct device_attribute *attr, 1165static ssize_t tun_show_group(struct device *dev, struct device_attribute *attr,
1163 char *buf) 1166 char *buf)
1164{ 1167{
1165 struct tun_struct *tun = netdev_priv(to_net_dev(dev)); 1168 struct tun_struct *tun = netdev_priv(to_net_dev(dev));
1166 return sprintf(buf, "%d\n", tun->group); 1169 return gid_valid(tun->group) ?
1170 sprintf(buf, "%u\n",
1171 from_kgid_munged(current_user_ns(), tun->group)):
1172 sprintf(buf, "-1\n");
1167} 1173}
1168 1174
1169static DEVICE_ATTR(tun_flags, 0444, tun_show_flags, NULL); 1175static DEVICE_ATTR(tun_flags, 0444, tun_show_flags, NULL);
@@ -1190,8 +1196,8 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1190 else 1196 else
1191 return -EINVAL; 1197 return -EINVAL;
1192 1198
1193 if (((tun->owner != -1 && cred->euid != tun->owner) || 1199 if (((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1194 (tun->group != -1 && !in_egroup_p(tun->group))) && 1200 (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1195 !capable(CAP_NET_ADMIN)) 1201 !capable(CAP_NET_ADMIN))
1196 return -EPERM; 1202 return -EPERM;
1197 err = security_tun_dev_attach(tun->socket.sk); 1203 err = security_tun_dev_attach(tun->socket.sk);
@@ -1375,6 +1381,8 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
1375 void __user* argp = (void __user*)arg; 1381 void __user* argp = (void __user*)arg;
1376 struct sock_fprog fprog; 1382 struct sock_fprog fprog;
1377 struct ifreq ifr; 1383 struct ifreq ifr;
1384 kuid_t owner;
1385 kgid_t group;
1378 int sndbuf; 1386 int sndbuf;
1379 int vnet_hdr_sz; 1387 int vnet_hdr_sz;
1380 int ret; 1388 int ret;
@@ -1448,16 +1456,26 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
1448 1456
1449 case TUNSETOWNER: 1457 case TUNSETOWNER:
1450 /* Set owner of the device */ 1458 /* Set owner of the device */
1451 tun->owner = (uid_t) arg; 1459 owner = make_kuid(current_user_ns(), arg);
1452 1460 if (!uid_valid(owner)) {
1453 tun_debug(KERN_INFO, tun, "owner set to %d\n", tun->owner); 1461 ret = -EINVAL;
1462 break;
1463 }
1464 tun->owner = owner;
1465 tun_debug(KERN_INFO, tun, "owner set to %d\n",
1466 from_kuid(&init_user_ns, tun->owner));
1454 break; 1467 break;
1455 1468
1456 case TUNSETGROUP: 1469 case TUNSETGROUP:
1457 /* Set group of the device */ 1470 /* Set group of the device */
1458 tun->group= (gid_t) arg; 1471 group = make_kgid(current_user_ns(), arg);
1459 1472 if (!gid_valid(group)) {
1460 tun_debug(KERN_INFO, tun, "group set to %d\n", tun->group); 1473 ret = -EINVAL;
1474 break;
1475 }
1476 tun->group = group;
1477 tun_debug(KERN_INFO, tun, "group set to %d\n",
1478 from_kgid(&init_user_ns, tun->group));
1461 break; 1479 break;
1462 1480
1463 case TUNSETLINK: 1481 case TUNSETLINK: