mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Subject: Re: realpath after chroot
Date: Wed, 9 Oct 2019 05:47:49 +0200	[thread overview]
Message-ID: <20191009034749.GC18139@voyager> (raw)
In-Reply-To: <20191008211010.GB16318@brightrain.aerifal.cx>

On Tue, Oct 08, 2019 at 05:10:10PM -0400, Rich Felker wrote:
> On Tue, Oct 08, 2019 at 09:56:23PM +0200, Markus Wichmann wrote:
> > Well, what does depend on /proc at the moment? Of course, there is
> > everything calling __procfdname(), so that would be
> >
> > - realpath() (main path)
> > - fexecve() (fallback path)
> > - fchmod() (fallback path)
> > - fchmodat() (main path for AT_SYMLINK_NOFOLLOW)
> > - fstatat() (fallback path)
> > - fchdir() (fallback path)
> > - fchown() (fallback path)
> > - ttyname_r() (main path), and ttyname() by extension
>
> Thanks for working these out.
>
> For the ones marked "fallback path", it's not entirely clear whether
> the fallback path is only needed for old kernels, or possibly needed
> even on recent/current ones. Historically Linux was very sloppy about
> supporting some of these operations on O_PATH (used for
> O_EXEC/O_SEARCH) fds.
>

Yes, I just had a glance at the code. For fchmod(), the fallback path is
triggered if SYS_fchmod returned EBADF, and yet the file descriptor
flags could be retrieved, indicating the FD is open. I'm guessing
SYS_fchmod is no longer an optional system call, but is bad about
O_PATH?

fstatat() is really special. There is the SYS_statx codepath which is
ignored on most architectures. At least until you push the time64_t
stuff. And __procfdname() is only called in the AT_EMPTY_PATH case, if
SYS_fstat displayed the same behavior as above (returning EBADF on an
open FD), and SYS_fstatat failed with EINVAL.

fchdir() and fchown() have the same code (entering the fallback path on
EBADF with open FD).

So it appears that fexecve() is the exception here, entering the
fallback path on ENOSYS.

> Indeed, there are at least a few items of "standard functionality"
> that depend on /proc, regardless of the status of the "fallback" ones:
> at least ttyname and fchmodat. Note that ttyname can be done without
> /proc by searching /dev for matching dev_t, either using known
> patterns for tty names or a global search, but this is ugly too.
>

I was about to protest that this would add /dev to the list of
dependencies. Then I noticed that ttyname() tries to stat() its result,
so if /dev isn't in the chroot jail, it does not work, either.

Ciao,
Markus


  reply	other threads:[~2019-10-09  3:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-08 17:24 Reiner Herrmann
2019-10-08 17:38 ` Rich Felker
2019-10-08 17:49   ` Reiner Herrmann
2019-10-08 19:56   ` Markus Wichmann
2019-10-08 21:10     ` Rich Felker
2019-10-09  3:47       ` Markus Wichmann [this message]
2019-10-09 11:45         ` Rich Felker
2019-10-09 16:00           ` Markus Wichmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191009034749.GC18139@voyager \
    --to=nullplan@gmx.net \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).