Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp30804pxb; Tue, 12 Jan 2021 19:05:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3eJLugH+SHVhm82Vp6MVDLpAbhJwZjoVppPitmYKA20pMFwul3BjBPSqgGqfBE41WidAz X-Received: by 2002:a17:906:3fc1:: with SMTP id k1mr36744ejj.58.1610507109572; Tue, 12 Jan 2021 19:05:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610507109; cv=none; d=google.com; s=arc-20160816; b=CJ2lBz++cgeBVnjfXmpVXWZiDgiikTJas8JwPnCcqQtQpYH5VvMw1P59mA1t+Msvbx UXtEcVnZyLWJaXGLQAAaFc9CZuGMAlPpvxnLl0Aa3X0S/E63TlQ5ZoUL+xOJlwMD2ElU 8SkYRPyFyFa2EphNYEAQuV4quDEojI6IwszGVKUkFQ+SeqNTacf+LBdfmCPg4/RDPaqC 5BnFwwZphqhL254rAtT3HzDEB3fGcjHkPj2NjwpXbhE33/pVY0gPnmykYCFug2V5WXdn YchbZpCZNXzhWLEFynqrXeZHmLOahyp/DIjFMFY79sIvm282uM+HM5L4mBvL6EG73E/P XosQ== 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=sHTSnnzc4xkZTuxrZdUqB75+PJEctOL1cBAOx4J+cI0=; b=h9JEkHLC+rIzJC87lZ0niFTNP+UQSLd87DvydjNzVhvAGH7zBVnxxzVm/97RwADk1o NUEK6aBZQeQ20Q/Ib4vObLcuoohwTTOi9/sx28Zkz0tcjZIGTN5xePzfA72X/GLUn6Tf BhJfdmUG1p6LN2ZXsLstPaHpqS40oWnWHw//OiG5Wo+hJkAyksc4HPLaTTHNFOH/1mIx cW7m9gPPZ1ShXE1Bn2ikTBHtQfkLFUn7urfZU/Frqfh6GxcyC6U/gmkEtkAMsKQ1oDBK N2EejZ5INePOdqDSU6jap2ukBuvJweEl8kNZKKomOCm9NEelm9wXXVXaPqPrXj6SeTHD b7Lg== 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 o22si357889edq.400.2021.01.12.19.04.46; Tue, 12 Jan 2021 19:05:09 -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 S2394500AbhALWNQ (ORCPT + 99 others); Tue, 12 Jan 2021 17:13:16 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:44400 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391516AbhALWNO (ORCPT ); Tue, 12 Jan 2021 17:13:14 -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 1kzRll-0003bd-A6; Tue, 12 Jan 2021 22:04:05 +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 , Christoph Hellwig Subject: [PATCH v5 30/42] would_dump: handle idmapped mounts Date: Tue, 12 Jan 2021 23:01:12 +0100 Message-Id: <20210112220124.837960-31-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210112220124.837960-1-christian.brauner@ubuntu.com> References: <20210112220124.837960-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 X-Patch-Hashes: v=1; h=sha256; i=A/nf/Qaib9/w6oGQlkS9dYx6cw1KsGe6yuBPNJQbdMM=; m=4hYmBTGmUweJzwkM0tcsls/aDQhSL4nXWwU9Y4FgaAw=; p=dM2EDxddYhyQIemXARbOMp6AocUi1/TUQx77AG7ubSo=; g=afdb8ac202966bf2d51cad3f6ed88f2cefefcea8 X-Patch-Sig: m=pgp; i=christian.brauner@ubuntu.com; s=0x0x91C61BC06578DCA2; b=iHMEABYKAB0WIQRAhzRXHqcMeLMyaSiRxhvAZXjcogUCX/4YuAAKCRCRxhvAZXjcohXEAQCptuP wpMnvYN0D/YoAkQguONf99A9nj40uFKgLFUuoLADwsLkciRUuOv9jL/jphrBcxCbG5EmZLQ+zkoiu i/gO 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. Cc: Christoph Hellwig Cc: David Howells Cc: Al Viro Cc: linux-fsdevel@vger.kernel.org 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 */ base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837 - Christoph Hellwig : - Use new file_userns_helper(). --- fs/exec.c | 5 +++-- fs/fcntl.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 049a8d2669db..36a1b927a8ae 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1404,14 +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_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) { diff --git a/fs/fcntl.c b/fs/fcntl.c index 58706031e603..ebbe831d5736 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -47,7 +47,7 @@ static int setfl(int fd, struct file * filp, unsigned long arg) /* O_NOATIME can only be set by the owner or superuser */ if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME)) - if (!inode_owner_or_capable(mnt_user_ns(filp->f_path.mnt), inode)) + if (!inode_owner_or_capable(file_user_ns(filp), inode)) return -EPERM; /* required for strict SunOS emulation */ -- 2.30.0