Repository navigation
feat(fast_io): expose openat2_supported() probe helper (SEC-1.d) - #4643
Merged
Merged
Conversation
Extract the cached `openat2(2)` availability probe from
`secure_dir::linux::try_openat2` into a new `linux_capabilities` module so
that the SEC-1.e..j cutover sites (`renameat2`, `linkat`, `unlinkat`, etc.)
share a single source of truth instead of each reinventing the probe.
The helper issues one no-op `openat2(AT_FDCWD, ".", { resolve: 0 })`
syscall on first call, caches the outcome in a `OnceLock<bool>`, and is
thread-safe. `ENOSYS` maps to "unsupported"; any other errno still proves
the syscall reached the kernel and is recorded as supported. On non-Linux
Unix targets the helper is a compile-time `false` so callers stay
platform-portable behind a single `#[cfg(unix)]` gate.
`secure_dir::try_openat2` now defers to `openat2_supported()` for the
gating decision; the inline `OnceLock` is gone.
6 tasks done
5 tasks
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
Extract the cached `openat2(2)` availability probe from
`secure_dir::linux::try_openat2` into a new `linux_capabilities` module so
that the SEC-1.e..j cutover sites (`renameat2`, `linkat`, `unlinkat`, etc.)
share a single source of truth instead of each reinventing the probe.
The helper issues one no-op `openat2(AT_FDCWD, ".", { resolve: 0 })`
syscall on first call, caches the outcome in a `OnceLock<bool>`, and is
thread-safe. `ENOSYS` maps to "unsupported"; any other errno still proves
the syscall reached the kernel and is recorded as supported. On non-Linux
Unix targets the helper is a compile-time `false` so callers stay
platform-portable behind a single `#[cfg(unix)]` gate.
`secure_dir::try_openat2` now defers to `openat2_supported()` for the
gating decision; the inline `OnceLock` is gone.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extracts the
openat2(2)runtime-availability probe out ofsecure_dir::linux::try_openat2(added in #4618 for SEC-1.c) into a newfast_io::linux_capabilitiesmodule, exposed aspub fn openat2_supported() -> bool. The probe issues one no-opopenat2(AT_FDCWD, ".", { resolve: 0 })syscall on first call, caches the outcome in aOnceLock<bool>, and is thread-safe.ENOSYSmaps to "unsupported"; any other errno proves the syscall reached the kernel and is recorded as supported. On non-Linux Unix targets the helper is a compile-timefalseso callers stay platform-portable behind a single#[cfg(unix)]gate.secure_dir::try_openat2now defers toopenat2_supported()for the gating decision; the inlineOnceLockis gone, and the cached probe result is shared with every future SEC-1 call site.Why
SEC-1.e..j (#2523-#2528) will add
*atsyscall wrappers forrenameat2,linkat,unlinkat,mkdirat,symlinkat, andfchownat. Each one needs to pick between the strict-resolution*2variant and the non-*2fallback based on kernel support. Sharing one probe avoids per-call-site re-detection and keeps the seccomp-rejected-syscall handling uniform.Test plan
cargo fmt --allcargo clippy --workspace --all-targets --all-features --no-deps -- -D warningscleancargo nextest run -p fast_io --features io_uring -E 'test(openat2_supported) or test(secure_dir)'- 6 passedcargo nextest run -p fast_io --all-features- 394 passedfalseshort-circuit assertion.Notes
#[cfg(unix)]per the task brief; Linux uses a real probe, every other Unix target compiles to a constantfalse. Windows is excluded entirely (NTFS handle-based APIs per the SEC-1.l audit).unsafescope wrapping the three FFI touches (zero-initopen_how,syscall(SYS_openat2, ...),close) with one combinedSAFETYcomment.