Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1779219ybp; Fri, 11 Oct 2019 21:12:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqyfplKvr+f9oblJGfIdRrXHZ/9b+i9tyevXAncgTzFjDBlVXe48u9zz9/M1n6WQ4GTZVP34 X-Received: by 2002:a17:906:470d:: with SMTP id y13mr17348540ejq.241.1570853552507; Fri, 11 Oct 2019 21:12:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570853552; cv=none; d=google.com; s=arc-20160816; b=yxohbtelGP9orhzLI4dUqjBXEpFOJpc7Cc1xD352t17r/ebJfpPbDVYn43JDdAVJwz 2McJK0cQpY37hOscm0EXUPBWrhl2DpAJFbrwhgYpaCgVmTWcSfOpfbNxBY/vf2wF9yr6 Wkq4JjJlCwdLqsnGmMhE6aRzNgjQ/+a284VqpCF+CvSP9RuUq2MaS8g9Dw+ZUM4AeCCC qAzpTeVifWpFSa3hA6/A9GDZDLF3Uva3ZSHeB6NNNtgZ+8C5EfOAcMB4qpsMatqm1dUk FcT7XuzzH5WFwcghk1cqCqhRHRiSE1/Mc+H44AJ93uk9lsmrTFObGUSCP8opa6DXlDWq h0uQ== 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=XB6ioF5fDyFRBUUVUU+ynzz4KjetHK64DHobcV6QI2I=; b=yVIEMyC2ub5G157U4rrk55bYs7X/YjmdmE9CUQM9KEEzzhDqKEBN6po43EBlthUgJH Hic/J9fJAWK6hQiee4EFzlEBLMrOJcCF8pN+n07+aEmHUpQrwabi68cHkI5h8f9SXNlK TcJg2UL/LsumPOFdenz3IXCLxaGUWTrCwhwRzqL3dlPTL1fZsw+zhfo6uoUfjNe6CKFz 3iDmSIfelrKHfjvYGC/w7e6yvB7pQs2GSo0qsD1x2OsiO1Fi9L6WQkZ+qgbh2a4Ea2y1 xYKTrqzqKCPcYvyeLQhz2qrKS5GgI/Fba/TI55JJ55ClKVBcp+gxEVcqWCiJ8YmB7jxi qrjA== 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 t37si8423315edd.25.2019.10.11.21.12.09; Fri, 11 Oct 2019 21:12:32 -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 S1728089AbfJLEIz (ORCPT + 99 others); Sat, 12 Oct 2019 00:08:55 -0400 Received: from mx2a.mailbox.org ([80.241.60.219]:42745 "EHLO mx2a.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727440AbfJLEIy (ORCPT ); Sat, 12 Oct 2019 00:08:54 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2a.mailbox.org (Postfix) with ESMTPS id 0485AA1104; Sat, 12 Oct 2019 06:08:47 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id WQcjjXFgeVVi; Sat, 12 Oct 2019 06:08:40 +0200 (CEST) Date: Sat, 12 Oct 2019 15:08:15 +1100 From: Aleksa Sarai To: Linus Torvalds Cc: Al Viro , Jeff Layton , "J. Bruce Fields" , Arnd Bergmann , David Howells , Shuah Khan , Shuah Khan , Ingo Molnar , Peter Zijlstra , Eric Biederman , Andy Lutomirski , Andrew Morton , Alexei Starovoitov , Kees Cook , Jann Horn , Tycho Andersen , David Drysdale , Chanho Min , Oleg Nesterov , Rasmus Villemoes , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Christian Brauner , Aleksa Sarai , Linux Containers , alpha , Linux API , GNU C Library , linux-arch , Linux ARM , linux-fsdevel , linux-ia64@vger.kernel.org, Linux Kernel Mailing List , "open list:KERNEL SELFTEST FRAMEWORK" , linux-m68k , linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390 , Linux-sh list , linux-xtensa@linux-xtensa.org, sparclinux@vger.kernel.org Subject: Re: [PATCH v14 2/6] namei: LOOKUP_IN_ROOT: chroot-like path resolution Message-ID: <20191012040815.gnc43cfmo5mnv67u@yavin.dot.cyphar.com> References: <20191010054140.8483-1-cyphar@cyphar.com> <20191010054140.8483-3-cyphar@cyphar.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="t2fxesclfr677pzw" 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 --t2fxesclfr677pzw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2019-10-10, Linus Torvalds wrote: > On Wed, Oct 9, 2019 at 10:42 PM Aleksa Sarai wrote: > > > > --- a/fs/namei.c > > +++ b/fs/namei.c > > @@ -2277,6 +2277,11 @@ static const char *path_init(struct nameidata *n= d, unsigned flags) > > > > nd->m_seq =3D read_seqbegin(&mount_lock); > > > > + /* LOOKUP_IN_ROOT treats absolute paths as being relative-to-di= rfd. */ > > + if (flags & LOOKUP_IN_ROOT) > > + while (*s =3D=3D '/') > > + s++; > > + > > /* Figure out the starting path and root (if needed). */ > > if (*s =3D=3D '/') { > > error =3D nd_jump_root(nd); >=20 > Hmm. Wouldn't this make more sense all inside the if (*s =3D- '/') test? > That way if would be where we check for "should we start at the root", > which seems to make more sense conceptually. I don't really agree (though I do think that both options are pretty ugly). Doing it before the block makes it clear that absolute paths are just treated relative-to-dirfd -- doing it inside the block makes it look more like "/" is a special-case for nd_jump_root(). And while that is somewhat true, this is just a side-effect of making the code more clean -- my earlier versions reworked the dirfd handling to always grab nd->root first if LOOKUP_IS_SCOPED. I switched to this method based on Al's review. In fairness, I do agree that the lonely while loop looks ugly. > That test for '/' currently has a "} else if (..)", but that's > pointless since it ends with a "return" anyway. So the "else" logic is > just noise. This depends on the fact that LOOKUP_BENEATH always triggers -EXDEV for nd_jump_root() -- if we ever add another "scoped lookup" flag then the logic will have to be further reworked. (It should be noted that the new version doesn't always end with a "return", but you could change it to act that way given the above assumption.) > And if you get rid of the unnecessary else, moving the LOOKUP_IN_ROOT > inside the if-statement works fine. >=20 > So this could be something like >=20 > --- a/fs/namei.c > +++ b/fs/namei.c > @@ -2194,11 +2196,19 @@ static const char *path_init(struct > nameidata *nd, unsigned flags) >=20 > nd->m_seq =3D read_seqbegin(&mount_lock); > if (*s =3D=3D '/') { > - set_root(nd); > - if (likely(!nd_jump_root(nd))) > - return s; > - return ERR_PTR(-ECHILD); > - } else if (nd->dfd =3D=3D AT_FDCWD) { > + /* LOOKUP_IN_ROOT treats absolute paths as being > relative-to-dirfd. */ > + if (!(flags & LOOKUP_IN_ROOT)) { > + set_root(nd); > + if (likely(!nd_jump_root(nd))) > + return s; > + return ERR_PTR(-ECHILD); > + } > + > + /* Skip initial '/' for LOOKUP_IN_ROOT */ > + do { s++; } while (*s =3D=3D '/'); > + } > + > + if (nd->dfd =3D=3D AT_FDCWD) { > if (flags & LOOKUP_RCU) { > struct fs_struct *fs =3D current->fs; > unsigned seq; >=20 > instead. The patch ends up slightly bigger (due to the re-indentation) > but now it handles all the "start at root" in the same place. Doesn't > that make sense? It is correct (though I'd need to clean it up a bit to handle nd_jump_root() correctly), and if you really would like me to change it I will -- but I just don't agree that it's cleaner. --=20 Aleksa Sarai Senior Software Engineer (Containers) SUSE Linux GmbH --t2fxesclfr677pzw Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQSxZm6dtfE8gxLLfYqdlLljIbnQEgUCXaFRqQAKCRCdlLljIbnQ El00AQDKyu1GNvL91tAxvDZP/2rrqVrUf7Ad1T8uobD+aKQbgwEAvz9eeuLveRVq aqnd3Ifu8HO4SYcqYn+hDFgDz5D5Kwo= =XXCi -----END PGP SIGNATURE----- --t2fxesclfr677pzw--