Skip to content

Commit

Permalink
CRED: Wrap current->cred and a few other accessors
Browse files Browse the repository at this point in the history
Wrap current->cred and a few other accessors to hide their actual
implementation.

Signed-off-by: David Howells <[email protected]>
Acked-by: James Morris <[email protected]>
Acked-by: Serge Hallyn <[email protected]>
Signed-off-by: James Morris <[email protected]>
  • Loading branch information
dhowells authored and James Morris committed Nov 13, 2008
1 parent f1752ee commit 86a264a
Show file tree
Hide file tree
Showing 27 changed files with 271 additions and 162 deletions.
7 changes: 3 additions & 4 deletions arch/ia64/ia32/sys_ia32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1767,25 +1767,24 @@ groups16_from_user(struct group_info *group_info, short __user *grouplist)
asmlinkage long
sys32_getgroups16 (int gidsetsize, short __user *grouplist)
{
const struct cred *cred = current_cred();
int i;

if (gidsetsize < 0)
return -EINVAL;

get_group_info(current->cred->group_info);
i = current->cred->group_info->ngroups;
i = cred->group_info->ngroups;
if (gidsetsize) {
if (i > gidsetsize) {
i = -EINVAL;
goto out;
}
if (groups16_to_user(grouplist, current->cred->group_info)) {
if (groups16_to_user(grouplist, cred->group_info)) {
i = -EFAULT;
goto out;
}
}
out:
put_group_info(current->cred->group_info);
return i;
}

Expand Down
8 changes: 5 additions & 3 deletions drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
struct tun_net *tn;
struct tun_struct *tun;
struct net_device *dev;
const struct cred *cred = current_cred();
int err;

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

/* Check permissions */
if (((tun->owner != -1 &&
current_euid() != tun->owner) ||
cred->euid != tun->owner) ||
(tun->group != -1 &&
current_egid() != tun->group)) &&
!capable(CAP_NET_ADMIN))
cred->egid != tun->group)) &&
!capable(CAP_NET_ADMIN)) {
return -EPERM;
}
}
else if (__dev_get_by_name(net, ifr->ifr_name))
return -EINVAL;
Expand Down
10 changes: 6 additions & 4 deletions drivers/usb/core/devio.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ static int usbdev_open(struct inode *inode, struct file *file)
{
struct usb_device *dev = NULL;
struct dev_state *ps;
const struct cred *cred = current_cred();
int ret;

lock_kernel();
Expand Down Expand Up @@ -617,8 +618,8 @@ static int usbdev_open(struct inode *inode, struct file *file)
init_waitqueue_head(&ps->wait);
ps->discsignr = 0;
ps->disc_pid = get_pid(task_pid(current));
ps->disc_uid = current_uid();
ps->disc_euid = current_euid();
ps->disc_uid = cred->uid;
ps->disc_euid = cred->euid;
ps->disccontext = NULL;
ps->ifclaimed = 0;
security_task_getsecid(current, &ps->secid);
Expand Down Expand Up @@ -967,6 +968,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
struct usb_host_endpoint *ep;
struct async *as;
struct usb_ctrlrequest *dr = NULL;
const struct cred *cred = current_cred();
unsigned int u, totlen, isofrmlen;
int ret, ifnum = -1;
int is_in;
Expand Down Expand Up @@ -1174,8 +1176,8 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
as->signr = uurb->signr;
as->ifnum = ifnum;
as->pid = get_pid(task_pid(current));
as->uid = current_uid();
as->euid = current_euid();
as->uid = cred->uid;
as->euid = cred->euid;
security_task_getsecid(current, &as->secid);
if (!is_in) {
if (copy_from_user(as->urb->transfer_buffer, uurb->buffer,
Expand Down
10 changes: 5 additions & 5 deletions fs/binfmt_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
int items;
elf_addr_t *elf_info;
int ei_index = 0;
struct task_struct *tsk = current;
const struct cred *cred = current_cred();
struct vm_area_struct *vma;

/*
Expand Down Expand Up @@ -223,10 +223,10 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
NEW_AUX_ENT(AT_BASE, interp_load_addr);
NEW_AUX_ENT(AT_FLAGS, 0);
NEW_AUX_ENT(AT_ENTRY, exec->e_entry);
NEW_AUX_ENT(AT_UID, tsk->cred->uid);
NEW_AUX_ENT(AT_EUID, tsk->cred->euid);
NEW_AUX_ENT(AT_GID, tsk->cred->gid);
NEW_AUX_ENT(AT_EGID, tsk->cred->egid);
NEW_AUX_ENT(AT_UID, cred->uid);
NEW_AUX_ENT(AT_EUID, cred->euid);
NEW_AUX_ENT(AT_GID, cred->gid);
NEW_AUX_ENT(AT_EGID, cred->egid);
NEW_AUX_ENT(AT_SECURE, security_bprm_secureexec(bprm));
NEW_AUX_ENT(AT_EXECFN, bprm->exec);
if (k_platform) {
Expand Down
9 changes: 5 additions & 4 deletions fs/binfmt_elf_fdpic.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,
struct elf_fdpic_params *exec_params,
struct elf_fdpic_params *interp_params)
{
const struct cred *cred = current_cred();
unsigned long sp, csp, nitems;
elf_caddr_t __user *argv, *envp;
size_t platform_len = 0, len;
Expand Down Expand Up @@ -623,10 +624,10 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,
NEW_AUX_ENT(AT_BASE, interp_params->elfhdr_addr);
NEW_AUX_ENT(AT_FLAGS, 0);
NEW_AUX_ENT(AT_ENTRY, exec_params->entry_addr);
NEW_AUX_ENT(AT_UID, (elf_addr_t) current->cred->uid);
NEW_AUX_ENT(AT_EUID, (elf_addr_t) current->cred->euid);
NEW_AUX_ENT(AT_GID, (elf_addr_t) current->cred->gid);
NEW_AUX_ENT(AT_EGID, (elf_addr_t) current->cred->egid);
NEW_AUX_ENT(AT_UID, (elf_addr_t) cred->uid);
NEW_AUX_ENT(AT_EUID, (elf_addr_t) cred->euid);
NEW_AUX_ENT(AT_GID, (elf_addr_t) cred->gid);
NEW_AUX_ENT(AT_EGID, (elf_addr_t) cred->egid);
NEW_AUX_ENT(AT_SECURE, security_bprm_secureexec(bprm));
NEW_AUX_ENT(AT_EXECFN, bprm->exec);

Expand Down
5 changes: 3 additions & 2 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,7 @@ EXPORT_SYMBOL(set_binfmt);
*/
static int format_corename(char *corename, long signr)
{
const struct cred *cred = current_cred();
const char *pat_ptr = core_pattern;
int ispipe = (*pat_ptr == '|');
char *out_ptr = corename;
Expand Down Expand Up @@ -1424,15 +1425,15 @@ static int format_corename(char *corename, long signr)
/* uid */
case 'u':
rc = snprintf(out_ptr, out_end - out_ptr,
"%d", current_uid());
"%d", cred->uid);
if (rc > out_end - out_ptr)
goto out;
out_ptr += rc;
break;
/* gid */
case 'g':
rc = snprintf(out_ptr, out_end - out_ptr,
"%d", current_gid());
"%d", cred->gid);
if (rc > out_end - out_ptr)
goto out;
out_ptr += rc;
Expand Down
3 changes: 2 additions & 1 deletion fs/fcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,14 @@ static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
int force)
{
const struct cred *cred = current_cred();
int err;

err = security_file_set_fowner(filp);
if (err)
return err;

f_modown(filp, pid, type, current_uid(), current_euid(), force);
f_modown(filp, pid, type, cred->uid, cred->euid, force);
return 0;
}
EXPORT_SYMBOL(__f_setown);
Expand Down
7 changes: 3 additions & 4 deletions fs/file_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int proc_nr_files(ctl_table *table, int write, struct file *filp,
*/
struct file *get_empty_filp(void)
{
struct task_struct *tsk;
const struct cred *cred = current_cred();
static int old_max;
struct file * f;

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

tsk = current;
INIT_LIST_HEAD(&f->f_u.fu_list);
atomic_long_set(&f->f_count, 1);
rwlock_init(&f->f_owner.lock);
f->f_uid = tsk->cred->fsuid;
f->f_gid = tsk->cred->fsgid;
f->f_uid = cred->fsuid;
f->f_gid = cred->fsgid;
eventpoll_init_file(f);
/* f->f_version: 0 */
return f;
Expand Down
5 changes: 3 additions & 2 deletions fs/hugetlbfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,14 +951,15 @@ struct file *hugetlb_file_setup(const char *name, size_t size)
struct inode *inode;
struct dentry *dentry, *root;
struct qstr quick_string;
struct user_struct *user = current_user();

if (!hugetlbfs_vfsmount)
return ERR_PTR(-ENOENT);

if (!can_do_hugetlb_shm())
return ERR_PTR(-EPERM);

if (!user_shm_lock(size, current->cred->user))
if (!user_shm_lock(size, user))
return ERR_PTR(-ENOMEM);

root = hugetlbfs_vfsmount->mnt_root;
Expand Down Expand Up @@ -998,7 +999,7 @@ struct file *hugetlb_file_setup(const char *name, size_t size)
out_dentry:
dput(dentry);
out_shm_unlock:
user_shm_unlock(size, current->cred->user);
user_shm_unlock(size, user);
return ERR_PTR(error);
}

Expand Down
4 changes: 2 additions & 2 deletions fs/ioprio.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ asmlinkage long sys_ioprio_set(int which, int who, int ioprio)
break;
case IOPRIO_WHO_USER:
if (!who)
user = current->cred->user;
user = current_user();
else
user = find_user(who);

Expand Down Expand Up @@ -216,7 +216,7 @@ asmlinkage long sys_ioprio_get(int which, int who)
break;
case IOPRIO_WHO_USER:
if (!who)
user = current->cred->user;
user = current_user();
else
user = find_user(who);

Expand Down
3 changes: 1 addition & 2 deletions fs/smbfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,7 @@ smb_make_node(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)

attr.ia_valid = ATTR_MODE | ATTR_UID | ATTR_GID;
attr.ia_mode = mode;
attr.ia_uid = current_euid();
attr.ia_gid = current_egid();
current_euid_egid(&attr.ia_uid, &attr.ia_gid);

if (!new_valid_dev(dev))
return -EINVAL;
Expand Down
Loading

0 comments on commit 86a264a

Please sign in to comment.