Project

General

Profile

Actions

Bug #9965

closed

Want support for O_DIRECTORY

Added by Garrett D'Amore over 2 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Category:
kernel
Start date:
2018-11-08
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

POSIX 2008 (SUSv7) specifies the use of O_DIRECTORY:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html

The justification is here:

"In addition, the open() function refuses to open non-directories if the O_DIRECTORY flag is set. This avoids race conditions whereby a user might compromise the system by substituting a hard link to a sensitive file (e.g., a device or a FIFO) while a privileged application is running, where opening a file even for read access might have undesirable side-effects."

Apparently some software now depends on this, as reported to me by Sebastian Wiedenroth:

Some software (slibtool) recently started using O_DIRECTORY, which is how I noticed that it’s not yet available on illumos.
Looking further I found that you had already implemented support for it in illumos-core, it just never made it into the gate:

Indeed I have implemented this in illumos-core.

The code I have for this today does not allow O_CREAT and O_DIRECTORY be supplied together. The version of the specification I recall reading about this was a big vague about this. The 2018 version linked above is also still vague, but seems to suggest that it should be possible to use the two together with O_RDWR or O_WRONLY (presumably to create a directory). The version of the code I am planning to supply at first lacks this capability, and simply reports EINVAL if the two are used together.

It may be reasonable to refactor this slightly to add support so that O_DIRECTORY|O_CREAT|O_WR behaves like mkdir. Ideally I would like to do that in a follow up task if needed.

Actions #1

Updated by Robert Mustacchi over 1 year ago

  • Subject changed from O_DIRECTORY required for POSIX 2008 to Want support for O_DIRECTORY
  • Assignee changed from Garrett D'Amore to Robert Mustacchi
Actions #2

Updated by Robert Mustacchi over 1 year ago

I've tested this through the addition of the test suite and ran a couple of the other ones for good measure. Andy F. tested this with a bunch of third-party software that was previously being patched out. I also used truss on the test suite to verify it and verified that mandoc still worked with this.

Actions #3

Updated by Electric Monk over 1 year ago

  • Status changed from New to Closed
  • % Done changed from 90 to 100

git commit 69c811ab73b7ce531454837ae68c4343e8724e0b

commit  69c811ab73b7ce531454837ae68c4343e8724e0b
Author: Robert Mustacchi <rm@fingolfin.org>
Date:   2020-02-01T06:34:51.000Z

    9965 Want support for O_DIRECTORY
    Reviewed by: Andy Fiddaman <andy@omniosce.org>
    Reviewed by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
    Approved by: Garrett D'Amore <garrett@damore.org>

Actions

Also available in: Atom PDF