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.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, 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 94F2FCA9EAF for ; Sun, 27 Oct 2019 12:08:49 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (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 03E032070B for ; Sun, 27 Oct 2019 12:08:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="d3QTzyBq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03E032070B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 471Gpk0t7xzDq5t for ; Sun, 27 Oct 2019 23:08:46 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linuxfoundation.org (client-ip=2a00:1450:4864:20::141; helo=mail-lf1-x141.google.com; envelope-from=torvalds@linuxfoundation.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="d3QTzyBq"; dkim-atps=neutral Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 471Gl65ldMzDqjN for ; Sun, 27 Oct 2019 23:05:37 +1100 (AEDT) Received: by mail-lf1-x141.google.com with SMTP id j14so722293lfb.8 for ; Sun, 27 Oct 2019 05:05:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3Zr1M0nCXlilSobwLkNmgKE2widPtGkZk30ZqC0Jsp4=; b=d3QTzyBq1ltmtg4yGSZr5XtauvY/fALYcdqhiDEtFOl1dE9JCqjexjO52exODJRIVQ Eh2Een6o4qvZdUFz/jDS+JnTxGr7PmGqPX7rFmA4YZFRZjrNKL/JZDN1nI+V4NXXs/c+ Hp/xfBUyMptBO5mKJ7+YknkxBRlijCGcU26uA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3Zr1M0nCXlilSobwLkNmgKE2widPtGkZk30ZqC0Jsp4=; b=FbBJK1y0EmmJt15xIowczhJcyHSErcLZ6KuhyYwE0UxY4lrrsmQV8+rrPPSik49SQd WpbuRaeO9/J5HNAYaFeCnTIrHd/f1fp71nKORgCmDVL0eeiQrTJ5bOFenYZm+mDqTTtr KgEa1tI6OtSbmkATWUKkuAxzraDeq9afWotqW/mmwpVgO/uhgxmpw5XzGXbSn1o0M80G iqJnor81vjvmJ/Fp/s0+uAwUOysvR+7CZeokj/2jHpew+s/XSBtj4AjnOoFWptHKAJR1 /cZWIVibijoNNvpihf4QOg/EChbJDLDAvYkLkNpaNYofNHZtlSsfPcY+3IDuG8v2FLWY QHrA== X-Gm-Message-State: APjAAAUNgPnXLVZvPwQeuF1V+0u/xPYfmcBQ8zTZLjpxFi0uzNtHl5di zhA9AdTIdpKiR0WLG0ATUeGPut06ILww0A== X-Google-Smtp-Source: APXvYqwKSXiVD2LkQUhxsmYwtzOTjfV1MpRH1r6PmeYU8pV7SfC0ICO7oOD0EoU6ePF1AnwE511Z2w== X-Received: by 2002:ac2:520e:: with SMTP id a14mr1145873lfl.43.1572177931795; Sun, 27 Oct 2019 05:05:31 -0700 (PDT) Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com. [209.85.167.48]) by smtp.gmail.com with ESMTPSA id b28sm432798ljp.9.2019.10.27.05.05.29 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 27 Oct 2019 05:05:30 -0700 (PDT) Received: by mail-lf1-f48.google.com with SMTP id y127so5690843lfc.0 for ; Sun, 27 Oct 2019 05:05:29 -0700 (PDT) X-Received: by 2002:a19:5504:: with SMTP id n4mr8268196lfe.106.1572177927159; Sun, 27 Oct 2019 05:05:27 -0700 (PDT) MIME-Version: 1.0 References: <20191026185700.10708-1-cyphar@cyphar.com> <20191026185700.10708-3-cyphar@cyphar.com> In-Reply-To: <20191026185700.10708-3-cyphar@cyphar.com> From: Linus Torvalds Date: Sun, 27 Oct 2019 08:05:11 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH RESEND v14 2/6] namei: LOOKUP_IN_ROOT: chroot-like path resolution To: Aleksa Sarai Content-Type: text/plain; charset="UTF-8" X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List 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 Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Sat, Oct 26, 2019 at 2:58 PM Aleksa Sarai wrote: > > + /* LOOKUP_IN_ROOT treats absolute paths as being relative-to-dirfd. */ > + if (flags & LOOKUP_IN_ROOT) > + while (*s == '/') > + s++; > + > /* Figure out the starting path and root (if needed). */ > if (*s == '/') { > error = nd_jump_root(nd); So I'm still hung up on this. I guess I can't help it, but I look at the above, and it makes me go "whoever wrote those tests wasn't thinking". It just annoys me how it tests for '/' completely unnecessarily. If LOOKUP_IN_ROOT is true, we know the subsequent test for '/' is not going to match, because we just removed it. So I look at that code and go "that code is doing stupid things". That's why I suggested moving the LOOKUP_IN_ROOT check inside the '/' test. Alternatively, just make the logic be if (flags & LOOKUP_IN_ROOT) { .. remove '/'s ... } else if (*s == '/') { .. handl;e root .. and remove the next "else" clause Linus