#include <linux/pipe_fs_i.h>
#include <linux/oom.h>
#include <linux/compat.h>
-#include <linux/user_namespace.h>
#include <swap/swap_us_hooks.h>
#include <asm/uaccess.h>
void would_dump(struct linux_binprm *bprm, struct file *file)
{
- struct inode *inode = file_inode(file);
- if (inode_permission(inode, MAY_READ) < 0) {
- struct user_namespace *old, *user_ns;
+ if (inode_permission(file_inode(file), MAY_READ) < 0)
bprm->interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP;
-
- /* Ensure mm->user_ns contains the executable */
- user_ns = old = bprm->mm->user_ns;
- while ((user_ns != &init_user_ns) &&
- !privileged_wrt_inode_uidgid(user_ns, inode))
- user_ns = user_ns->parent;
-
- if (old != user_ns) {
- bprm->mm->user_ns = get_user_ns(user_ns);
- put_user_ns(old);
- }
- }
}
EXPORT_SYMBOL(would_dump);
!gid_eq(bprm->cred->gid, current_egid())) {
current->pdeath_signal = 0;
} else {
+ would_dump(bprm, bprm->file);
if (bprm->interp_flags & BINPRM_FLAGS_ENFORCE_NONDUMP)
set_dumpable(current->mm, suid_dumpable);
}
if (retval < 0)
goto out;
- would_dump(bprm, bprm->file);
-
/* execve succeeded */
current->fs->in_exec = 0;
current->in_execve = 0;
struct user_namespace *ns, int cap);
extern bool capable(int cap);
extern bool ns_capable(struct user_namespace *ns, int cap);
-extern bool privileged_wrt_inode_uidgid(struct user_namespace *ns, const struct inode *inode);
extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
}
EXPORT_SYMBOL(capable);
-/**
- * privileged_wrt_inode_uidgid - Do capabilities in the namespace work over the inode?
- * @ns: The user namespace in question
- * @inode: The inode in question
- *
- * Return true if the inode uid and gid are within the namespace.
- */
-bool privileged_wrt_inode_uidgid(struct user_namespace *ns, const struct inode *inode)
-{
- return kuid_has_mapping(ns, inode->i_uid) &&
- kgid_has_mapping(ns, inode->i_gid);
-}
-
/**
* capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
* @inode: The inode in question
{
struct user_namespace *ns = current_user_ns();
- return ns_capable(ns, cap) && privileged_wrt_inode_uidgid(ns, inode);
+ return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
+ kgid_has_mapping(ns, inode->i_gid);
}
EXPORT_SYMBOL(capable_wrt_inode_uidgid);