Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp31649pxb; Tue, 12 Jan 2021 19:06:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJw0y7+WphU57I/nyQbiUfDWYbFVpRQ+t3WK3KqLibaZ9Ou3iYxiJ4JxPBCkZsYEJLvgXqPV X-Received: by 2002:a17:907:28d4:: with SMTP id en20mr32037ejc.196.1610507190322; Tue, 12 Jan 2021 19:06:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610507190; cv=none; d=google.com; s=arc-20160816; b=HcBfCgAOTCn+Emn8k2fAHtiF8i86iNEomaYYJAVaBRvbSTCK7hRhufo7gOh9wwk67c UMjZYhq1AdQJI689McaAml8L+mm9AGKNu7glNM6F8/Ca+BSAWMtAxfbh+EL1Kdbdxko6 FUifWAAw+WIbxCof3z0lM6LFHAn61Lyt0GH4pJFcks4+ubbl/Cwi8Gew2BOg1s5y8djJ GqeaVBzrJnFA6WNZMjAt+PtrZnypf5QEzsyDF/Qws44ef0mh0danmnAXsfpKsLZTAQUP y53rBQ8cFrqBjDmc3DELxMJT5YZTOp3EF7yRmeG232mcvV16TGJi4oNyc6Qc1/Wtw8XN z/xg== 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=T8q1g9KO9OI8CX6PcliNLHkjTDofrHRGL+ViaHiUUxw=; b=d//ZTz+rscgmWIvP99adlYuqmlPJ9n7MCTUXGHSx7C2IIBMO7/fRB08c2ktfS8Fmni 1UoUooZtRdITI+yeaQII1eApZSAEIL1sPSZw9SEPpq98OxpllfVkETbbkT0jSNpSLJgy dcrf5sYKBJEReEJjWjw0vVvAL2/ao7yGUXkk8kmjvcN7f9HWdZGC6fzIWFJEyfHgvbr5 ksQcJUi7I73HRrOU7zNbdsUCgvdF/5HQb7uETXSC9EruAI235tF89FpcKAyATKjcsuob z1who/9QECEWBKaz4YuaTMnIQmRAxyOs/a50j8jH36NXNJwG3ZF0vkEEEp3/XC/rt6sS vlCw== 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 jz8si284983ejb.237.2021.01.12.19.06.07; Tue, 12 Jan 2021 19:06:30 -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 S2438231AbhALWQv (ORCPT + 99 others); Tue, 12 Jan 2021 17:16:51 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:44947 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438225AbhALWQr (ORCPT ); Tue, 12 Jan 2021 17:16:47 -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 1kzRln-0003bd-Qt; Tue, 12 Jan 2021 22:04:07 +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 31/42] exec: handle idmapped mounts Date: Tue, 12 Jan 2021 23:01:13 +0100 Message-Id: <20210112220124.837960-32-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=z3V1fTqinwXFXuBPT/F1/hXfgz5+RFdSDv1+bqcElO4=; m=dSmUO4lNQY/1KQIljwSUZlys/r5kqPY0ATmQGa0aOgc=; p=VslHb3N0lBAUc5siOQWy6xbVTFXnD/IAUdtdf9hX2NI=; g=12460a0074314a05345e63a213e6770ca717a756 X-Patch-Sig: m=pgp; i=christian.brauner@ubuntu.com; s=0x0x91C61BC06578DCA2; b=iHUEABYKAB0WIQRAhzRXHqcMeLMyaSiRxhvAZXjcogUCX/4YuAAKCRCRxhvAZXjcoqXaAP9jK4V c3Af5yoIa54Rl3S/RZYYPgS7UFFOz2yjdRyH/PwEA5dih9bTOIQNZdBDIQn+Chfmpxb1OyFx+xpcY mMXL4Q8= 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. 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 --- fs/exec.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 36a1b927a8ae..61ae826d5a16 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 = mnt_user_ns(file->f_path.mnt); + /* 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