Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1807472ybg; Sun, 27 Oct 2019 05:16:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzs/hCczvlp+WbAo/J0XPZj6yyQ+75I6YHuF2d3yI7EM62AerKAE/wkh8P5Iu5G6xqeKfc+ X-Received: by 2002:aa7:c954:: with SMTP id h20mr13965382edt.159.1572178595145; Sun, 27 Oct 2019 05:16:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572178595; cv=none; d=google.com; s=arc-20160816; b=G3HyCdOgZLARY9mPdwC1Ur+Xjs/n5Y2pEP+4QHa8oU9tRkM9alIPbacjvYD6Odzzn6 BHzV82cvSC0VbbjMiK6v85oF6XZy92wf5lsZnvX/1oust3WfnwyQh/H9gN4Nk66OWibH 5k4U5F50y+JT55PnHWIt7DbJizBUGzbA3CCthCOy+es+QYuEretrl5zLoWb8LBAbcImX lzQkYojlKwUf2ZSkoG8f78Yx94bxUcLXQEYGtmIqoe4vyQmkPvFs7Bx+K/13ATaNCwVb izRrd0q5VHF85+1Yspbnn8xI9ffaOg726f44NXApb/9OAjriI1YkWq5BidFeq+qD5Vn1 7Pew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=3Zr1M0nCXlilSobwLkNmgKE2widPtGkZk30ZqC0Jsp4=; b=rOtcnifLNhczoPHa7dg2IdoaGz3G88C2hbkW1AqEe9wISyXt/w3oSMBrDhAosO95Kk rQv1npF1Z5AXye8HTkrEvviloKsC+Kp+XJEqZzPNC5BNUJKs8vptKemIdvnzQRGfORJo 9WWTF8TRhz+0smt4vIAK3VM3Bb5pHWNeJSDEV2vvejdNKxvB7vnz1mv+EMEDFZ4K5xxk wKitYW5YW/O3kTNr2BhjhnXEeBjWmduH7iQTsirw/JqZGyE4uB9+L69OS1zWUkyEkkdB wsCUBADAes55PoTR4JHYDbRaWH7vs3Rcw29kxYhERzsqT7BVnCzR/fYXFULZAfVFne69 XqYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=d3QTzyBq; 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 n9si4561571ejz.3.2019.10.27.05.16.09; Sun, 27 Oct 2019 05:16:35 -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; dkim=pass header.i=@linux-foundation.org header.s=google header.b=d3QTzyBq; 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 S1726979AbfJ0MFe (ORCPT + 99 others); Sun, 27 Oct 2019 08:05:34 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:33786 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726961AbfJ0MFe (ORCPT ); Sun, 27 Oct 2019 08:05:34 -0400 Received: by mail-lf1-f68.google.com with SMTP id y127so5690911lfc.0 for ; Sun, 27 Oct 2019 05:05:33 -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=Y2zo6zoB1E8uVRVKhmtmvBbudN72HMHnnM4VZDa9EpgqEVg2Lz9C1y1THTavm5lCW4 Aqi2769GEkW59n1nnPflHRTzf01GwCFBJnyfqjN/5hBcCH9s6P5ir31ciObVoxL6EWDQ 33oTFWdIPuyr1k+fEujHMpDbYPN6ooOFfdQXqdrIKMu5PF6zhaBBmZjeHO1Q0vv2Uw+4 EKBYoG5NO/wDzDVeKdjkwcx2lbcLhP7Ham9Rt/WU6fdFt+XdeLf3sHjByEXfjca8QHNl staDfZxiWylqKb0+nuPfJe47xyyrxBbvivs8bE88glG7XYRseU3iIb47BLa7+GN9Pqsw scRw== X-Gm-Message-State: APjAAAWj35q0igwGvsyjH6hr38kH7dLh9ADy97fHxYA2nroWheGgfyXK MDPPixei0BtdLRT6rJ7oiUFZClB4C1T9kw== X-Received: by 2002:a19:750:: with SMTP id 77mr8019759lfh.81.1572177931931; Sun, 27 Oct 2019 05:05:31 -0700 (PDT) Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com. [209.85.167.49]) by smtp.gmail.com with ESMTPSA id u26sm3891445lfd.19.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-f49.google.com with SMTP id y6so5680364lfj.2 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 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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