Page MenuHomeFreeBSD

Add O_SYMLINK emulation and freadlink(3)
Needs ReviewPublic

Authored by kib on Sun, Apr 12, 1:44 PM.
Tags
None
Referenced Files
F153653787: D56365.id.diff
Wed, Apr 22, 4:25 PM
F153577860: D56365.id175346.diff
Wed, Apr 22, 1:55 AM
Unknown Object (File)
Wed, Apr 22, 12:12 AM
Unknown Object (File)
Tue, Apr 21, 7:05 PM
Unknown Object (File)
Tue, Apr 21, 2:35 PM
Unknown Object (File)
Tue, Apr 21, 11:36 AM
Unknown Object (File)
Mon, Apr 20, 5:48 PM
Unknown Object (File)
Sun, Apr 19, 5:53 PM
Subscribers

Details

Summary
Add O_SYMLINK emulation

for MacOSX partial compatibility, defined as O_PATH | O_NOFOLLOW.
fstat(2) and freadlink(3) works on the resulting file descriptors,
but reads on the regular file do not.

More complete but more hackish version was developed but deemed too
hackish.


libc: add freadlink(3)

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

kib requested review of this revision.Sun, Apr 12, 1:44 PM

An alternative for this O_SYMLINK is to define it just to O_PATH | O_NOFOLLOW, if it is not important to be able to open(<regular file>, O_SYMLINK | O_RDONLY) and be able to read from the resulting fd.
I would prefer that implementation instead of the reopening with EMPTYPATH for non-symlinks, but I do not know real-world usage patterns for O_SYMLINK.

In D56365#1289902, @kib wrote:

An alternative for this O_SYMLINK is to define it just to O_PATH | O_NOFOLLOW, if it is not important to be able to open(<regular file>, O_SYMLINK | O_RDONLY) and be able to read from the resulting fd.
I would prefer that implementation instead of the reopening with EMPTYPATH for non-symlinks, but I do not know real-world usage patterns for O_SYMLINK.

I cannot find much documentation for O_SYMLINK, it is not clear to me if open(<regular file>, O_SYMLINK) is permitted at all, and I have no good way to test. I would prefer O_PATH | O_NOFOLLOW too.

lib/libc/gen/freadlink.c
6

I think this line is not supposed to be added anymore.

lib/libthr/thread/thr_syscalls.c
301 ↗(On Diff #175346)

This is assuming O_SYMLINK is never ORed with other flags (except O_RDONLY I suppose).

sys/sys/fcntl.h
149
183

O_SYNC == O_FSYNC

kib marked 4 inline comments as done.Wed, Apr 15, 4:03 PM
In D56365#1289902, @kib wrote:

An alternative for this O_SYMLINK is to define it just to O_PATH | O_NOFOLLOW, if it is not important to be able to open(<regular file>, O_SYMLINK | O_RDONLY) and be able to read from the resulting fd.
I would prefer that implementation instead of the reopening with EMPTYPATH for non-symlinks, but I do not know real-world usage patterns for O_SYMLINK.

I cannot find much documentation for O_SYMLINK, it is not clear to me if open(<regular file>, O_SYMLINK) is permitted at all, and I have no good way to test. I would prefer O_PATH | O_NOFOLLOW too.

I read it in the following paragraph from MacOSX open(2) man page:

If O_SYMLINK is used in the mask and the target file passed to open() is a symbolic link then the open()
will be for the symbolic link itself, not what it links to.

For now I left the libc hack in the branch, but lets wait for des@ opinion.

lib/libthr/thread/thr_syscalls.c
301 ↗(On Diff #175346)

Why not? I masking the O_SYMLINK bits when testing.

The problematic case is when consumer specifies all the constituent bits from O_SYMLINK for open(), but the combination of O_PATH | O_DSYNC does not make sense already.

kib marked an inline comment as done.

Minor editings.

In D56365#1291416, @kib wrote:
In D56365#1289902, @kib wrote:

An alternative for this O_SYMLINK is to define it just to O_PATH | O_NOFOLLOW, if it is not important to be able to open(<regular file>, O_SYMLINK | O_RDONLY) and be able to read from the resulting fd.
I would prefer that implementation instead of the reopening with EMPTYPATH for non-symlinks, but I do not know real-world usage patterns for O_SYMLINK.

I cannot find much documentation for O_SYMLINK, it is not clear to me if open(<regular file>, O_SYMLINK) is permitted at all, and I have no good way to test. I would prefer O_PATH | O_NOFOLLOW too.

I read it in the following paragraph from MacOSX open(2) man page:

If O_SYMLINK is used in the mask and the target file passed to open() is a symbolic link then the open()
will be for the symbolic link itself, not what it links to.

For now I left the libc hack in the branch, but lets wait for des@ opinion.

Right, this is all I found too.

lib/libthr/thread/thr_syscalls.c
301 ↗(On Diff #175346)

Sorry, I misread.

sys/sys/fcntl.h
186

markj@, are you fine with this chunk? I might push it in advance.

sys/sys/fcntl.h
186

Yes, I think it's fine.

This revision was not accepted when it landed; it landed in state Needs Review.Thu, Apr 16, 1:27 PM
This revision was automatically updated to reflect the committed changes.

Rebase after partial commit.

In D56365#1289902, @kib wrote:

An alternative for this O_SYMLINK is to define it just to O_PATH | O_NOFOLLOW, if it is not important to be able to open(<regular file>, O_SYMLINK | O_RDONLY) and be able to read from the resulting fd.
I would prefer that implementation instead of the reopening with EMPTYPATH for non-symlinks, but I do not know real-world usage patterns for O_SYMLINK.

It's hard to say... based on inspecting various uses, it seems like it's /usually/ expected to be used for things like applying acls/xattrs to the result, at least. read(2) from it does work if it's a regular file, though.

lib/libc/sys/openat.c
83 ↗(On Diff #175628)

XNU technically allows this, they have a test in xnu that exercises it, apparently because someone noticed that it was ignored with O_CREAT: https://github.com/apple-oss-distributions/xnu/blob/main/tests/vfs/open_symlink.c

kib edited the summary of this revision. (Show Details)

Retract ambitions of O_SYMLINK to O_PATH | O_NOFOLLOW.