Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2384854pxb; Sun, 15 Nov 2020 02:48:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJy53ToH/KLLANp5loo8V0DCvkh5dy3Z82XD+2Jk9JBOB9gB45aBGaBs4RHaLdxL1xMoAdFh X-Received: by 2002:a17:906:1497:: with SMTP id x23mr10550312ejc.457.1605437308199; Sun, 15 Nov 2020 02:48:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605437308; cv=none; d=google.com; s=arc-20160816; b=h+vDBA7PTISWGValEAZ4GJ0D302jd4mamA8iwNOCmVyHyLdyjbZiWKqOfT9blMGzl0 v3E1p/syqwXm8x7dFFNYy76djOCRON7vhKArHGT6lSNfeDfVcxAffkLBi3NZtAqWCMZp HJtYI6uWkizK0DQye+Z3q07hsdehTdgq90PkG90BDxtHUMVVpY0JX3qCI8E1X/QGYEJO ZxBrZ5sBSP5YvOC6bC12xYHepAB7D6e/AiJpSAIIJKmuw+XVgPWFnAc4lyHefyYWK/AQ ykgJcoPjyhzX1+OgC9USlkDIL1dU3Cn9i3gMIVH6BRyZ03ssYL+rmx0yg8e996XsJdTQ On0A== 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=k5uBP5TuTyFGhH5x5FYukGLOzCQyZuQU6cafu3srCxo=; b=qTylJTf5DIOTccK3n7UYOhkxDf1ZBY53rY8kd4yrym4RGEQPRu/nK0CFm/GJAU/jIm jZv9dLjp4Z8jE6ihInyW14qAQExzwl7dkIUPbA3vRilHI571FL993eFvPMvOlt3AAy7M +TwaiZm8SSd0agG/pestHcRyt2xRU4CX5g0ptVEvuiJ9odm+SkBl+NGXgS8dLmPCwQEQ U3NBrCUB25PYeJrLTUcmb1S0RIGsNRt7x2x/ke6WuqiLDvF5cOdLr+bS/eppFSUTJxuq X+N2QBTxONTiBK6HuethN7NRPsco16afk9PpRQ2HnJa1UHT32YCwqCZK9P2ZxQres4hQ YZRw== 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 zc3si9476810ejb.158.2020.11.15.02.48.04; Sun, 15 Nov 2020 02:48:28 -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 S1727067AbgKOKr7 (ORCPT + 99 others); Sun, 15 Nov 2020 05:47:59 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:59758 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726647AbgKOKrS (ORCPT ); Sun, 15 Nov 2020 05:47:18 -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 1keFRc-0000Kt-PM; Sun, 15 Nov 2020 10:39:40 +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 , Jann Horn , Seth Forshee , =?UTF-8?q?St=C3=A9phane=20Graber?= , Aleksa Sarai , Lennart Poettering , "Eric W. Biederman" , smbarber@chromium.org, Phil Estes , Serge Hallyn , Kees Cook , Todd Kjos , Jonathan Corbet , containers@lists.linux-foundation.org, linux-security-module@vger.kernel.org, linux-api@vger.kernel.org, linux-ext4@vger.kernel.org, linux-audit@redhat.com, linux-integrity@vger.kernel.org, selinux@vger.kernel.org, Christian Brauner , Christoph Hellwig Subject: [PATCH v2 28/39] exec: handle idmapped mounts Date: Sun, 15 Nov 2020 11:37:07 +0100 Message-Id: <20201115103718.298186-29-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201115103718.298186-1-christian.brauner@ubuntu.com> References: <20201115103718.298186-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 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.On regular mounts this is a nop. Cc: Christoph Hellwig Cc: David Howells Cc: Al Viro Cc: linux-fsdevel@vger.kernel.org Signed-off-by: Christian Brauner --- /* v2 */ unchanged --- fs/exec.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 10c06fdf78a7..7d6d3dd17e84 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1567,6 +1567,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 *user_ns; struct inode *inode; unsigned int mode; kuid_t uid; @@ -1583,13 +1584,15 @@ static void bprm_fill_uid(struct linux_binprm *bprm, struct file *file) if (!(mode & (S_ISUID|S_ISGID))) return; + user_ns = 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(user_ns, inode); + gid = i_gid_into_mnt(user_ns, inode); inode_unlock(inode); /* We ignore suid/sgid if there are no mappings for them in the ns */ -- 2.29.2