9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Ethan Gardener" <eekee57@fastmail.fm>
To: "g_patrickb via 9fans" <9fans@9fans.net>
Subject: Re: [9fans] `test -x` returns wrong results for directories
Date: Sun, 07 Jun 2020 14:56:13 +0100	[thread overview]
Message-ID: <92f9c753-600a-44e5-b877-3ed8d578ea15@www.fastmail.com> (raw)
In-Reply-To: <CAOw7k5jeYoL3mcarGyLdHB6qbdmP8uXaa6SknY2iQ=atsy0O6Q@mail.gmail.com>

On Sat, Jun 6, 2020, at 2:25 PM, Charles Forsyth wrote:
> execute permission on files, meaning here non-directories, is a special variant of read. a file with mode 0111 can be opened with OEXEC and read(2) will work as well as exec(2),
> but can't be opened with OREAD, because it's not got any of 0444 set. bits 0111 distinguish a file with contents that are intended to be executed once read from files with only 0444 that do not contain executable content.
> you wouldn't want every readable file to be executable (especially if you've used systems that didn't have that distinction).
> on the other hand, in a distributed file system, the client needs the contents of the file to run it (whether code or #!script) so it needs to be able to read files with just OEXEC.
> I suppose the rule could have been that it would need mode 5 (r+x) to make clear that the file was also readable, but it isn't.
> 
> that OEXEC allows reading isn't true for a directory because exec means "search", so if it's mode 0111 (say) you can chdir into it but not read the names within it.
> if you know a name of a file in that directory, though, you can still open that. that's entirely enforced by the server.
> 
> as the bug in access(2) suggests, only the server knows whether access should be granted, and the open call gets it to do that,
> but it doesn't work for OEXEC for directories as others have noted. perhaps stat+chdir is the most accurate test, since you need x (search) permission to walk(5) into a directory,
> but the caller won't thank you for the chdir (and there's no easy or certain way back), and ... that restriction isn't enforced by fossil or ramfs. (ramfs wrongly allows you to read a directory that's mode 0.)
> 
> probably the best thing is just to ignore the owner/group/other distinction, and if the open(...OEXEC) fails, dirstat it, and if it's a directory with any of 0111 set, it's fine (a little better than now).

thanks for the analysis, charles. the dirstat you suggest wouldn't do any good for my case because rc-httpd runs as user none. the common problem it's trying to catch is a directory which isn't world-readable & world-searchable. 770 750 and 700 are common permissions. perhaps i should have rc-httpd just run the commands and test their status rather than trying to test ahead of time, but this would somewhat spoil the neat and simple design.

  reply	other threads:[~2020-06-07 13:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-05 12:45 Ethan Gardener
2020-06-05 19:22 ` [9fans] " Richard Miller
2020-06-06  6:36   ` Ethan Gardener
2020-06-06 12:11     ` Alexander Kapshuk
2020-06-06 13:25     ` Charles Forsyth
2020-06-07 13:56       ` Ethan Gardener [this message]
2020-06-06 21:13     ` ori
2020-06-07 14:48       ` Ethan Gardener
2020-06-07 15:41         ` Richard Miller
2020-06-08  2:04           ` ori
2020-06-08  2:13             ` Charles Forsyth
2020-06-08  2:20               ` Charles Forsyth
2020-06-09 10:50               ` Ethan Gardener

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=92f9c753-600a-44e5-b877-3ed8d578ea15@www.fastmail.com \
    --to=eekee57@fastmail.fm \
    --cc=9fans@9fans.net \
    /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.
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).