From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AAE4C10F14 for ; Sat, 12 Oct 2019 04:09:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6E1152084C for ; Sat, 12 Oct 2019 04:09:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jZuaSNoe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E1152084C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=cyphar.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jwmaUC6k40oQ8yjWhNeSmwiq22W05JVnWiKVycJx+VU=; b=jZuaSNoeGiTH0iBqtXi73bzuz LKy7/OOdcaU3ozq462DaCa2ASyQ7PQmLmfaeUYKYlcDV9i0lsa/sKQoA93QyTkdVFSMhYoz9NgrKh wQYEef/3B+rVQMx2wW2a/4n3ymlT7SrLhHyNV58VgNzwR1RYcrtkUvOsGOQDJDIVz6eJAtrzzoIca 453LcjECSCJo/1trUMWnbRB59xZPjdKmiwUhG7e7xWPuV0S9rlyPK2EPaKAN3a9F2NWATUGEkp3T8 i3DwlDJ/81f5gWuLVNuP/r8Sy4TTBvR82WIrvqDjCezgzSHeEIcTwFv0RX1tT3ZkiXhsQU2MJOYGM YBopshWxw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iJ8iE-0005g0-Ux; Sat, 12 Oct 2019 04:09:02 +0000 Received: from mx2a.mailbox.org ([2001:67c:2050:104:0:2:25:2]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iJ8iA-0005eQ-AA for linux-arm-kernel@lists.infradead.org; Sat, 12 Oct 2019 04:09:00 +0000 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 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 In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191011_210858_651586_0775564C X-CRM114-Status: GOOD ( 24.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-ia64@vger.kernel.org, Linux-sh list , Peter Zijlstra , Rasmus Villemoes , Alexei Starovoitov , Linux Kernel Mailing List , David Howells , "open list:KERNEL SELFTEST FRAMEWORK" , sparclinux@vger.kernel.org, Jiri Olsa , linux-arch , linux-s390 , Tycho Andersen , Aleksa Sarai , Shuah Khan , Alexander Shishkin , Ingo Molnar , Linux ARM , linux-mips@vger.kernel.org, linux-xtensa@linux-xtensa.org, Kees Cook , Arnd Bergmann , Jann Horn , linux-m68k , Al Viro , Andy Lutomirski , Shuah Khan , Namhyung Kim , David Drysdale , Christian Brauner , "J. Bruce Fields" , GNU C Library , linux-parisc@vger.kernel.org, Linux API , Chanho Min , Jeff Layton , Oleg Nesterov , Eric Biederman , alpha , linux-fsdevel , Andrew Morton , linuxppc-dev@lists.ozlabs.org, Linux Containers Content-Type: multipart/mixed; boundary="===============3501656562022824303==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============3501656562022824303== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="t2fxesclfr677pzw" Content-Disposition: inline --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-- --===============3501656562022824303== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============3501656562022824303==--