Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1117636imm; Fri, 5 Oct 2018 19:10:43 -0700 (PDT) X-Google-Smtp-Source: ACcGV60O27D+vzpRK5vC+mi/YKXHjjYPiS3zf256CA5i+7/66TEbGTzUbUhsd5B/hABGPkiYUUvz X-Received: by 2002:a63:aa48:: with SMTP id x8-v6mr12157214pgo.87.1538791843741; Fri, 05 Oct 2018 19:10:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538791843; cv=none; d=google.com; s=arc-20160816; b=yJaoeJ6UTlrI3XMTHEQJ9vofcZKIoxJ6xFIvs26f/2orUkoybiSuj9DvXU5VIMswT2 y/RAKDCzJkg9Q/uFx1+INcMz/0Ib4eTvn1aCYm8Yc976LFeSKFC5Jjj34M66BC5FBxF2 P9+TVMszPNLWFIbd275XOmVYVwUm3dSkufte4AgYD13X+glft4mrIhtQvJLOHsbhftqG 021RdGIDVgnJOEjYY10yWbyiwHI9z77PubVOAbzWxPylo0tVva1PVtr0auGgkaxITZZ9 se/24IQmPCymXu8nNPGacmGyQHugcbM01jRpCajPRf5y7t+2LPMwKcg5IlH0cWYwbhx2 miHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=MYHqMoLkMo9J7smtlvfUG9AZdbMf1pRddOVD43m9OaI=; b=Uq0TovptkYCI5gaFM1xKGQ+UGb9f3DtP4ZMqd6YWBNcsdDFDvnaHrjRlXpdSMQSes5 2tYWELL2lueO/Icy2N9akJPEFVMwkhEvTdiLcozNo++d1LPf2cL2sWLcFKHYD2p63UkG zYwx9cn0UlilQRla0gi5PhGnIzgWcmqoYDIPpGqJozQphnJuuDYVME+lyGVp0if688Kd H8KKkai873SaRVFnVjV4nf6Srh3RnHLbjchUZAFIWaMz4ZL1VrEw26NsyWskW4LIqCg0 VdCm+PHwntw6KUw96SjHGltevONnczcRJPog5Jo4EDnFexPfQM/tdxs53jR9U1OE/ba5 SBPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s6-v6si9140570pgc.133.2018.10.05.19.10.25; Fri, 05 Oct 2018 19:10:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729047AbeJFJLs (ORCPT + 99 others); Sat, 6 Oct 2018 05:11:48 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:54122 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726505AbeJFJLr (ORCPT ); Sat, 6 Oct 2018 05:11:47 -0400 Received: from smtp2.mailbox.org (unknown [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 612C741517; Sat, 6 Oct 2018 04:10:18 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id HCkFdIR-ehHB; Sat, 6 Oct 2018 04:10:16 +0200 (CEST) Date: Sat, 6 Oct 2018 12:10:02 +1000 From: Aleksa Sarai To: Jann Horn Cc: "Eric W. Biederman" , Al Viro , jlayton@kernel.org, Bruce Fields , Arnd Bergmann , shuah@kernel.org, David Howells , Andy Lutomirski , christian@brauner.io, Tycho Andersen , kernel list , linux-fsdevel@vger.kernel.org, linux-arch , linux-kselftest@vger.kernel.org, dev@opencontainers.org, containers@lists.linux-foundation.org, "cyphar@cyphar.com Linux API" Subject: Re: [PATCH 2/3] namei: implement AT_THIS_ROOT chroot-like path resolution Message-ID: <20181006021002.6vzsdwd3klddbmji@ryuk> References: <20180929103453.12025-1-cyphar@cyphar.com> <20180929131534.24472-1-cyphar@cyphar.com> <20181004162611.vdlujbdguvagalpt@ryuk> <20181005150728.mgqnpkbukpeu3bsm@ryuk> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="y5cyimyl4h3ru7zm" Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --y5cyimyl4h3ru7zm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2018-10-05, Jann Horn wrote: > > What if we took rename_lock (call it nd->r_seq) at the start of the > > resolution, and then only tried the __d_path-style check > > > > if (read_seqretry(&rename_lock, nd->r_seq) || > > read_seqretry(&mount_lock, nd->m_seq)) > > /* do the __d_path lookup. */ > > > > That way you would only hit the slow path if there were concurrent > > renames or mounts *and* you are doing a path resolution with > > AT_THIS_ROOT or AT_BENEATH. I've attached a modified patch that does > > this (and after some testing it also appears to work). >=20 > Yeah, I think that might do the job. *phew* I was all out of other ideas. :P > > --- > > fs/namei.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- > > 1 file changed, 46 insertions(+), 3 deletions(-) > > > > diff --git a/fs/namei.c b/fs/namei.c > > index 6f995e6de6b1..12c9be175cb4 100644 > > --- a/fs/namei.c > > +++ b/fs/namei.c > > @@ -493,7 +493,7 @@ struct nameidata { > > struct path root; > > struct inode *inode; /* path.dentry.d_inode */ > > unsigned int flags; > > - unsigned seq, m_seq; > > + unsigned seq, m_seq, r_seq; > > int last_type; > > unsigned depth; > > int total_link_count; > > @@ -1375,6 +1375,27 @@ static int follow_dotdot_rcu(struct nameidata *n= d) > > return -EXDEV; > > break; > > } > > + if (unlikely((nd->flags & (LOOKUP_BENEATH | LOOKUP_CHRO= OT)) && > > + (read_seqretry(&rename_lock, nd->r_seq) || > > + read_seqretry(&mount_lock, nd->m_seq)))) { > > + char *pathbuf, *pathptr; > > + > > + nd->r_seq =3D read_seqbegin(&rename_lock); > > + /* Cannot take m_seq here. */ > > + > > + pathbuf =3D kmalloc(PATH_MAX, GFP_ATOMIC); > > + if (!pathbuf) > > + return -ECHILD; > > + pathptr =3D __d_path(&nd->path, &nd->root, path= buf, PATH_MAX); > > + kfree(pathbuf); >=20 > You're doing this check before actually looking up the parent, right? > So as long as I don't trigger the "path_equal(&nd->path, &nd->root)" > check that you do for O_BENEATH, escaping up by one level is possible, > right? You should probably move this check so that it happens after > following "..". Yup, you're right. I'll do that. > (Also: I assume that you're going to get rid of that memory allocation > in a future version.) Sure. Would you prefer adding some scratch space in nameidata, or that I change __d_path so it accepts NULL as the buffer (and thus it doesn't actually do any string operations)? > > if (nd->path.dentry !=3D nd->path.mnt->mnt_root) { > > int ret =3D path_parent_directory(&nd->path); > > if (ret) > > @@ -2269,6 +2311,9 @@ static const char *path_init(struct nameidata *nd= , unsigned flags) > > nd->last_type =3D LAST_ROOT; /* if there are only slashes... */ > > nd->flags =3D flags | LOOKUP_JUMPED | LOOKUP_PARENT; > > nd->depth =3D 0; > > + nd->m_seq =3D read_seqbegin(&mount_lock); > > + nd->r_seq =3D read_seqbegin(&rename_lock); >=20 > This means that now, attempting to perform a lookup while something is > holding the rename_lock will spin on the lock. I don't know whether > that's a problem in practice though. Does anyone on this thread know > whether this is problematic? I could make it so that we only take &rename_lock if (nd->flags & (FOLLOW_BENEATH | FOLLOW_CHROOT)), since it's not used outside of that path. --=20 Aleksa Sarai Senior Software Engineer (Containers) SUSE Linux GmbH --y5cyimyl4h3ru7zm Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEXzbGxhtUYBJKdfWmnhiqJn3bjbQFAlu4GXcACgkQnhiqJn3b jbSetw/9H1Y6MiSjGRuK0/R1aLFbEbq0BkUgy+kdt3R+qt0BJjUU9JrmzbbUWnjC eQH8by6CDPNBIY5R8G/SlbcUiEoyRevo/saa14ZS5ny2vJjuxd9n82Ey9oHpZb0Y hSD4+dx6S4iQADq0+HbsVO/5x+9jxVr2Nmk92GkTdGd1kTeob8NmNW8rbFqteGM8 6HJ9DxCaOC0Tlk0aY70OzavIk5rylvi4conyxoYWqE+gZIXUCRNzFBBqbxSAgUMq NKFkDwEK+MuCgMoGstrKvCnaGijbuTGBGjY1lKmY506wsnPO1k2hnQPDS904jOoB P4MjsobwBIU2Kx4lPIeDbL70E+f1AwXpmBQw2rFotf4mq79SoASM40wb/TP7HBhx cn9gjPO1oykB9NkJ/yhFySN3rZszXHfhNRAY2BwQeBlA5Mo1fmJCAN0E8813GCt8 f5KLN6vYYxsnUjiY4R1yLHe4TsY+F93b0xqLkghdgpHg+78ytOvgpDR+13TShE3j eIcwyeG0ZCJr84Xgloeny/tc13IhtW0nnH5HgTaNXqFHpavtaRAROBXttV7ADTL2 XSmRgIihrrN8ULpFTuwEvE7qBLwh3V9AyYhMY4XrVlanEygmdVJkn0R/CQ7lbwiV EW56EqlbKmen/1fN7jYU9obldALUIX+b5Iq8AktXKyOOVBeekXk= =EMae -----END PGP SIGNATURE----- --y5cyimyl4h3ru7zm--