Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

CRED: Wrap task credential accesses in the filesystem subsystem

Wrap access to task credentials so that they can be separated more easily from
the task_struct during the introduction of COW creds.

Change most current->(|e|s|fs)[ug]id to current_(|e|s|fs)[ug]id().

Change some task->e?[ug]id to task_e?[ug]id(). In some places it makes more
sense to use RCU directly rather than a convenient wrapper; these will be
addressed by later patches.

Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: James Morris <jmorris@namei.org>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: James Morris <jmorris@namei.org>

authored by

David Howells and committed by
James Morris
da9592ed 82ab8ded

+38 -36
+2 -2
fs/anon_inodes.c
··· 154 154 */ 155 155 inode->i_state = I_DIRTY; 156 156 inode->i_mode = S_IRUSR | S_IWUSR; 157 - inode->i_uid = current->fsuid; 158 - inode->i_gid = current->fsgid; 157 + inode->i_uid = current_fsuid(); 158 + inode->i_gid = current_fsgid(); 159 159 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; 160 160 return inode; 161 161 }
+2 -2
fs/attr.c
··· 29 29 30 30 /* Make sure a caller can chown. */ 31 31 if ((ia_valid & ATTR_UID) && 32 - (current->fsuid != inode->i_uid || 32 + (current_fsuid() != inode->i_uid || 33 33 attr->ia_uid != inode->i_uid) && !capable(CAP_CHOWN)) 34 34 goto error; 35 35 36 36 /* Make sure caller can chgrp. */ 37 37 if ((ia_valid & ATTR_GID) && 38 - (current->fsuid != inode->i_uid || 38 + (current_fsuid() != inode->i_uid || 39 39 (!in_group_p(attr->ia_gid) && attr->ia_gid != inode->i_gid)) && 40 40 !capable(CAP_CHOWN)) 41 41 goto error;
+4 -4
fs/binfmt_elf_fdpic.c
··· 623 623 NEW_AUX_ENT(AT_BASE, interp_params->elfhdr_addr); 624 624 NEW_AUX_ENT(AT_FLAGS, 0); 625 625 NEW_AUX_ENT(AT_ENTRY, exec_params->entry_addr); 626 - NEW_AUX_ENT(AT_UID, (elf_addr_t) current->uid); 627 - NEW_AUX_ENT(AT_EUID, (elf_addr_t) current->euid); 628 - NEW_AUX_ENT(AT_GID, (elf_addr_t) current->gid); 629 - NEW_AUX_ENT(AT_EGID, (elf_addr_t) current->egid); 626 + NEW_AUX_ENT(AT_UID, (elf_addr_t) current_uid()); 627 + NEW_AUX_ENT(AT_EUID, (elf_addr_t) current_euid()); 628 + NEW_AUX_ENT(AT_GID, (elf_addr_t) current_gid()); 629 + NEW_AUX_ENT(AT_EGID, (elf_addr_t) current_egid()); 630 630 NEW_AUX_ENT(AT_SECURE, security_bprm_secureexec(bprm)); 631 631 NEW_AUX_ENT(AT_EXECFN, bprm->exec); 632 632
+2 -2
fs/dquot.c
··· 874 874 875 875 switch (dquot->dq_type) { 876 876 case USRQUOTA: 877 - return current->fsuid == dquot->dq_id; 877 + return current_fsuid() == dquot->dq_id; 878 878 case GRPQUOTA: 879 879 return in_group_p(dquot->dq_id); 880 880 } ··· 981 981 MINOR(dquot->dq_sb->s_dev)); 982 982 if (ret) 983 983 goto attr_err_out; 984 - ret = nla_put_u64(skb, QUOTA_NL_A_CAUSED_ID, current->user->uid); 984 + ret = nla_put_u64(skb, QUOTA_NL_A_CAUSED_ID, current_uid()); 985 985 if (ret) 986 986 goto attr_err_out; 987 987 genlmsg_end(skb, msg_head);
+9 -9
fs/exec.c
··· 980 980 /* This is the point of no return */ 981 981 current->sas_ss_sp = current->sas_ss_size = 0; 982 982 983 - if (current->euid == current->uid && current->egid == current->gid) 983 + if (current_euid() == current_uid() && current_egid() == current_gid()) 984 984 set_dumpable(current->mm, 1); 985 985 else 986 986 set_dumpable(current->mm, suid_dumpable); ··· 1007 1007 */ 1008 1008 current->mm->task_size = TASK_SIZE; 1009 1009 1010 - if (bprm->e_uid != current->euid || bprm->e_gid != current->egid) { 1010 + if (bprm->e_uid != current_euid() || bprm->e_gid != current_egid()) { 1011 1011 suid_keys(current); 1012 1012 set_dumpable(current->mm, suid_dumpable); 1013 1013 current->pdeath_signal = 0; ··· 1047 1047 if (bprm->file->f_op == NULL) 1048 1048 return -EACCES; 1049 1049 1050 - bprm->e_uid = current->euid; 1051 - bprm->e_gid = current->egid; 1050 + bprm->e_uid = current_euid(); 1051 + bprm->e_gid = current_egid(); 1052 1052 1053 1053 if(!(bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID)) { 1054 1054 /* Set-uid? */ ··· 1096 1096 { 1097 1097 int unsafe; 1098 1098 1099 - if (bprm->e_uid != current->uid) { 1099 + if (bprm->e_uid != current_uid()) { 1100 1100 suid_keys(current); 1101 1101 current->pdeath_signal = 0; 1102 1102 } ··· 1424 1424 /* uid */ 1425 1425 case 'u': 1426 1426 rc = snprintf(out_ptr, out_end - out_ptr, 1427 - "%d", current->uid); 1427 + "%d", current_uid()); 1428 1428 if (rc > out_end - out_ptr) 1429 1429 goto out; 1430 1430 out_ptr += rc; ··· 1432 1432 /* gid */ 1433 1433 case 'g': 1434 1434 rc = snprintf(out_ptr, out_end - out_ptr, 1435 - "%d", current->gid); 1435 + "%d", current_gid()); 1436 1436 if (rc > out_end - out_ptr) 1437 1437 goto out; 1438 1438 out_ptr += rc; ··· 1709 1709 struct inode * inode; 1710 1710 struct file * file; 1711 1711 int retval = 0; 1712 - int fsuid = current->fsuid; 1712 + int fsuid = current_fsuid(); 1713 1713 int flag = 0; 1714 1714 int ispipe = 0; 1715 1715 unsigned long core_limit = current->signal->rlim[RLIMIT_CORE].rlim_cur; ··· 1815 1815 * Dont allow local users get cute and trick others to coredump 1816 1816 * into their pre-created files: 1817 1817 */ 1818 - if (inode->i_uid != current->fsuid) 1818 + if (inode->i_uid != current_fsuid()) 1819 1819 goto close_fail; 1820 1820 if (!file->f_op) 1821 1821 goto close_fail;
+1 -1
fs/fcntl.c
··· 211 211 if (err) 212 212 return err; 213 213 214 - f_modown(filp, pid, type, current->uid, current->euid, force); 214 + f_modown(filp, pid, type, current_uid(), current_euid(), force); 215 215 return 0; 216 216 } 217 217 EXPORT_SYMBOL(__f_setown);
+1 -1
fs/inotify_user.c
··· 601 601 goto out_put_fd; 602 602 } 603 603 604 - user = get_uid(current->user); 604 + user = get_current_user(); 605 605 if (unlikely(atomic_read(&user->inotify_devs) >= 606 606 inotify_max_user_instances)) { 607 607 ret = -EMFILE;
+2 -2
fs/ioprio.c
··· 32 32 int err; 33 33 struct io_context *ioc; 34 34 35 - if (task->uid != current->euid && 36 - task->uid != current->uid && !capable(CAP_SYS_NICE)) 35 + if (task->uid != current_euid() && 36 + task->uid != current_uid() && !capable(CAP_SYS_NICE)) 37 37 return -EPERM; 38 38 39 39 err = security_task_setioprio(task, ioprio);
+1 -1
fs/locks.c
··· 1349 1349 struct inode *inode = dentry->d_inode; 1350 1350 int error, rdlease_count = 0, wrlease_count = 0; 1351 1351 1352 - if ((current->fsuid != inode->i_uid) && !capable(CAP_LEASE)) 1352 + if ((current_fsuid() != inode->i_uid) && !capable(CAP_LEASE)) 1353 1353 return -EACCES; 1354 1354 if (!S_ISREG(inode->i_mode)) 1355 1355 return -EINVAL;
+6 -4
fs/namei.c
··· 186 186 187 187 mask &= MAY_READ | MAY_WRITE | MAY_EXEC; 188 188 189 - if (current->fsuid == inode->i_uid) 189 + if (current_fsuid() == inode->i_uid) 190 190 mode >>= 6; 191 191 else { 192 192 if (IS_POSIXACL(inode) && (mode & S_IRWXG) && check_acl) { ··· 441 441 if (inode->i_op && inode->i_op->permission) 442 442 return -EAGAIN; 443 443 444 - if (current->fsuid == inode->i_uid) 444 + if (current_fsuid() == inode->i_uid) 445 445 mode >>= 6; 446 446 else if (in_group_p(inode->i_gid)) 447 447 mode >>= 3; ··· 1334 1334 */ 1335 1335 static inline int check_sticky(struct inode *dir, struct inode *inode) 1336 1336 { 1337 + uid_t fsuid = current_fsuid(); 1338 + 1337 1339 if (!(dir->i_mode & S_ISVTX)) 1338 1340 return 0; 1339 - if (inode->i_uid == current->fsuid) 1341 + if (inode->i_uid == fsuid) 1340 1342 return 0; 1341 - if (dir->i_uid == current->fsuid) 1343 + if (dir->i_uid == fsuid) 1342 1344 return 0; 1343 1345 return !capable(CAP_FOWNER); 1344 1346 }
+1 -1
fs/namespace.c
··· 1176 1176 if (S_ISLNK(path->dentry->d_inode->i_mode)) 1177 1177 return -EPERM; 1178 1178 if (path->dentry->d_inode->i_mode & S_ISVTX) { 1179 - if (current->uid != path->dentry->d_inode->i_uid) 1179 + if (current_uid() != path->dentry->d_inode->i_uid) 1180 1180 return -EPERM; 1181 1181 } 1182 1182 if (inode_permission(path->dentry->d_inode, MAY_WRITE))
+2 -2
fs/pipe.c
··· 899 899 */ 900 900 inode->i_state = I_DIRTY; 901 901 inode->i_mode = S_IFIFO | S_IRUSR | S_IWUSR; 902 - inode->i_uid = current->fsuid; 903 - inode->i_gid = current->fsgid; 902 + inode->i_uid = current_fsuid(); 903 + inode->i_gid = current_fsgid(); 904 904 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; 905 905 906 906 return inode;
+2 -2
fs/posix_acl.c
··· 217 217 switch(pa->e_tag) { 218 218 case ACL_USER_OBJ: 219 219 /* (May have been checked already) */ 220 - if (inode->i_uid == current->fsuid) 220 + if (inode->i_uid == current_fsuid()) 221 221 goto check_perm; 222 222 break; 223 223 case ACL_USER: 224 - if (pa->e_id == current->fsuid) 224 + if (pa->e_id == current_fsuid()) 225 225 goto mask; 226 226 break; 227 227 case ACL_GROUP_OBJ:
+2 -2
fs/quota.c
··· 79 79 80 80 /* Check privileges */ 81 81 if (cmd == Q_GETQUOTA) { 82 - if (((type == USRQUOTA && current->euid != id) || 82 + if (((type == USRQUOTA && current_euid() != id) || 83 83 (type == GRPQUOTA && !in_egroup_p(id))) && 84 84 !capable(CAP_SYS_ADMIN)) 85 85 return -EPERM; ··· 130 130 131 131 /* Check privileges */ 132 132 if (cmd == Q_XGETQUOTA) { 133 - if (((type == XQM_USRQUOTA && current->euid != id) || 133 + if (((type == XQM_USRQUOTA && current_euid() != id) || 134 134 (type == XQM_GRPQUOTA && !in_egroup_p(id))) && 135 135 !capable(CAP_SYS_ADMIN)) 136 136 return -EPERM;
+1 -1
include/linux/fs.h
··· 1193 1193 #define has_fs_excl() atomic_read(&current->fs_excl) 1194 1194 1195 1195 #define is_owner_or_cap(inode) \ 1196 - ((current->fsuid == (inode)->i_uid) || capable(CAP_FOWNER)) 1196 + ((current_fsuid() == (inode)->i_uid) || capable(CAP_FOWNER)) 1197 1197 1198 1198 /* not quite ready to be deprecated, but... */ 1199 1199 extern void lock_super(struct super_block *);