Commit 0ae18b54 authored by Seth Forshee's avatar Seth Forshee

userns: Replace in_userns with current_in_userns

All current callers of in_userns pass current_user_ns as the
first argument. Simplify by replacing in_userns with
current_in_userns which checks whether current_user_ns is in the
namespace supplied as an argument.
Signed-off-by: default avatarSeth Forshee <seth.forshee@canonical.com>
parent cab03bc4
...@@ -3286,7 +3286,7 @@ bool mnt_may_suid(struct vfsmount *mnt) ...@@ -3286,7 +3286,7 @@ bool mnt_may_suid(struct vfsmount *mnt)
* in other namespaces. * in other namespaces.
*/ */
return !(mnt->mnt_flags & MNT_NOSUID) && check_mnt(real_mount(mnt)) && return !(mnt->mnt_flags & MNT_NOSUID) && check_mnt(real_mount(mnt)) &&
in_userns(current_user_ns(), mnt->mnt_sb->s_user_ns); current_in_userns(mnt->mnt_sb->s_user_ns);
} }
static struct ns_common *mntns_get(struct task_struct *task) static struct ns_common *mntns_get(struct task_struct *task)
......
...@@ -72,8 +72,7 @@ extern ssize_t proc_projid_map_write(struct file *, const char __user *, size_t, ...@@ -72,8 +72,7 @@ extern ssize_t proc_projid_map_write(struct file *, const char __user *, size_t,
extern ssize_t proc_setgroups_write(struct file *, const char __user *, size_t, loff_t *); extern ssize_t proc_setgroups_write(struct file *, const char __user *, size_t, loff_t *);
extern int proc_setgroups_show(struct seq_file *m, void *v); extern int proc_setgroups_show(struct seq_file *m, void *v);
extern bool userns_may_setgroups(const struct user_namespace *ns); extern bool userns_may_setgroups(const struct user_namespace *ns);
extern bool in_userns(const struct user_namespace *ns, extern bool current_in_userns(const struct user_namespace *target_ns);
const struct user_namespace *target_ns);
#else #else
static inline struct user_namespace *get_user_ns(struct user_namespace *ns) static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
...@@ -103,8 +102,7 @@ static inline bool userns_may_setgroups(const struct user_namespace *ns) ...@@ -103,8 +102,7 @@ static inline bool userns_may_setgroups(const struct user_namespace *ns)
return true; return true;
} }
static inline bool in_userns(const struct user_namespace *ns, static inline bool current_in_userns(const struct user_namespace *target_ns)
const struct user_namespace *target_ns)
{ {
return true; return true;
} }
......
...@@ -949,10 +949,10 @@ bool userns_may_setgroups(const struct user_namespace *ns) ...@@ -949,10 +949,10 @@ bool userns_may_setgroups(const struct user_namespace *ns)
* Returns true if @ns is the same namespace as or a descendant of * Returns true if @ns is the same namespace as or a descendant of
* @target_ns. * @target_ns.
*/ */
bool in_userns(const struct user_namespace *ns, bool current_in_userns(const struct user_namespace *target_ns)
const struct user_namespace *target_ns)
{ {
for (; ns; ns = ns->parent) { struct user_namespace *ns;
for (ns = current_user_ns(); ns; ns = ns->parent) {
if (ns == target_ns) if (ns == target_ns)
return true; return true;
} }
......
...@@ -450,7 +450,7 @@ static int get_file_caps(struct linux_binprm *bprm, bool *effective, bool *has_c ...@@ -450,7 +450,7 @@ static int get_file_caps(struct linux_binprm *bprm, bool *effective, bool *has_c
if (!mnt_may_suid(bprm->file->f_path.mnt)) if (!mnt_may_suid(bprm->file->f_path.mnt))
return 0; return 0;
if (!in_userns(current_user_ns(), bprm->file->f_path.mnt->mnt_sb->s_user_ns)) if (!current_in_userns(bprm->file->f_path.mnt->mnt_sb->s_user_ns))
return 0; return 0;
rc = get_vfs_caps_from_disk(bprm->file->f_path.dentry, &vcaps); rc = get_vfs_caps_from_disk(bprm->file->f_path.dentry, &vcaps);
......
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