Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3173452pxb; Mon, 25 Jan 2021 08:47:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBx0mjhBeNfePz3Mq69xWjP05sI/09Iri2m7jBLImr/jLEbvStB4niywywSAJyyVW2Q9vm X-Received: by 2002:a17:906:d62:: with SMTP id s2mr958238ejh.61.1611593240075; Mon, 25 Jan 2021 08:47:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611593240; cv=none; d=google.com; s=arc-20160816; b=LiXYzl7+fxSoAngN10RE4DMrcWoSeySUaM4TK2nq8Zk7Pv4hHhc0RxKhWKqr3Rrecw cpajlVo7bOmg2puVYiPcEfdn6jiT/T6geOylzDDfjcRcc3wAn+yuZeainkknpZ+1+oj1 MgkEEt6jZbTYJmZRKBFqjH+Qp0DnzXlNG31X+8FM/b+qxmjT+02iMlL20FdYuYivRoEf tV0dq51SfGKf42zpCRSxw1FJ38Xu2vRbFwz7SpSmo5gUllZx6dmB+fl3/Lr6OvIfy8fF 2ybuxwFa5UZ1uADzlzt9CASycEcARXPb3uecU/Qy1GN3FGu+ugFsu18NE4acV/iPvOs9 UW+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:mime-version:user-agent:message-id :in-reply-to:date:references:cc:to:from; bh=DoG+FO+0AsYCPFhxNCZWP6cpGGnAgsB2XB2IC63rvU0=; b=wBtJLZi8VUkLYF8Xn8Se3Dl7IAHkquQAx0/bYMCC0YmNpCMDK/WL0CQZ9+9XAy0i6U iLFDCs7W4ew7ELnjtOHTtsNCyJdMIrnPtDklw3/LQFKvMKy+6ZHdIBWGA/mw/oDOqQvZ PeDNAV17+oGubNddw+uak+r02gVPELVDdiOkbVioCTORvlprnB7tJTclq978P+QbX0G+ ETpCQL269bz9E4d0214lncsssPKuQZ4MlmPvWEBq1LYMngDTtOu/1lLOGHmGBjjtWj0C F2OGBgXWQhw32TC3TtsZxYMb760tXGhg5iSDOQcEeR1TUw1Vjq2T9gw1oTcury6DAd0j RMmQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k3si2894350ejs.609.2021.01.25.08.46.47; Mon, 25 Jan 2021 08:47:20 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730839AbhAYQlj (ORCPT + 99 others); Mon, 25 Jan 2021 11:41:39 -0500 Received: from out03.mta.xmission.com ([166.70.13.233]:55430 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730830AbhAYQld (ORCPT ); Mon, 25 Jan 2021 11:41:33 -0500 Received: from in02.mta.xmission.com ([166.70.13.52]) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1l44ua-000JK6-HB; Mon, 25 Jan 2021 09:40:20 -0700 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=x220.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1l44uY-005na2-OS; Mon, 25 Jan 2021 09:40:20 -0700 From: ebiederm@xmission.com (Eric W. Biederman) To: Christian Brauner Cc: Alexander Viro , Christoph Hellwig , linux-fsdevel@vger.kernel.org, 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?= Graber , Linus Torvalds , Aleksa Sarai , Lennart Poettering , 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 References: <20210121131959.646623-1-christian.brauner@ubuntu.com> <20210121131959.646623-24-christian.brauner@ubuntu.com> Date: Mon, 25 Jan 2021 10:39:01 -0600 In-Reply-To: <20210121131959.646623-24-christian.brauner@ubuntu.com> (Christian Brauner's message of "Thu, 21 Jan 2021 14:19:42 +0100") Message-ID: <875z3l0y56.fsf@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1l44uY-005na2-OS;;;mid=<875z3l0y56.fsf@x220.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1/xzi6ZD1Y1LahVVXJQCa6ijNXolO+AIc8= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on sa07.xmission.com X-Spam-Level: ** X-Spam-Status: No, score=2.2 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,LotsOfNums_01,T_TM2_M_HEADER_IN_MSG, XM_Multi_Part_URI autolearn=disabled version=3.4.2 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * 1.2 LotsOfNums_01 BODY: Lots of long strings of numbers * 1.2 XM_Multi_Part_URI URI: Long-Multi-Part URIs * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Christian Brauner X-Spam-Relay-Country: X-Spam-Timing: total 1103 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 11 (1.0%), b_tie_ro: 9 (0.8%), parse: 1.03 (0.1%), extract_message_metadata: 24 (2.2%), get_uri_detail_list: 2.3 (0.2%), tests_pri_-1000: 13 (1.2%), tests_pri_-950: 1.30 (0.1%), tests_pri_-900: 1.09 (0.1%), tests_pri_-90: 76 (6.9%), check_bayes: 74 (6.7%), b_tokenize: 15 (1.3%), b_tok_get_all: 11 (1.0%), b_comp_prob: 3.0 (0.3%), b_tok_touch_all: 42 (3.8%), b_finish: 0.85 (0.1%), tests_pri_0: 662 (60.0%), check_dkim_signature: 0.57 (0.1%), check_dkim_adsp: 19 (1.8%), poll_dns_idle: 292 (26.4%), tests_pri_10: 2.0 (0.2%), tests_pri_500: 308 (27.9%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH v6 23/40] exec: handle idmapped mounts X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Christian Brauner writes: > 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. This does not handle the v3 capabilites xattr with embeds a uid. So at least at that level you are missing some critical conversions. Eric > 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 */