Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1650364pxu; Tue, 24 Nov 2020 05:53:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzoyDDBUBt+bAYBlHL8N525C9Bfy28iPv0F75iGYNOc9hSd2QNpLwy/qUxFsAnC79kyKkZy X-Received: by 2002:a05:6402:308b:: with SMTP id de11mr4085357edb.5.1606226032299; Tue, 24 Nov 2020 05:53:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606226032; cv=none; d=google.com; s=arc-20160816; b=TqpMyoqFcezCulXdanWw8vqLwKVutpOsp2Wy2j3Wp+dd5/7+roa6X386DDlwnCAn8l 7JUQuBYQtsMzzx/AyTkvE0tIgGF97hmUKHH784c7VwRSUQ0rtYn3HKDdqn2u8O2/l8WM XfGRsaZB2sBTqQ/9dHYwidadKSMmdhbXnLE5lqnbTyGlJMemv5h7f+tgCAyRELyTcFf+ nC7yjzXfu2jEWmeQa/sDQsR7W4ChTle1+g2qZnHb/jDAsujZmLdiWpDbGf3fo041CyAL wqfX5qyNhGzdmGZtQaaFqYShSXlDqFCH6lRtJQDlCYGPQZ+BaFSi1Hjc0VdlfjkyCTKd tuDg== 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:dkim-signature :dkim-signature; bh=ICi3xGmyU3rUTgE9Z8EkpSjYA46p82e0AHaf1vgqc2E=; b=a8MIZQ4Egqswm/E5rAtmlDfGQKiilNfFWxT7b4hgX5hLTge4GzfQQXfdbv3B/RqsWx G8Z5FU3EcwSUIX4y+3oNyLsmIizV1KmRTbyAVG7vw6BvoizzmcuFJfxx6aoObb91dyD7 Mu4e87Ozo84rLyRD7LEgfvczcFsoEFquy3L7ZxKB7dmzQJwevwSYlRHOaVHTKV0nzYnE Ds82TgOlFJPSTgyxRysD41bliplTVOtsRfqHFuPrzPz+NwicnoFb3AcV50G8eaqJ7oLm d4StQHmN+6/c+q6ms6wcciqRRya8uM40f17Hn7HRp0uOT+MFjkvJEJXkvTRHFZK8cqqs Mv6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tycho.pizza header.s=fm1 header.b=cKsAEMFF; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=rE0Loylz; 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 du15si9226722ejc.471.2020.11.24.05.53.28; Tue, 24 Nov 2020 05:53:52 -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; dkim=pass header.i=@tycho.pizza header.s=fm1 header.b=cKsAEMFF; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=rE0Loylz; 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 S2388434AbgKXNup (ORCPT + 99 others); Tue, 24 Nov 2020 08:50:45 -0500 Received: from new3-smtp.messagingengine.com ([66.111.4.229]:39255 "EHLO new3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388478AbgKXNp5 (ORCPT ); Tue, 24 Nov 2020 08:45:57 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailnew.nyi.internal (Postfix) with ESMTP id BF80658088F; Tue, 24 Nov 2020 08:45:17 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 24 Nov 2020 08:45:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho.pizza; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=ICi3xGmyU3rUTgE9Z8EkpSjYA46 p82e0AHaf1vgqc2E=; b=cKsAEMFFYuOAZzrmzVuS6fDaUdnOlWfJzkxXkSJO9Qe 4cPiabvCXG6yJevVlNt4UrBnhnM0oAjUCKFFTuiIP7KHkNqf6wAkJ1AGkr4y8R8F rshUTX7y/HGl4fDGx++8ZJ8B6vtl63FtXbpf/OVRf2eLIrr6d5Xgprn9bsV5H/hc 9HhzXpI0HlbN51t3O3r9ZYlv9IOtYlExB/SMGqvdTunWU6XcwAgzBGlIQe2rSTW7 X7ovYra3a1oSR47nZWVdudMNKQtPD32D8Y836jecithq2pdamn29HzkVmL8scqJb ewbh/XND3Cf49DNyIIsIt5so+/Xp0AT9ETHPbNNIZNA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=ICi3xG myU3rUTgE9Z8EkpSjYA46p82e0AHaf1vgqc2E=; b=rE0LoylzT/qyJu2DBs+yai 0QTR0Lw04fwyDVaPS1SIlsrWZ3D8qygcvuLQ0lTlybxYdeskf/8F8p5IvV4QcJng q/1hU9484JxUfjHiQ7wTCfZZpvGcpjBBPrP/v1/XjQCkCieLN7ky9TWOnLfN42M3 G74z61K75HbJqkrtvsc7O10emOLD9pKCmH2ZE0v63EaN1bs2NKDLdx5vv+4F4sXe qruYWcanFZ9LoRjo+8qZuQVKRGIdXmo0kzVF6DfbkMvZUdiH/ITNmdMY9WNO18iC HP+d5mUkfTPR/M4TP6ZK/VXAm/rZAl2sCZQ4h2xqevt37qG1w1zz1h8qTKXk6WNg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudegkedgheeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefvhigthhho ucetnhguvghrshgvnhcuoehthigthhhosehthigthhhordhpihiiiigrqeenucggtffrrg htthgvrhhnpeegkeefjeegkedtjefgfeduleekueetjeeghffhuefgffefleehgeeifedv gfethfenucfkphepuddvkedruddtjedrvdeguddrudeivdenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthigthhhosehthigthhhordhpihii iigr X-ME-Proxy: Received: from cisco (unknown [128.107.241.162]) by mail.messagingengine.com (Postfix) with ESMTPA id 5D0B13064AB4; Tue, 24 Nov 2020 08:45:06 -0500 (EST) Date: Tue, 24 Nov 2020 08:44:59 -0500 From: Tycho Andersen To: Christian Brauner 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: <20201124134459.GB52954@cisco> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201124134035.2l36avuaqp6gxyum@wittgenstein> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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 think we should still use smp_store_release() in mnt_user_ns() paired > with smp_load_acquire() in do_idmap_mount() thought. Sounds reasonable. Tycho