aboutsummaryrefslogtreecommitdiffstats
path: root/security/keys/keyctl.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 /security/keys/keyctl.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 'security/keys/keyctl.c')
-rw-r--r--security/keys/keyctl.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index 6cfc6478863e..305ecb76519c 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -569,8 +569,8 @@ okay:
569 ret = snprintf(tmpbuf, PAGE_SIZE - 1, 569 ret = snprintf(tmpbuf, PAGE_SIZE - 1,
570 "%s;%d;%d;%08x;%s", 570 "%s;%d;%d;%08x;%s",
571 key->type->name, 571 key->type->name,
572 key->uid, 572 from_kuid_munged(current_user_ns(), key->uid),
573 key->gid, 573 from_kgid_munged(current_user_ns(), key->gid),
574 key->perm, 574 key->perm,
575 key->description ?: ""); 575 key->description ?: "");
576 576
@@ -766,15 +766,25 @@ error:
766 * 766 *
767 * If successful, 0 will be returned. 767 * If successful, 0 will be returned.
768 */ 768 */
769long keyctl_chown_key(key_serial_t id, uid_t uid, gid_t gid) 769long keyctl_chown_key(key_serial_t id, uid_t user, gid_t group)
770{ 770{
771 struct key_user *newowner, *zapowner = NULL; 771 struct key_user *newowner, *zapowner = NULL;
772 struct key *key; 772 struct key *key;
773 key_ref_t key_ref; 773 key_ref_t key_ref;
774 long ret; 774 long ret;
775 kuid_t uid;
776 kgid_t gid;
777
778 uid = make_kuid(current_user_ns(), user);
779 gid = make_kgid(current_user_ns(), group);
780 ret = -EINVAL;
781 if ((user != (uid_t) -1) && !uid_valid(uid))
782 goto error;
783 if ((group != (gid_t) -1) && !gid_valid(gid))
784 goto error;
775 785
776 ret = 0; 786 ret = 0;
777 if (uid == (uid_t) -1 && gid == (gid_t) -1) 787 if (user == (uid_t) -1 && group == (gid_t) -1)
778 goto error; 788 goto error;
779 789
780 key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL, 790 key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,
@@ -792,27 +802,27 @@ long keyctl_chown_key(key_serial_t id, uid_t uid, gid_t gid)
792 802
793 if (!capable(CAP_SYS_ADMIN)) { 803 if (!capable(CAP_SYS_ADMIN)) {
794 /* only the sysadmin can chown a key to some other UID */ 804 /* only the sysadmin can chown a key to some other UID */
795 if (uid != (uid_t) -1 && key->uid != uid) 805 if (user != (uid_t) -1 && !uid_eq(key->uid, uid))
796 goto error_put; 806 goto error_put;
797 807
798 /* only the sysadmin can set the key's GID to a group other 808 /* only the sysadmin can set the key's GID to a group other
799 * than one of those that the current process subscribes to */ 809 * than one of those that the current process subscribes to */
800 if (gid != (gid_t) -1 && gid != key->gid && !in_group_p(gid)) 810 if (group != (gid_t) -1 && !gid_eq(gid, key->gid) && !in_group_p(gid))
801 goto error_put; 811 goto error_put;
802 } 812 }
803 813
804 /* change the UID */ 814 /* change the UID */
805 if (uid != (uid_t) -1 && uid != key->uid) { 815 if (user != (uid_t) -1 && !uid_eq(uid, key->uid)) {
806 ret = -ENOMEM; 816 ret = -ENOMEM;
807 newowner = key_user_lookup(uid, current_user_ns()); 817 newowner = key_user_lookup(uid);
808 if (!newowner) 818 if (!newowner)
809 goto error_put; 819 goto error_put;
810 820
811 /* transfer the quota burden to the new user */ 821 /* transfer the quota burden to the new user */
812 if (test_bit(KEY_FLAG_IN_QUOTA, &key->flags)) { 822 if (test_bit(KEY_FLAG_IN_QUOTA, &key->flags)) {
813 unsigned maxkeys = (uid == 0) ? 823 unsigned maxkeys = uid_eq(uid, GLOBAL_ROOT_UID) ?
814 key_quota_root_maxkeys : key_quota_maxkeys; 824 key_quota_root_maxkeys : key_quota_maxkeys;
815 unsigned maxbytes = (uid == 0) ? 825 unsigned maxbytes = uid_eq(uid, GLOBAL_ROOT_UID) ?
816 key_quota_root_maxbytes : key_quota_maxbytes; 826 key_quota_root_maxbytes : key_quota_maxbytes;
817 827
818 spin_lock(&newowner->lock); 828 spin_lock(&newowner->lock);
@@ -846,7 +856,7 @@ long keyctl_chown_key(key_serial_t id, uid_t uid, gid_t gid)
846 } 856 }
847 857
848 /* change the GID */ 858 /* change the GID */
849 if (gid != (gid_t) -1) 859 if (group != (gid_t) -1)
850 key->gid = gid; 860 key->gid = gid;
851 861
852 ret = 0; 862 ret = 0;
@@ -897,7 +907,7 @@ long keyctl_setperm_key(key_serial_t id, key_perm_t perm)
897 down_write(&key->sem); 907 down_write(&key->sem);
898 908
899 /* if we're not the sysadmin, we can only change a key that we own */ 909 /* if we're not the sysadmin, we can only change a key that we own */
900 if (capable(CAP_SYS_ADMIN) || key->uid == current_fsuid()) { 910 if (capable(CAP_SYS_ADMIN) || uid_eq(key->uid, current_fsuid())) {
901 key->perm = perm; 911 key->perm = perm;
902 ret = 0; 912 ret = 0;
903 } 913 }
@@ -1506,18 +1516,18 @@ long keyctl_session_to_parent(void)
1506 1516
1507 /* the parent must have the same effective ownership and mustn't be 1517 /* the parent must have the same effective ownership and mustn't be
1508 * SUID/SGID */ 1518 * SUID/SGID */
1509 if (pcred->uid != mycred->euid || 1519 if (!uid_eq(pcred->uid, mycred->euid) ||
1510 pcred->euid != mycred->euid || 1520 !uid_eq(pcred->euid, mycred->euid) ||
1511 pcred->suid != mycred->euid || 1521 !uid_eq(pcred->suid, mycred->euid) ||
1512 pcred->gid != mycred->egid || 1522 !gid_eq(pcred->gid, mycred->egid) ||
1513 pcred->egid != mycred->egid || 1523 !gid_eq(pcred->egid, mycred->egid) ||
1514 pcred->sgid != mycred->egid) 1524 !gid_eq(pcred->sgid, mycred->egid))
1515 goto unlock; 1525 goto unlock;
1516 1526
1517 /* the keyrings must have the same UID */ 1527 /* the keyrings must have the same UID */
1518 if ((pcred->tgcred->session_keyring && 1528 if ((pcred->tgcred->session_keyring &&
1519 pcred->tgcred->session_keyring->uid != mycred->euid) || 1529 !uid_eq(pcred->tgcred->session_keyring->uid, mycred->euid)) ||
1520 mycred->tgcred->session_keyring->uid != mycred->euid) 1530 !uid_eq(mycred->tgcred->session_keyring->uid, mycred->euid))
1521 goto unlock; 1531 goto unlock;
1522 1532
1523 /* cancel an already pending keyring replacement */ 1533 /* cancel an already pending keyring replacement */