Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1600160pxu; Tue, 24 Nov 2020 04:36:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJwyaF9/zJ6bRNd2j15SJdszFAr5DR9pshiO8MOYKRM9uGvRdBMD2AzPTMdJ/uI5pvef7voc X-Received: by 2002:a50:ab07:: with SMTP id s7mr3634674edc.374.1606221410630; Tue, 24 Nov 2020 04:36:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606221410; cv=none; d=google.com; s=arc-20160816; b=Yv+8IGMbam7zd7NWbMm/+YI7Dn7gpnGptmwch4xx3hVi4nuNntUb0ePdkl6QHBrbh0 1jy/gZa1XX6Jbxl+Vvb3Gw6KBNKxp+gPL/u4j0b2EQ/ADAsCLwvCXGoweoiTnqaI+re6 TGm1FvAD7ajD73bd6dGsUhlthEzaGPQDnDJqoltNNeHPHmdaqUcVBQWMkdqAngu+bnLS kReKSqFni0nh4Cik6ugqh2RVl6Gimqrh+4YL8fkzAqpoAcD2CqGs00a7aA8n5uzLSUen JOCS/6+l74YM193cP23R+y0v8HMZ2mZ2F9BhhJHTfll0NY3TRBLj2j7MBulzawMBkkTO jyDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=Xo0DAwV27dVW9xVcvuA/k6pGREl5jmq09PLeC4dWIHk=; b=MdI3AmFXj+qmdc+2x6ZGeZz9n1Eys5Uzvvql/qdo8h33kM+Zfr8HrExQEW92qqiAcl fbKizTbPGKADm+OmXH4mvvHTsBFHlsXT6AAP396a8TcPIV24irEI/hkuZNM3kNVQltlw VeEf+32X0AnMCMLQ/TJnH1byM/HbAGd8jMMdRvqkyvohvIAOYChuXyYO0iFaJmkbwJgq R9OFwc3ZkwEI9+MC8fzxogRih9S7L6kpHzjGXWgYdYpGxOC0rW0P8WFkDJ07wWkonirJ fy8QjFsFuKu1gjSXkBiOrXrmnpiMFXwsudul+kyjXblMe1P0uMT+YwmvkzrJDm4VQ0sy whJQ== 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 g19si8673221edy.65.2020.11.24.04.36.22; Tue, 24 Nov 2020 04:36:50 -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 S1733164AbgKXMav (ORCPT + 99 others); Tue, 24 Nov 2020 07:30:51 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:52354 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733011AbgKXMau (ORCPT ); Tue, 24 Nov 2020 07:30:50 -0500 Received: from ip5f5af0a0.dynamic.kabel-deutschland.de ([95.90.240.160] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1khXSv-0004ea-Op; Tue, 24 Nov 2020 12:30:37 +0000 Date: Tue, 24 Nov 2020 13:30:35 +0100 From: Christian Brauner To: Tycho Andersen Cc: Andy Lutomirski , Mimi Zohar , James Bottomley , Andreas Dilger , Christoph Hellwig , Jonathan Corbet , smbarber@chromium.org, Christoph Hellwig , Casey Schaufler , linux-ext4@vger.kernel.org, Mrunal Patel , Kees Cook , Arnd Bergmann , Jann Horn , selinux@vger.kernel.org, Josh Triplett , Seth Forshee , Aleksa Sarai , Alexander Viro , Lennart Poettering , OGAWA Hirofumi , Geoffrey Thomas , David Howells , John Johansen , Theodore Tso , Dmitry Kasatkin , containers@lists.linux-foundation.org, linux-security-module@vger.kernel.org, linux-audit@redhat.com, "Eric W. Biederman" , linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alban Crequy , linux-integrity@vger.kernel.org, Stephen Smalley , Todd Kjos Subject: Re: [PATCH v2 07/39] mount: attach mappings to mounts Message-ID: <20201124123035.hbv4sstyoucht7xp@wittgenstein> References: <20201115103718.298186-1-christian.brauner@ubuntu.com> <20201115103718.298186-8-christian.brauner@ubuntu.com> <20201123154719.GD4025434@cisco> <20201123162428.GA24807@cisco> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201123162428.GA24807@cisco> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Mon, Nov 23, 2020 at 11:24:28AM -0500, Tycho Andersen wrote: > On Mon, Nov 23, 2020 at 10:47:19AM -0500, Tycho Andersen wrote: > > On Sun, Nov 15, 2020 at 11:36:46AM +0100, Christian Brauner wrote: > > > +static inline struct user_namespace *mnt_user_ns(const struct vfsmount *mnt) > > > +{ > > > + return mnt->mnt_user_ns; > > > +} > > > > I think you might want a READ_ONCE() here. Right now it seems ok, since the > > mnt_user_ns can't change, but if we ever allow it to change (and I see you have > > a idmapped_mounts_wip_v2_allow_to_change_idmapping branch on your public tree > > :D), the pattern of, > > > > user_ns = mnt_user_ns(path->mnt); > > if (mnt_idmapped(path->mnt)) { > > uid = kuid_from_mnt(user_ns, uid); > > gid = kgid_from_mnt(user_ns, gid); > > } > > > > could race. > > Actually, isn't a race possible now? > > kuid_from_mnt(mnt_user_ns(path->mnt) /* &init_user_ns */); > WRITE_ONCE(mnt->mnt.mnt_user_ns, user_ns); > WRITE_ONCE(m->mnt.mnt_flags, flags); > kgid_from_mnt(mnt_user_ns(path->mnt) /* the right user ns */); > > So maybe it should be: > > if (mnt_idmapped(path->mnt)) { > barrier(); > user_ns = mnt_user_ns(path->mnt); > uid = kuid_from_mnt(user_ns, uid); > gid = kgid_from_mnt(user_ns, gid); > } > > since there's no data dependency between mnt_idmapped() and > mnt_user_ns()? I think I had something to handle this case in another branch of mine. The READ_ONCE() you mentioned in another patch I had originally dropped because I wasn't sure whether it works on pointers but after talking to Jann and David it seems that it handles pointers fine. Let me take a look and fix it in the next version. I just finished porting the test suite to xfstests as Christoph requested and I'm looking at this now. Thanks! Christian