Commit 8e96e3b7 authored by Eric W. Biederman's avatar Eric W. Biederman

userns: Use uid_eq gid_eq helpers when comparing kuids and kgids in the vfs

Acked-by: default avatarSerge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
parent 72cda3d1
...@@ -47,14 +47,14 @@ int inode_change_ok(const struct inode *inode, struct iattr *attr) ...@@ -47,14 +47,14 @@ int inode_change_ok(const struct inode *inode, struct iattr *attr)
/* Make sure a caller can chown. */ /* Make sure a caller can chown. */
if ((ia_valid & ATTR_UID) && if ((ia_valid & ATTR_UID) &&
(current_fsuid() != inode->i_uid || (!uid_eq(current_fsuid(), inode->i_uid) ||
attr->ia_uid != inode->i_uid) && !capable(CAP_CHOWN)) !uid_eq(attr->ia_uid, inode->i_uid)) && !capable(CAP_CHOWN))
return -EPERM; return -EPERM;
/* Make sure caller can chgrp. */ /* Make sure caller can chgrp. */
if ((ia_valid & ATTR_GID) && if ((ia_valid & ATTR_GID) &&
(current_fsuid() != inode->i_uid || (!uid_eq(current_fsuid(), inode->i_uid) ||
(!in_group_p(attr->ia_gid) && attr->ia_gid != inode->i_gid)) && (!in_group_p(attr->ia_gid) && !gid_eq(attr->ia_gid, inode->i_gid))) &&
!capable(CAP_CHOWN)) !capable(CAP_CHOWN))
return -EPERM; return -EPERM;
......
...@@ -1139,7 +1139,7 @@ void setup_new_exec(struct linux_binprm * bprm) ...@@ -1139,7 +1139,7 @@ void setup_new_exec(struct linux_binprm * bprm)
/* This is the point of no return */ /* This is the point of no return */
current->sas_ss_sp = current->sas_ss_size = 0; current->sas_ss_sp = current->sas_ss_size = 0;
if (current_euid() == current_uid() && current_egid() == current_gid()) if (uid_eq(current_euid(), current_uid()) && gid_eq(current_egid(), current_gid()))
set_dumpable(current->mm, 1); set_dumpable(current->mm, 1);
else else
set_dumpable(current->mm, suid_dumpable); set_dumpable(current->mm, suid_dumpable);
...@@ -1153,8 +1153,8 @@ void setup_new_exec(struct linux_binprm * bprm) ...@@ -1153,8 +1153,8 @@ void setup_new_exec(struct linux_binprm * bprm)
current->mm->task_size = TASK_SIZE; current->mm->task_size = TASK_SIZE;
/* install the new credentials */ /* install the new credentials */
if (bprm->cred->uid != current_euid() || if (!uid_eq(bprm->cred->uid, current_euid()) ||
bprm->cred->gid != current_egid()) { !gid_eq(bprm->cred->gid, current_egid())) {
current->pdeath_signal = 0; current->pdeath_signal = 0;
} else { } else {
would_dump(bprm, bprm->file); would_dump(bprm, bprm->file);
...@@ -2120,7 +2120,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs) ...@@ -2120,7 +2120,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
if (__get_dumpable(cprm.mm_flags) == 2) { if (__get_dumpable(cprm.mm_flags) == 2) {
/* Setuid core dump mode */ /* Setuid core dump mode */
flag = O_EXCL; /* Stop rewrite attacks */ flag = O_EXCL; /* Stop rewrite attacks */
cred->fsuid = 0; /* Dump root private */ cred->fsuid = GLOBAL_ROOT_UID; /* Dump root private */
} }
retval = coredump_wait(exit_code, &core_state); retval = coredump_wait(exit_code, &core_state);
...@@ -2221,7 +2221,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs) ...@@ -2221,7 +2221,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
* Dont allow local users get cute and trick others to coredump * Dont allow local users get cute and trick others to coredump
* into their pre-created files. * into their pre-created files.
*/ */
if (inode->i_uid != current_fsuid()) if (!uid_eq(inode->i_uid, current_fsuid()))
goto close_fail; goto close_fail;
if (!cprm.file->f_op || !cprm.file->f_op->write) if (!cprm.file->f_op || !cprm.file->f_op->write)
goto close_fail; goto close_fail;
......
...@@ -532,9 +532,9 @@ static inline int sigio_perm(struct task_struct *p, ...@@ -532,9 +532,9 @@ static inline int sigio_perm(struct task_struct *p,
rcu_read_lock(); rcu_read_lock();
cred = __task_cred(p); cred = __task_cred(p);
ret = ((fown->euid == 0 || ret = ((uid_eq(fown->euid, GLOBAL_ROOT_UID) ||
fown->euid == cred->suid || fown->euid == cred->uid || uid_eq(fown->euid, cred->suid) || uid_eq(fown->euid, cred->uid) ||
fown->uid == cred->suid || fown->uid == cred->uid) && uid_eq(fown->uid, cred->suid) || uid_eq(fown->uid, cred->uid)) &&
!security_file_send_sigiotask(p, fown, sig)); !security_file_send_sigiotask(p, fown, sig));
rcu_read_unlock(); rcu_read_unlock();
return ret; return ret;
......
...@@ -37,8 +37,8 @@ int set_task_ioprio(struct task_struct *task, int ioprio) ...@@ -37,8 +37,8 @@ int set_task_ioprio(struct task_struct *task, int ioprio)
rcu_read_lock(); rcu_read_lock();
tcred = __task_cred(task); tcred = __task_cred(task);
if (tcred->uid != cred->euid && if (!uid_eq(tcred->uid, cred->euid) &&
tcred->uid != cred->uid && !capable(CAP_SYS_NICE)) { !uid_eq(tcred->uid, cred->uid) && !capable(CAP_SYS_NICE)) {
rcu_read_unlock(); rcu_read_unlock();
return -EPERM; return -EPERM;
} }
......
...@@ -1445,7 +1445,7 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp) ...@@ -1445,7 +1445,7 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
int error; int error;
if ((current_fsuid() != inode->i_uid) && !capable(CAP_LEASE)) if ((!uid_eq(current_fsuid(), inode->i_uid)) && !capable(CAP_LEASE))
return -EACCES; return -EACCES;
if (!S_ISREG(inode->i_mode)) if (!S_ISREG(inode->i_mode))
return -EINVAL; return -EINVAL;
......
...@@ -228,7 +228,7 @@ static int acl_permission_check(struct inode *inode, int mask) ...@@ -228,7 +228,7 @@ static int acl_permission_check(struct inode *inode, int mask)
{ {
unsigned int mode = inode->i_mode; unsigned int mode = inode->i_mode;
if (likely(current_fsuid() == inode->i_uid)) if (likely(uid_eq(current_fsuid(), inode->i_uid)))
mode >>= 6; mode >>= 6;
else { else {
if (IS_POSIXACL(inode) && (mode & S_IRWXG)) { if (IS_POSIXACL(inode) && (mode & S_IRWXG)) {
...@@ -1956,13 +1956,13 @@ static int user_path_parent(int dfd, const char __user *path, ...@@ -1956,13 +1956,13 @@ static int user_path_parent(int dfd, const char __user *path,
*/ */
static inline int check_sticky(struct inode *dir, struct inode *inode) static inline int check_sticky(struct inode *dir, struct inode *inode)
{ {
uid_t fsuid = current_fsuid(); kuid_t fsuid = current_fsuid();
if (!(dir->i_mode & S_ISVTX)) if (!(dir->i_mode & S_ISVTX))
return 0; return 0;
if (inode->i_uid == fsuid) if (uid_eq(inode->i_uid, fsuid))
return 0; return 0;
if (dir->i_uid == fsuid) if (uid_eq(dir->i_uid, fsuid))
return 0; return 0;
return !inode_capable(inode, CAP_FOWNER); return !inode_capable(inode, CAP_FOWNER);
} }
......
...@@ -22,8 +22,8 @@ static inline struct quota_info *sb_dqopt(struct super_block *sb) ...@@ -22,8 +22,8 @@ static inline struct quota_info *sb_dqopt(struct super_block *sb)
static inline bool is_quota_modification(struct inode *inode, struct iattr *ia) static inline bool is_quota_modification(struct inode *inode, struct iattr *ia)
{ {
return (ia->ia_valid & ATTR_SIZE && ia->ia_size != inode->i_size) || return (ia->ia_valid & ATTR_SIZE && ia->ia_size != inode->i_size) ||
(ia->ia_valid & ATTR_UID && ia->ia_uid != inode->i_uid) || (ia->ia_valid & ATTR_UID && !uid_eq(ia->ia_uid, inode->i_uid)) ||
(ia->ia_valid & ATTR_GID && ia->ia_gid != inode->i_gid); (ia->ia_valid & ATTR_GID && !gid_eq(ia->ia_gid, inode->i_gid));
} }
#if defined(CONFIG_QUOTA) #if defined(CONFIG_QUOTA)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment