]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
would_dump: handle idmapped mounts
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 21 Jan 2021 13:19:41 +0000 (14:19 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 24 Jan 2021 13:27:19 +0000 (14:27 +0100)
When determining whether or not to create a coredump the vfs will verify
that the caller is privileged over the inode. Make the would_dump()
helper handle idmapped mounts by passing down the mount's user namespace
of the exec file. If the initial user namespace is passed nothing
changes so non-idmapped mounts will see identical behavior as before.

Link: https://lore.kernel.org/r/20210121131959.646623-23-christian.brauner@ubuntu.com
Cc: Christoph Hellwig <hch@lst.de>
Cc: David Howells <dhowells@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
fs/exec.c

index a8ec371cd3cd1849a5c4ee45c63d93a9f067fbed..d803227805f679dec3b5148d1bfbde3e9ede0020 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1404,15 +1404,15 @@ EXPORT_SYMBOL(begin_new_exec);
 void would_dump(struct linux_binprm *bprm, struct file *file)
 {
        struct inode *inode = file_inode(file);
-       if (inode_permission(&init_user_ns, inode, MAY_READ) < 0) {
+       struct user_namespace *mnt_userns = file_mnt_user_ns(file);
+       if (inode_permission(mnt_userns, inode, MAY_READ) < 0) {
                struct user_namespace *old, *user_ns;
                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, &init_user_ns,
-                                                   inode))
+                      !privileged_wrt_inode_uidgid(user_ns, mnt_userns, inode))
                        user_ns = user_ns->parent;
 
                if (old != user_ns) {