Skip to content

feat(fast_io): expose openat2_supported() probe helper (SEC-1.d) - #4643

Merged
oferchen merged 1 commit into
masterfrom
feat/fast-io-openat2-supported-sec1d
May 21, 2026
Merged

oferchen merged 1 commit into
masterfrom
feat/fast-io-openat2-supported-sec1d

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

Extracts the openat2(2) runtime-availability probe out of secure_dir::linux::try_openat2 (added in #4618 for SEC-1.c) into a new fast_io::linux_capabilities module, exposed as pub fn openat2_supported() -> bool. The probe 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 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, and the cached probe result is shared with every future SEC-1 call site.

Why

SEC-1.e..j (#2523-#2528) will add *at syscall wrappers for renameat2, linkat, unlinkat, mkdirat, symlinkat, and fchownat. Each one needs to pick between the strict-resolution *2 variant and the non-*2 fallback 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 --all
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings clean
  • cargo nextest run -p fast_io --features io_uring -E 'test(openat2_supported) or test(secure_dir)' - 6 passed
  • cargo nextest run -p fast_io --all-features - 394 passed
  • New tests cover: stable return across calls, 1024-iteration cache hammer, 8-thread race, and a non-Linux false short-circuit assertion.

Notes

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.
@github-actions github-actions Bot added the enhancement New feature or request label May 21, 2026
@oferchen
oferchen merged commit 9147da9 into master May 21, 2026
55 checks passed
@oferchen
oferchen deleted the feat/fast-io-openat2-supported-sec1d branch May 21, 2026 07:18
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant