Page MenuHomeFreeBSD

Add O_RESOLVE_NO_SYMLINKS open flag
AbandonedPublic

Authored by walker.aj325_gmail.com on Jan 4 2024, 2:12 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Nov 25, 12:34 AM
Unknown Object (File)
Oct 22 2024, 12:21 AM
Unknown Object (File)
Oct 22 2024, 12:21 AM
Unknown Object (File)
Oct 22 2024, 12:20 AM
Unknown Object (File)
Oct 22 2024, 12:20 AM
Unknown Object (File)
Oct 21 2024, 10:44 PM
Unknown Object (File)
Oct 18 2024, 3:44 AM
Unknown Object (File)
Oct 4 2024, 7:44 PM
Subscribers

Details

Reviewers
kib
brooks
Summary

This is required for Samba 4.17 and higher. Internally samba uses the openat2 flag RESOLVE_NO_SMYLINKS as an optimization to create a fast-path for opening files that helps mitigate a Samba 4.13+ metadata performance regression due to symlink safety checks. This commit adds an open flag equivalent to the MNT_NOSYMLINKFOLLOW mount flag.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

open(2) should be updated to describe the flag. Probably additional text explaining the difference with O_NOFOLLOW would be useful as well.

Does the same flag needed for *at() syscalls?

sounds like the thing to do is to add openat2 so that this automagically works, instead of a freebsd-specific flag

In D43313#987417, @mjg wrote:

sounds like the thing to do is to add openat2 so that this automagically works, instead of a freebsd-specific flag

Yes, that is a better solution in general. I'm not sure how many Linux applications other than Samba use openat2 since glibc doesn't currently have a wrapper for it (samba uses syscall(2) to call it), but maybe in future it will be more common.

In D43313#987356, @kib wrote:

open(2) should be updated to describe the flag. Probably additional text explaining the difference with O_NOFOLLOW would be useful as well.

Does the same flag needed for *at() syscalls?

I don't think a corresponding _at flag is needed needed (unless someone has particular use-case for it). Good point about manpage, totally slipped my mind.

I can possibly submit a minimal openat2() implementation that only supports existing resolve flags for now (for example: RESOLVE_BENEATH, RESOLVE_NO_SYMLINK) if decision is firm that we don't want to add more path-resolution flags for open(2).

Linux folk explicitly designed openat2 to be extensible, so I expect it is going to pick up explicit "official" usage down the road.

That said, I think a minimal initial implementation is the way to go here.

Add openat2() syscall that wraps around kern_openat.

In D43313#987766, @mjg wrote:

Linux folk explicitly designed openat2 to be extensible, so I expect it is going to pick up explicit "official" usage down the road.

That said, I think a minimal initial implementation is the way to go here.

I uploaded a minimal implementation. Basically, I opted to to use an internal open flag to pass to kern_openat rather than adding kern_openat2 or significantly changing kern_openat. Very basic testing seems to work. If you don't have concerns with implementing in this manner, I will start working on a manpage and tests.

Please

  1. Move addition of the open2 syscall into a new review.
  2. Do not put changes to generated files into the diff (it should be committed as an additional commit anyway).
  3. I very much dislike internal openat flag. Please add a new flag2 argument for kern_openat(9) (and perhaps vn_open_cred() but might be not needed right now) and pass a new flag there.
lib/libc/sys/openat2.c
5 ↗(On Diff #132488)

Definitely not, I know.

sys/kern/vfs_syscalls.c
1128 ↗(On Diff #132488)

Why - ?

1130 ↗(On Diff #132488)
sys/sys/openat2.h
52 ↗(On Diff #132488)
57 ↗(On Diff #132488)
In D43313#988667, @kib wrote:

Please

  1. Move addition of the open2 syscall into a new review.
  2. Do not put changes to generated files into the diff (it should be committed as an additional commit anyway).
  3. I very much dislike internal openat flag. Please add a new flag2 argument for kern_openat(9) (and perhaps vn_open_cred() but might be not needed right now) and pass a new flag there.

Okay. I will make the requested changes into new review and link add reference to here. Sorry about the copy-pasted copyright in header. E2BIG is specified response in Linux manpage for this situation.

E2BIG is specified response in Linux manpage for this situation.

I mean that - is not needed for passing FreeBSD errno code (unlike Linux).

Per feedback, this reverts syscall-related changes and restores original diff. Will create new diff for syscall.