Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp216967pxb; Thu, 21 Jan 2021 05:36:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJxXeeGWPPLwCrDOxA8Ts9Teh624v5ZYzFbedUUzokFqc/V91tvSoH1totU0G6C7AjA3hGYE X-Received: by 2002:a05:6402:4391:: with SMTP id o17mr11310168edc.196.1611236193991; Thu, 21 Jan 2021 05:36:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611236193; cv=none; d=google.com; s=arc-20160816; b=ZQst8Iskf4CTo7Mcq9F27BMknmirqNMX6r0N620sKonemYfx3pl2B0rSSMwFwsYSI3 wcXyqJ3LSrCRtT/egI4DHIS4EeB+NY7rayD3LDT7VgWF7cZsx6uoW4A59NY7PIbDiibF PWly2+wzTroC4fST4LurDhQZE6ysM7yX5KZu6gUIiKDQMwHo8tHQKlJ+hQmhs1UncMHE vzW6lFEd1lyRnZNbxgA7Ve50l/ZcUGNhSWy3oHy1dlZIiff+KAYY4e+DLxzz1H7KxUXo 9MYjY7p43aSOcQ1TYxGPhS/J3l2qHbcgkXbfgOvziJRfjH8wuquXzgUxAXPxjnuE+q0S m5pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jLRfA6Hdy3UYxE57E1n+KMQ8E+4B8B7lncW6HlSWNmk=; b=cHS+5ljjEPlkb33TDYRIgwBzY5nsTuC185V1RZqWEHpBLtte4NHt7Iclc77z3YX0/B bgQpCnPwTyMKoSXtSy7Nc4s+BKahsxQrkx8Qf6mVLmjomez0h9yUomBXzaDGHOMjrjGO JqCTQIdtd9rP46xr/jpf5Thh2IkjDVxSEV8PU9t+1BmdGiAS/o5Cy6PJioSsNFUr0A2J SkdRfjeI12fqRbnvDLZKg/QEtBd4vUuWVl8ff9rdZWRZqxMKR0czS8kWjwG7lk23Aakr zVjykYaOEdDxRoVraLD8lkJQOPYVxMrJx4z5pILphw6qBmFf7nR4F5ICY8naFbB5t+ZZ Ek2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v1si2151876edr.217.2021.01.21.05.36.10; Thu, 21 Jan 2021 05:36:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732432AbhAUNet (ORCPT + 99 others); Thu, 21 Jan 2021 08:34:49 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:55317 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732304AbhAUNdj (ORCPT ); Thu, 21 Jan 2021 08:33:39 -0500 Received: from ip5f5af0a0.dynamic.kabel-deutschland.de ([95.90.240.160] helo=wittgenstein.fritz.box) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1l2ZuI-0005g7-8p; Thu, 21 Jan 2021 13:21:50 +0000 From: Christian Brauner To: Alexander Viro , Christoph Hellwig , linux-fsdevel@vger.kernel.org Cc: John Johansen , James Morris , Mimi Zohar , Dmitry Kasatkin , Stephen Smalley , Casey Schaufler , Arnd Bergmann , Andreas Dilger , OGAWA Hirofumi , Geoffrey Thomas , Mrunal Patel , Josh Triplett , Andy Lutomirski , Theodore Tso , Alban Crequy , Tycho Andersen , David Howells , James Bottomley , Seth Forshee , =?UTF-8?q?St=C3=A9phane=20Graber?= , Linus Torvalds , Aleksa Sarai , Lennart Poettering , "Eric W. Biederman" , smbarber@chromium.org, Phil Estes , Serge Hallyn , Kees Cook , Todd Kjos , Paul Moore , Jonathan Corbet , containers@lists.linux-foundation.org, linux-security-module@vger.kernel.org, linux-api@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-integrity@vger.kernel.org, selinux@vger.kernel.org, Christian Brauner Subject: [PATCH v6 22/40] would_dump: handle idmapped mounts Date: Thu, 21 Jan 2021 14:19:41 +0100 Message-Id: <20210121131959.646623-23-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210121131959.646623-1-christian.brauner@ubuntu.com> References: <20210121131959.646623-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 X-Patch-Hashes: v=1; h=sha256; i=A/nf/Qaib9/w6oGQlkS9dYx6cw1KsGe6yuBPNJQbdMM=; m=5fDX5uz0YnC3GH96qex7V+5TwhlVI48wrMLhtmDIkl8=; p=QepK7fKjTZuoI1u3TlKmBwlnbcyQSzJL+R6j/ywgVPc=; g=4190fea7306895f3e77ebfd677e8257c1f573c61 X-Patch-Sig: m=pgp; i=christian.brauner@ubuntu.com; s=0x0x91C61BC06578DCA2; b=iHUEABYKAB0WIQRAhzRXHqcMeLMyaSiRxhvAZXjcogUCYAl9pQAKCRCRxhvAZXjcokbCAP9K3z3 CreUyBktYJ8SjXaIHJXRbCwIFFhlpN72GXHM7cgEA72Za1OgttnSBIi5PswjJIk6RpEFXF+qFrzcs uz9ZrAk= Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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/20210112220124.837960-31-christian.brauner@ubuntu.com Cc: Christoph Hellwig Cc: David Howells Cc: Al Viro Cc: linux-fsdevel@vger.kernel.org Reviewed-by: Christoph Hellwig Signed-off-by: Christian Brauner --- /* v2 */ unchanged /* v3 */ unchanged /* v4 */ - Serge Hallyn : - Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent. /* v5 */ unchanged base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837 - Christoph Hellwig : - Use new file_mnt_user_ns() helper. /* v6 */ unchanged base-commit: 19c329f6808995b142b3966301f217c831e7cf31 --- fs/exec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index a8ec371cd3cd..d803227805f6 100644 --- 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) { -- 2.30.0