Skip to content

Commit 86a264a

Browse files
dhowellsxjamesmorris
authored andcommitted
CRED: Wrap current->cred and a few other accessors
Wrap current->cred and a few other accessors to hide their actual implementation. Signed-off-by: David Howells <dhowells@redhat.com> Acked-by: James Morris <jmorris@namei.org> Acked-by: Serge Hallyn <serue@us.ibm.com> Signed-off-by: James Morris <jmorris@namei.org>
1 parent f1752ee commit 86a264a

27 files changed

Lines changed: 271 additions & 162 deletions

File tree

‎arch/ia64/ia32/sys_ia32.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,25 +1767,24 @@ groups16_from_user(struct group_info *group_info, short __user *grouplist)
17671767
asmlinkage long
17681768
sys32_getgroups16 (int gidsetsize, short __user *grouplist)
17691769
{
1770+
const struct cred *cred = current_cred();
17701771
int i;
17711772

17721773
if (gidsetsize < 0)
17731774
return -EINVAL;
17741775

1775-
get_group_info(current->cred->group_info);
1776-
i = current->cred->group_info->ngroups;
1776+
i = cred->group_info->ngroups;
17771777
if (gidsetsize) {
17781778
if (i > gidsetsize) {
17791779
i = -EINVAL;
17801780
goto out;
17811781
}
1782-
if (groups16_to_user(grouplist, current->cred->group_info)) {
1782+
if (groups16_to_user(grouplist, cred->group_info)) {
17831783
i = -EFAULT;
17841784
goto out;
17851785
}
17861786
}
17871787
out:
1788-
put_group_info(current->cred->group_info);
17891788
return i;
17901789
}
17911790

‎drivers/net/tun.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
702702
struct tun_net *tn;
703703
struct tun_struct *tun;
704704
struct net_device *dev;
705+
const struct cred *cred = current_cred();
705706
int err;
706707

707708
tn = net_generic(net, tun_net_id);
@@ -712,11 +713,12 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
712713

713714
/* Check permissions */
714715
if (((tun->owner != -1 &&
715-
current_euid() != tun->owner) ||
716+
cred->euid != tun->owner) ||
716717
(tun->group != -1 &&
717-
current_egid() != tun->group)) &&
718-
!capable(CAP_NET_ADMIN))
718+
cred->egid != tun->group)) &&
719+
!capable(CAP_NET_ADMIN)) {
719720
return -EPERM;
721+
}
720722
}
721723
else if (__dev_get_by_name(net, ifr->ifr_name))
722724
return -EINVAL;

‎drivers/usb/core/devio.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ static int usbdev_open(struct inode *inode, struct file *file)
574574
{
575575
struct usb_device *dev = NULL;
576576
struct dev_state *ps;
577+
const struct cred *cred = current_cred();
577578
int ret;
578579

579580
lock_kernel();
@@ -617,8 +618,8 @@ static int usbdev_open(struct inode *inode, struct file *file)
617618
init_waitqueue_head(&ps->wait);
618619
ps->discsignr = 0;
619620
ps->disc_pid = get_pid(task_pid(current));
620-
ps->disc_uid = current_uid();
621-
ps->disc_euid = current_euid();
621+
ps->disc_uid = cred->uid;
622+
ps->disc_euid = cred->euid;
622623
ps->disccontext = NULL;
623624
ps->ifclaimed = 0;
624625
security_task_getsecid(current, &ps->secid);
@@ -967,6 +968,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
967968
struct usb_host_endpoint *ep;
968969
struct async *as;
969970
struct usb_ctrlrequest *dr = NULL;
971+
const struct cred *cred = current_cred();
970972
unsigned int u, totlen, isofrmlen;
971973
int ret, ifnum = -1;
972974
int is_in;
@@ -1174,8 +1176,8 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
11741176
as->signr = uurb->signr;
11751177
as->ifnum = ifnum;
11761178
as->pid = get_pid(task_pid(current));
1177-
as->uid = current_uid();
1178-
as->euid = current_euid();
1179+
as->uid = cred->uid;
1180+
as->euid = cred->euid;
11791181
security_task_getsecid(current, &as->secid);
11801182
if (!is_in) {
11811183
if (copy_from_user(as->urb->transfer_buffer, uurb->buffer,

‎fs/binfmt_elf.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
157157
int items;
158158
elf_addr_t *elf_info;
159159
int ei_index = 0;
160-
struct task_struct *tsk = current;
160+
const struct cred *cred = current_cred();
161161
struct vm_area_struct *vma;
162162

163163
/*
@@ -223,10 +223,10 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
223223
NEW_AUX_ENT(AT_BASE, interp_load_addr);
224224
NEW_AUX_ENT(AT_FLAGS, 0);
225225
NEW_AUX_ENT(AT_ENTRY, exec->e_entry);
226-
NEW_AUX_ENT(AT_UID, tsk->cred->uid);
227-
NEW_AUX_ENT(AT_EUID, tsk->cred->euid);
228-
NEW_AUX_ENT(AT_GID, tsk->cred->gid);
229-
NEW_AUX_ENT(AT_EGID, tsk->cred->egid);
226+
NEW_AUX_ENT(AT_UID, cred->uid);
227+
NEW_AUX_ENT(AT_EUID, cred->euid);
228+
NEW_AUX_ENT(AT_GID, cred->gid);
229+
NEW_AUX_ENT(AT_EGID, cred->egid);
230230
NEW_AUX_ENT(AT_SECURE, security_bprm_secureexec(bprm));
231231
NEW_AUX_ENT(AT_EXECFN, bprm->exec);
232232
if (k_platform) {

‎fs/binfmt_elf_fdpic.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,
475475
struct elf_fdpic_params *exec_params,
476476
struct elf_fdpic_params *interp_params)
477477
{
478+
const struct cred *cred = current_cred();
478479
unsigned long sp, csp, nitems;
479480
elf_caddr_t __user *argv, *envp;
480481
size_t platform_len = 0, len;
@@ -623,10 +624,10 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,
623624
NEW_AUX_ENT(AT_BASE, interp_params->elfhdr_addr);
624625
NEW_AUX_ENT(AT_FLAGS, 0);
625626
NEW_AUX_ENT(AT_ENTRY, exec_params->entry_addr);
626-
NEW_AUX_ENT(AT_UID, (elf_addr_t) current->cred->uid);
627-
NEW_AUX_ENT(AT_EUID, (elf_addr_t) current->cred->euid);
628-
NEW_AUX_ENT(AT_GID, (elf_addr_t) current->cred->gid);
629-
NEW_AUX_ENT(AT_EGID, (elf_addr_t) current->cred->egid);
627+
NEW_AUX_ENT(AT_UID, (elf_addr_t) cred->uid);
628+
NEW_AUX_ENT(AT_EUID, (elf_addr_t) cred->euid);
629+
NEW_AUX_ENT(AT_GID, (elf_addr_t) cred->gid);
630+
NEW_AUX_ENT(AT_EGID, (elf_addr_t) cred->egid);
630631
NEW_AUX_ENT(AT_SECURE, security_bprm_secureexec(bprm));
631632
NEW_AUX_ENT(AT_EXECFN, bprm->exec);
632633

‎fs/exec.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,7 @@ EXPORT_SYMBOL(set_binfmt);
13881388
*/
13891389
static int format_corename(char *corename, long signr)
13901390
{
1391+
const struct cred *cred = current_cred();
13911392
const char *pat_ptr = core_pattern;
13921393
int ispipe = (*pat_ptr == '|');
13931394
char *out_ptr = corename;
@@ -1424,15 +1425,15 @@ static int format_corename(char *corename, long signr)
14241425
/* uid */
14251426
case 'u':
14261427
rc = snprintf(out_ptr, out_end - out_ptr,
1427-
"%d", current_uid());
1428+
"%d", cred->uid);
14281429
if (rc > out_end - out_ptr)
14291430
goto out;
14301431
out_ptr += rc;
14311432
break;
14321433
/* gid */
14331434
case 'g':
14341435
rc = snprintf(out_ptr, out_end - out_ptr,
1435-
"%d", current_gid());
1436+
"%d", cred->gid);
14361437
if (rc > out_end - out_ptr)
14371438
goto out;
14381439
out_ptr += rc;

‎fs/fcntl.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,14 @@ static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
205205
int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
206206
int force)
207207
{
208+
const struct cred *cred = current_cred();
208209
int err;
209210

210211
err = security_file_set_fowner(filp);
211212
if (err)
212213
return err;
213214

214-
f_modown(filp, pid, type, current_uid(), current_euid(), force);
215+
f_modown(filp, pid, type, cred->uid, cred->euid, force);
215216
return 0;
216217
}
217218
EXPORT_SYMBOL(__f_setown);

‎fs/file_table.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int proc_nr_files(ctl_table *table, int write, struct file *filp,
9494
*/
9595
struct file *get_empty_filp(void)
9696
{
97-
struct task_struct *tsk;
97+
const struct cred *cred = current_cred();
9898
static int old_max;
9999
struct file * f;
100100

@@ -118,12 +118,11 @@ struct file *get_empty_filp(void)
118118
if (security_file_alloc(f))
119119
goto fail_sec;
120120

121-
tsk = current;
122121
INIT_LIST_HEAD(&f->f_u.fu_list);
123122
atomic_long_set(&f->f_count, 1);
124123
rwlock_init(&f->f_owner.lock);
125-
f->f_uid = tsk->cred->fsuid;
126-
f->f_gid = tsk->cred->fsgid;
124+
f->f_uid = cred->fsuid;
125+
f->f_gid = cred->fsgid;
127126
eventpoll_init_file(f);
128127
/* f->f_version: 0 */
129128
return f;

‎fs/hugetlbfs/inode.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,14 +951,15 @@ struct file *hugetlb_file_setup(const char *name, size_t size)
951951
struct inode *inode;
952952
struct dentry *dentry, *root;
953953
struct qstr quick_string;
954+
struct user_struct *user = current_user();
954955

955956
if (!hugetlbfs_vfsmount)
956957
return ERR_PTR(-ENOENT);
957958

958959
if (!can_do_hugetlb_shm())
959960
return ERR_PTR(-EPERM);
960961

961-
if (!user_shm_lock(size, current->cred->user))
962+
if (!user_shm_lock(size, user))
962963
return ERR_PTR(-ENOMEM);
963964

964965
root = hugetlbfs_vfsmount->mnt_root;
@@ -998,7 +999,7 @@ struct file *hugetlb_file_setup(const char *name, size_t size)
998999
out_dentry:
9991000
dput(dentry);
10001001
out_shm_unlock:
1001-
user_shm_unlock(size, current->cred->user);
1002+
user_shm_unlock(size, user);
10021003
return ERR_PTR(error);
10031004
}
10041005

‎fs/ioprio.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ asmlinkage long sys_ioprio_set(int which, int who, int ioprio)
123123
break;
124124
case IOPRIO_WHO_USER:
125125
if (!who)
126-
user = current->cred->user;
126+
user = current_user();
127127
else
128128
user = find_user(who);
129129

@@ -216,7 +216,7 @@ asmlinkage long sys_ioprio_get(int which, int who)
216216
break;
217217
case IOPRIO_WHO_USER:
218218
if (!who)
219-
user = current->cred->user;
219+
user = current_user();
220220
else
221221
user = find_user(who);
222222

0 commit comments

Comments
 (0)