@@ -569,8 +569,8 @@ long keyctl_describe_key(key_serial_t keyid,
569569 ret = snprintf (tmpbuf , PAGE_SIZE - 1 ,
570570 "%s;%d;%d;%08x;%s" ,
571571 key -> type -> name ,
572- key -> uid ,
573- key -> gid ,
572+ from_kuid_munged ( current_user_ns (), key -> uid ) ,
573+ from_kgid_munged ( current_user_ns (), key -> gid ) ,
574574 key -> perm ,
575575 key -> description ?: "" );
576576
@@ -766,15 +766,25 @@ long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
766766 *
767767 * If successful, 0 will be returned.
768768 */
769- long keyctl_chown_key (key_serial_t id , uid_t uid , gid_t gid )
769+ long keyctl_chown_key (key_serial_t id , uid_t user , gid_t group )
770770{
771771 struct key_user * newowner , * zapowner = NULL ;
772772 struct key * key ;
773773 key_ref_t key_ref ;
774774 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 ;
775785
776786 ret = 0 ;
777- if (uid == (uid_t ) - 1 && gid == (gid_t ) - 1 )
787+ if (user == (uid_t ) - 1 && group == (gid_t ) - 1 )
778788 goto error ;
779789
780790 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)
792802
793803 if (!capable (CAP_SYS_ADMIN )) {
794804 /* 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 ) )
796806 goto error_put ;
797807
798808 /* only the sysadmin can set the key's GID to a group other
799809 * 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 ))
801811 goto error_put ;
802812 }
803813
804814 /* change the UID */
805- if (uid != (uid_t ) - 1 && uid != key -> uid ) {
815+ if (user != (uid_t ) - 1 && ! uid_eq ( uid , key -> uid ) ) {
806816 ret = - ENOMEM ;
807- newowner = key_user_lookup (uid , current_user_ns () );
817+ newowner = key_user_lookup (uid );
808818 if (!newowner )
809819 goto error_put ;
810820
811821 /* transfer the quota burden to the new user */
812822 if (test_bit (KEY_FLAG_IN_QUOTA , & key -> flags )) {
813- unsigned maxkeys = (uid == 0 ) ?
823+ unsigned maxkeys = uid_eq (uid , GLOBAL_ROOT_UID ) ?
814824 key_quota_root_maxkeys : key_quota_maxkeys ;
815- unsigned maxbytes = (uid == 0 ) ?
825+ unsigned maxbytes = uid_eq (uid , GLOBAL_ROOT_UID ) ?
816826 key_quota_root_maxbytes : key_quota_maxbytes ;
817827
818828 spin_lock (& newowner -> lock );
@@ -846,7 +856,7 @@ long keyctl_chown_key(key_serial_t id, uid_t uid, gid_t gid)
846856 }
847857
848858 /* change the GID */
849- if (gid != (gid_t ) - 1 )
859+ if (group != (gid_t ) - 1 )
850860 key -> gid = gid ;
851861
852862 ret = 0 ;
@@ -897,7 +907,7 @@ long keyctl_setperm_key(key_serial_t id, key_perm_t perm)
897907 down_write (& key -> sem );
898908
899909 /* 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 () )) {
901911 key -> perm = perm ;
902912 ret = 0 ;
903913 }
@@ -1507,18 +1517,18 @@ long keyctl_session_to_parent(void)
15071517
15081518 /* the parent must have the same effective ownership and mustn't be
15091519 * SUID/SGID */
1510- if (pcred -> uid != mycred -> euid ||
1511- pcred -> euid != mycred -> euid ||
1512- pcred -> suid != mycred -> euid ||
1513- pcred -> gid != mycred -> egid ||
1514- pcred -> egid != mycred -> egid ||
1515- pcred -> sgid != mycred -> egid )
1520+ if (! uid_eq ( pcred -> uid , mycred -> euid ) ||
1521+ ! uid_eq ( pcred -> euid , mycred -> euid ) ||
1522+ ! uid_eq ( pcred -> suid , mycred -> euid ) ||
1523+ ! gid_eq ( pcred -> gid , mycred -> egid ) ||
1524+ ! gid_eq ( pcred -> egid , mycred -> egid ) ||
1525+ ! gid_eq ( pcred -> sgid , mycred -> egid ) )
15161526 goto unlock ;
15171527
15181528 /* the keyrings must have the same UID */
15191529 if ((pcred -> tgcred -> session_keyring &&
1520- pcred -> tgcred -> session_keyring -> uid != mycred -> euid ) ||
1521- mycred -> tgcred -> session_keyring -> uid != mycred -> euid )
1530+ ! uid_eq ( pcred -> tgcred -> session_keyring -> uid , mycred -> euid ) ) ||
1531+ ! uid_eq ( mycred -> tgcred -> session_keyring -> uid , mycred -> euid ) )
15221532 goto unlock ;
15231533
15241534 /* cancel an already pending keyring replacement */
0 commit comments