Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1659272pxu; Tue, 24 Nov 2020 06:05:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQDM4HmweCyp78pYxYmxD+xDoZkjzmoQ2fzjAnIVtIrtdeyJHtQlUL0IVX2jyZ6TwFusKC X-Received: by 2002:a50:ee97:: with SMTP id f23mr4162502edr.333.1606226726940; Tue, 24 Nov 2020 06:05:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606226726; cv=none; d=google.com; s=arc-20160816; b=r2ZON7SgzEmeu1hklHVi7r7z80E4LUHq3Tw+90C8Yf4GaQu2o72qDiDvTRI6U1zsWF p2teOfQpZo65yu9v2R46RW9bdV7riBytsEMOv3lrj/tmhj1EXpsYAvdZmTwzpxozLUWf UIGagxrLGj2uu/9pdVnW5VCLqCggVKrM2FmlDRcB/AcCj8WF+HgWNeW6W/xO4FeGFgOQ O9eBB0BAK027v85hmccroU2ZJ7ajTihqnD1irW5NQBSLQCNgqEzRN+nZAP3379kTY6aV e0Nz4KO3zFUjnAdOFsX9Qe2IqHNO2aXABL3MA4KJZ90ogJzjjvHgeRC+gqcOzJv7ddVa xW+g== 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=byVtm55jJAnH9OtKJNwgLitbS50koLbdVhEzRDuVvOw=; b=KCdRXSfbd4znwkejVu2VvvZ2C6BXIltLOZl1/HPy90yqlNySq2RKRHDBjDsFC2NSWS ae3OXFhnoxsWPrOK9KTDDN+AwBMvPkyHx5YjMTmwCGYGewpnSVPVEmEjra7SOnEQlz+f ixIBsk7FXHbDUqQnjlAj2ztyrP707hZDPaMhjbJWCy5Ay0DWwSXHGLpRd2sZqNl77Ar0 CXCVXRK5B5g/k++vfU+pX9+kCQtp2MC3zasRzZi+Tf1fINzJDvNzuNBf8/Ks8Jj8+3LG th2IY+kGEsytagYTC4kl271RCEmvdoikO8pWdmQe+Cbvz70TkJ3MiRDgJ9ujy41vsIYB jj4g== 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 l26si8329496ejq.557.2020.11.24.06.04.47; Tue, 24 Nov 2020 06:05:26 -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 S1726145AbgKXOAB (ORCPT + 99 others); Tue, 24 Nov 2020 09:00:01 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:54719 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726085AbgKXOAA (ORCPT ); Tue, 24 Nov 2020 09:00:00 -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 1khYrD-0002SV-VO; Tue, 24 Nov 2020 13:59:48 +0000 Date: Tue, 24 Nov 2020 14:59:46 +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: <20201124135946.27krt6za2qapyx43@wittgenstein> References: <20201115103718.298186-1-christian.brauner@ubuntu.com> <20201115103718.298186-8-christian.brauner@ubuntu.com> <20201123154719.GD4025434@cisco> <20201123162428.GA24807@cisco> <20201124123035.hbv4sstyoucht7xp@wittgenstein> <20201124133740.GA52954@cisco> <20201124134035.2l36avuaqp6gxyum@wittgenstein> <20201124134459.GB52954@cisco> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201124134459.GB52954@cisco> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Tue, Nov 24, 2020 at 08:44:59AM -0500, Tycho Andersen wrote: > On Tue, Nov 24, 2020 at 02:40:35PM +0100, Christian Brauner wrote: > > On Tue, Nov 24, 2020 at 08:37:40AM -0500, Tycho Andersen wrote: > > > On Tue, Nov 24, 2020 at 01:30:35PM +0100, Christian Brauner wrote: > > > > 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. > > > > > > Another way would be to just have mnt_idmapped() test > > > mnt_user_ns() != &init_user_ns instead of the flags; then I think you > > > get the data dependency and thus correct ordering for free. > > > > I indeed dropped mnt_idmapped() which is unnecessary. :) > > It still might be a nice helper to prevent people from checking the > flags and forgetting that there's a memory ordering issue, though. I just mentioned this offline but for the record: the flag is gone since we can rely on the pointer alone. :) Christian