This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH RESEND v14 2/6] namei: LOOKUP_IN_ROOT: chroot-like path resolution
- From: Aleksa Sarai <cyphar at cyphar dot com>
- To: Linus Torvalds <torvalds at linux-foundation dot org>
- Cc: Al Viro <viro at zeniv dot linux dot org dot uk>, Jeff Layton <jlayton at kernel dot org>, "J. Bruce Fields" <bfields at fieldses dot org>, Arnd Bergmann <arnd at arndb dot de>, David Howells <dhowells at redhat dot com>, Shuah Khan <shuah at kernel dot org>, Shuah Khan <skhan at linuxfoundation dot org>, Ingo Molnar <mingo at redhat dot com>, Peter Zijlstra <peterz at infradead dot org>, Eric Biederman <ebiederm at xmission dot com>, Andy Lutomirski <luto at kernel dot org>, Andrew Morton <akpm at linux-foundation dot org>, Alexei Starovoitov <ast at kernel dot org>, Kees Cook <keescook at chromium dot org>, Jann Horn <jannh at google dot com>, Tycho Andersen <tycho at tycho dot ws>, David Drysdale <drysdale at google dot com>, Chanho Min <chanho dot min at lge dot com>, Oleg Nesterov <oleg at redhat dot com>, Rasmus Villemoes <linux at rasmusvillemoes dot dk>, Alexander Shishkin <alexander dot shishkin at linux dot intel dot com>, Jiri Olsa <jolsa at redhat dot com>, Namhyung Kim <namhyung at kernel dot org>, Christian Brauner <christian at brauner dot io>, Aleksa Sarai <asarai at suse dot de>, Linux Containers <containers at lists dot linux-foundation dot org>, alpha <linux-alpha at vger dot kernel dot org>, Linux API <linux-api at vger dot kernel dot org>, GNU C Library <libc-alpha at sourceware dot org>, linux-arch <linux-arch at vger dot kernel dot org>, Linux ARM <linux-arm-kernel at lists dot infradead dot org>, linux-fsdevel <linux-fsdevel at vger dot kernel dot org>, linux-ia64 at vger dot kernel dot org, Linux Kernel Mailing List <linux-kernel at vger dot kernel dot org>, "open list:KERNEL SELFTEST FRAMEWORK" <linux-kselftest at vger dot kernel dot org>, linux-m68k <linux-m68k at lists dot linux-m68k dot org>, linux-mips at vger dot kernel dot org, linux-parisc at vger dot kernel dot org, linuxppc-dev at lists dot ozlabs dot org, linux-s390 <linux-s390 at vger dot kernel dot org>, Linux-sh list <linux-sh at vger dot kernel dot org>, linux-xtensa at linux-xtensa dot org, sparclinux at vger dot kernel dot org
- Date: Mon, 28 Oct 2019 02:41:15 +1100
- Subject: Re: [PATCH RESEND v14 2/6] namei: LOOKUP_IN_ROOT: chroot-like path resolution
- References: <20191026185700.10708-1-cyphar@cyphar.com> <20191026185700.10708-3-cyphar@cyphar.com> <CAHk-=wjPPWvm5_eR4uaHJaU1isTUk-4iXQV3Z2Px9A+w6j2nHg@mail.gmail.com>
On 2019-10-27, Linus Torvalds <torvalds@linux-foundation.org> wrote:
> On Sat, Oct 26, 2019 at 2:58 PM Aleksa Sarai <cyphar@cyphar.com> 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".
Okay, fair enough.
> 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
I've gone with the latter since I think it reads better.
--
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
<https://www.cyphar.com/>
Attachment:
signature.asc
Description: PGP signature