Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp31768pxb; Tue, 12 Jan 2021 19:06:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4VEbHkNtjDlY62UuzR7PWfqSK+b6bwVTKpjhqoIXALz0pfJGdEJmZASq8NkvfH+7sBlp9 X-Received: by 2002:a17:907:389:: with SMTP id ss9mr33726ejb.158.1610507200959; Tue, 12 Jan 2021 19:06:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610507200; cv=none; d=google.com; s=arc-20160816; b=b21V4vlL2WipsH9taXcS9G5HEax6y2AAD5ZrVMfk371rv3kVpjrPNcH6RuqgvLJp84 7dCuPhX+KuoOsfKgUEARy4XIrkakSynoPyKE7eP4A6JIZwuC6/igTUn3wU/cPhgOzpFq +pmY8VrRcKF3qtcaHJCfJcT1mPV6MzwvOlv1zxaUVdq+jvMQoS09WEutHWzDmsrymJLE YG5k1i7r+XP1vPejOyDXco9/FutbrUIaghyCuLxQK3iBJ049g+qc0AT/tzwljMysI3S7 vG7hPIVrcgKwCQuddYlL9unaqZV8xZ2ZpUPxcaBooYDe4XW1Ixexy2WVuIJWWoWXR2NK sAXA== 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=6gCBqnI74k8KJ1NOL0RHTA3Oq1f/KWx4I8mI0iWgrBI=; b=obqxKROMrVujg0np0cF27ErdqPv/uLedSGB/o5SadbMs3502oMgZNpZcPkf1+v9qls L6EHlIw9PBn9C21gqPyQ1KGG62Jl/RtaiVrktucfG+FXSAz4idGlQzhU6iByaZGkKWlg VZWU4PlPgQqfeOwCTI5rM3aXshiW8S31VqEpyqgnixYRPaPEuoBq9neUsLlaTQRaCDfJ RJ2R4ON2y3cVVSy3OkhCq39U3zdAP1Ug7R49nAPBdD5eiV7dNrAT7g/8xL7BmE2/s93z C3GUMu449j3Lpvk2XrItoErAfv/k+KerCL0dFGmpPHTXZx0xYiaIhbav5/OiphiNBYJw 22lQ== 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 g10si358079edy.201.2021.01.12.19.06.16; Tue, 12 Jan 2021 19:06:40 -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 S2438180AbhALWP7 (ORCPT + 99 others); Tue, 12 Jan 2021 17:15:59 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:44793 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438174AbhALWP5 (ORCPT ); Tue, 12 Jan 2021 17:15:57 -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 1kzRli-0003bd-Qe; Tue, 12 Jan 2021 22:04:02 +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 29/42] ioctl: handle idmapped mounts Date: Tue, 12 Jan 2021 23:01:11 +0100 Message-Id: <20210112220124.837960-30-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=kAwitCaU5Zsp+82CuxVVPm6U8xXlPPtQ0Z0Dh6WXu44=; m=VC5Xd0Zl8AGaO0BlP8YtVNixey9scChiBadwiGTSB5k=; p=oTgP29ybjPTdbnArRS0UjBd62m6f1UrtDPAozi+SHu8=; g=c32d9c1a69a581553f7de28602c01b53e63879e6 X-Patch-Sig: m=pgp; i=christian.brauner@ubuntu.com; s=0x0x91C61BC06578DCA2; b=iHUEABYKAB0WIQRAhzRXHqcMeLMyaSiRxhvAZXjcogUCX/4YuAAKCRCRxhvAZXjcolFtAP9Jyut NCwljnX8YPYbEbH0TGh2ZGqdwFl7dwrXEioMjsgEAxXesyAYTyhhGHAHOKEZri1frriOo39vmk6H9 U/Lv1wg= Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Enable generic ioctls to handle idmapped mounts by passing down the mount's user namespace. 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 */ patch introduced /* 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/remap_range.c | 7 +++++-- fs/verity/enable.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/remap_range.c b/fs/remap_range.c index 29a4a4dbfe12..dc68394ec9a1 100644 --- a/fs/remap_range.c +++ b/fs/remap_range.c @@ -432,13 +432,16 @@ EXPORT_SYMBOL(vfs_clone_file_range); /* Check whether we are allowed to dedupe the destination file */ static bool allow_file_dedupe(struct file *file) { + struct user_namespace *mnt_userns = file_user_ns(file); + struct inode *inode = file_inode(file); + if (capable(CAP_SYS_ADMIN)) return true; if (file->f_mode & FMODE_WRITE) return true; - if (uid_eq(current_fsuid(), file_inode(file)->i_uid)) + if (uid_eq(current_fsuid(), i_uid_into_mnt(mnt_userns, inode))) return true; - if (!inode_permission(&init_user_ns, file_inode(file), MAY_WRITE)) + if (!inode_permission(mnt_userns, inode, MAY_WRITE)) return true; return false; } diff --git a/fs/verity/enable.c b/fs/verity/enable.c index 6809cf8a99b7..9a221e368fa6 100644 --- a/fs/verity/enable.c +++ b/fs/verity/enable.c @@ -369,7 +369,7 @@ int fsverity_ioctl_enable(struct file *filp, const void __user *uarg) * has verity enabled, and to stabilize the data being hashed. */ - err = inode_permission(&init_user_ns, inode, MAY_WRITE); + err = inode_permission(file_user_ns(filp), inode, MAY_WRITE); if (err) return err; -- 2.30.0