Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp274473pxb; Thu, 21 Jan 2021 06:54:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzd+nIvMtSi+U9Hhhkwu8x9Z1LiEEYo/cMY9YC5H7EsYh77S1sgx+We9YqoWNu/3X8wpEh5 X-Received: by 2002:a17:906:49c2:: with SMTP id w2mr9051236ejv.12.1611240846796; Thu, 21 Jan 2021 06:54:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611240846; cv=none; d=google.com; s=arc-20160816; b=Dq4APTrZHIFNkdrLp/Hdeutc1R7QSTmYDtSvZFtyxAggytU/wpoZYH9aE/8iuaiHum pp2qPPhqtPFpyWdnEULDV9bPqPAXBNLG0G+79f/mNmeSU7m93MJrnsDljynDn6ir+oMf XkJE8vRX3ANTD7ZvbNwHG2YYlFYV5XrmY/ltNa5vcwK2ODkbujNCigWVY2oY8CAvljAP EyMgHkCarEZoIVFO8xUgZz7NiJ0ZMGd7YJhLfoS7l6eUmMEIR37Ai3iJ/teqQEOUVIL3 GqntTcUwn5Y94or0zpsCXeFV4Ee6Q5Yz86g06fwP0Iz6GgBAACFQo5s4MWBYIMNcN58g RjlA== 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=5QG/mzmxDVnN2+vEu9+SSleGr2cVSpUh46GnZDU0BFQ=; b=Bg0VsxXHK05LdxpimwCtRPh958nV5SalxFKbF/y2IhVZR8yiKdAKmLwcm4vU95ixvv wyJ6hLkLluGNyRPLYkzm4p+KkZPTXauqqYsY7BuAEqyu+7Ttck8h7opucE9dPGMr8LNx kDmqiEEtDq/XSiEOz14sm09G91yJbpcGMdPeQJOYmjd3zXM21+OMeGHC2/HPWQ4MOCbe SMLNpAcLqMtdhweGQEAIdlS92ImLpylNy49oDkxtbIiif+bFmqm8T2LgOeZ6eeLk8rv8 UF5wRipftUBYHJMtPUb503VF/xDXTX0TJMnRjlBRqS/tp7U6c1Sw7f9iLC6At14Tqu9m jbbw== 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 e4si2287846edk.306.2021.01.21.06.53.43; Thu, 21 Jan 2021 06:54:06 -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 S1731265AbhAUOvY (ORCPT + 99 others); Thu, 21 Jan 2021 09:51:24 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:55443 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732415AbhAUNen (ORCPT ); Thu, 21 Jan 2021 08:34:43 -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 1l2ZuE-0005g7-1n; Thu, 21 Jan 2021 13:21:46 +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 21/40] ioctl: handle idmapped mounts Date: Thu, 21 Jan 2021 14:19:40 +0100 Message-Id: <20210121131959.646623-22-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=kAwitCaU5Zsp+82CuxVVPm6U8xXlPPtQ0Z0Dh6WXu44=; m=UpfceT5PbXKo01hKHANNfX4pv3prk2UbtbeKFcGNyNE=; p=y//6XjR+zTD631rX6/gWz3LAiLcFvTajhF27PIxpIdA=; g=5e16b077c672ef24b7f183b0ccacbaa0635cf469 X-Patch-Sig: m=pgp; i=christian.brauner@ubuntu.com; s=0x0x91C61BC06578DCA2; b=iHUEABYKAB0WIQRAhzRXHqcMeLMyaSiRxhvAZXjcogUCYAl9pQAKCRCRxhvAZXjcoiCtAP4zbuF Pr97jUAmAEgwFyFaqCOgEAAlveG4nc9eQ6WkxKwEAm9NBL+olb3bocl29AH+ZFzzGApRcmiIIQ2hh +n1ZcQQ= 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. Link: https://lore.kernel.org/r/20210112220124.837960-30-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 */ patch introduced /* 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 */ base-commit: 19c329f6808995b142b3966301f217c831e7cf31 - Christoph Hellwig : - Make use of file_permission() helper. --- fs/remap_range.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/remap_range.c b/fs/remap_range.c index 29a4a4dbfe12..e4a5fdd7ad7b 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_mnt_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; } -- 2.30.0