Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp216862pxb; Thu, 21 Jan 2021 05:36:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJyXxBl4sOtfAlieqb+iOqTB4jiSmooOqeL+06eNBG6y8G47bwgg8ipGU0e2pifQ1okWlU6C X-Received: by 2002:a17:907:76a9:: with SMTP id jw9mr9909453ejc.79.1611236184021; Thu, 21 Jan 2021 05:36:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611236184; cv=none; d=google.com; s=arc-20160816; b=Pm6P2VSzi07/9vhPQw81zHJpsoP5zDI4xjNebvqQVLfvrBdqVd5vsIygh3GGPEPSsv pIfvR/RW4mLl9vj/FadoreuKzkppB27PBWXo4WPkxwyr3bB0OlfYAn1OH0n3cRLNpxgP 4SWsJloDJFolFJkEb+LURpd9utHGJR0zgNlaoQfvnAsE3FuNaOcm1YrSYSi5oHg3MXj3 YCGH3iLtliE1wB88Mx1B5hxU7OWxVe1NQQdYropn8Bz1O6MAinrPCjVRPVkaqaS3pFC5 cK8wHBD3QVGMmy8mh4bRCbWPGK81GPlkQFV7qgzwo+Xt3CL0FDJuFjYCMPPvbMgpmsiR 7ZSw== 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=CmpAFB4h9Wo46MV47ND3iFbJuPiRmSEgPHz+NC5AEfc=; b=ikThD8HxLh2nQbXQkEQdHD6eBPOT7gOfa+6uHI/MjPEipbr2k8sq1OARtf2K4bLNie zdqF3cfdQom2l8ywvEItC1+gSyXtQXpFgXWxsyYv3dk6McMjCIvpb+PLe3BRm4thQizi NJ9MkSUzBCxVK5VFTHR+ercJap8Fk2dGwvFsBWVCEJqDwe4DcgoEwG+U5e8sUUrXWZaB fKI9pFM25OuWbmJSQY3X47abnfWTofVyFYISTag0mj0s93d2RkE03mWWXD98PjG1Bq1O LuOGlXG9sJ7XID9tLng2gonpcOiszroz197K1ezjipu1kEGaw9Zg/yuw9bsvhICwenpf 7w1w== 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 c10si1741306ejs.369.2021.01.21.05.36.00; Thu, 21 Jan 2021 05:36:24 -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 S1732448AbhAUNfK (ORCPT + 99 others); Thu, 21 Jan 2021 08:35:10 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:55324 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732314AbhAUNdo (ORCPT ); Thu, 21 Jan 2021 08:33:44 -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 1l2ZuM-0005g7-Ag; Thu, 21 Jan 2021 13:21:54 +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 23/40] exec: handle idmapped mounts Date: Thu, 21 Jan 2021 14:19:42 +0100 Message-Id: <20210121131959.646623-24-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=z3V1fTqinwXFXuBPT/F1/hXfgz5+RFdSDv1+bqcElO4=; m=pa7oyqjV6cs0De7RkFUKqnoILUWsjrd+GGkDcRnF7e4=; p=e3JlF/8T1cdyjaEUPbrFI9rl6HdxUVBqTEYS22fNFZk=; g=96f8f9f670a40251c9d649d880221f3c3f943146 X-Patch-Sig: m=pgp; i=christian.brauner@ubuntu.com; s=0x0x91C61BC06578DCA2; b=iHUEABYKAB0WIQRAhzRXHqcMeLMyaSiRxhvAZXjcogUCYAl9pQAKCRCRxhvAZXjconUpAQCTIZQ 8C3ba4lje18NvrTHsReci/Ovd9qdOQRTBQ2jEdwD/YSyNacQTQKobAyIgKGa8ALgMZ7LbpDA6GlTv S/f8HQw= Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org When executing a setuid binary the kernel will verify in bprm_fill_uid() that the inode has a mapping in the caller's user namespace before setting the callers uid and gid. Let bprm_fill_uid() handle idmapped mounts. If the inode is accessed through an idmapped mount it is mapped according to the mount's user namespace. Afterwards the checks are identical to non-idmapped mounts. 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-32-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 /* v6 */ base-commit: 19c329f6808995b142b3966301f217c831e7cf31 - Christoph Hellwig : - Use new file_mnt_user_ns() helper. --- fs/exec.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index d803227805f6..48d1e8b1610b 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1580,6 +1580,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm) static void bprm_fill_uid(struct linux_binprm *bprm, struct file *file) { /* Handle suid and sgid on files */ + struct user_namespace *mnt_userns; struct inode *inode; unsigned int mode; kuid_t uid; @@ -1596,13 +1597,15 @@ static void bprm_fill_uid(struct linux_binprm *bprm, struct file *file) if (!(mode & (S_ISUID|S_ISGID))) return; + mnt_userns = file_mnt_user_ns(file); + /* Be careful if suid/sgid is set */ inode_lock(inode); /* reload atomically mode/uid/gid now that lock held */ mode = inode->i_mode; - uid = inode->i_uid; - gid = inode->i_gid; + uid = i_uid_into_mnt(mnt_userns, inode); + gid = i_gid_into_mnt(mnt_userns, inode); inode_unlock(inode); /* We ignore suid/sgid if there are no mappings for them in the ns */ -- 2.30.0