Skip to content

feat: implement O_TMPFILE + linkat for anonymous temp file writes - #2918

Merged
oferchen merged 1 commit into
masterfrom
feat/o-tmpfile-anonymous-write
Mar 22, 2026
Merged

oferchen merged 1 commit into
masterfrom
feat/o-tmpfile-anonymous-write

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Add open_anonymous_tmpfile(dir, mode) - opens an unnamed inode via O_TMPFILE | O_WRONLY | O_CLOEXEC using libc::open
  • Add link_anonymous_tmpfile(fd, dest) - materializes the anonymous file at the final path via linkat(AT_FDCWD, "/proc/self/fd/N", AT_FDCWD, dest, AT_SYMLINK_FOLLOW)
  • Add o_tmpfile_available(dir) - probes filesystem support with process-wide atomic cache
  • All functions gated with #[cfg(target_os = "linux")]; non-Linux stubs return io::ErrorKind::Unsupported
  • Re-exported from fast_io crate root for consumer convenience

This eliminates the crash-window vulnerability of named temp files: the destination path either appears atomically with full content (via linkat) or does not appear at all (kernel reclaims the anonymous inode). No cleanup needed on failure, no name collisions possible.

Test plan

  • Linux unit tests: probe consistency, open/link roundtrip, EEXIST on existing dest, mode bits preservation
  • CI validates compilation on all platforms (Linux, macOS, Windows)
  • CI runs Linux-gated tests via nextest

@github-actions github-actions Bot added the enhancement New feature or request label Mar 21, 2026
@oferchen
oferchen force-pushed the feat/o-tmpfile-anonymous-write branch from 2b1e476 to a85f99a Compare March 22, 2026 08:05
Add open_anonymous_tmpfile() and link_anonymous_tmpfile() to fast_io
for atomic file creation on Linux 3.11+. The anonymous file has no
directory entry until linkat materializes it, eliminating crash-window
partial files and temp name collisions.

Includes o_tmpfile_available() probe with process-wide atomic cache,
non-Linux stubs returning Unsupported, and Linux-gated unit tests.
@oferchen
oferchen force-pushed the feat/o-tmpfile-anonymous-write branch from a85f99a to cfd98ef Compare March 22, 2026 08:59
@oferchen
oferchen merged commit 97432ea into master Mar 22, 2026
4 of 9 checks passed
@oferchen
oferchen deleted the feat/o-tmpfile-anonymous-write branch March 22, 2026 09:00
oferchen added a commit that referenced this pull request May 1, 2026
)

Add open_anonymous_tmpfile() and link_anonymous_tmpfile() to fast_io
for atomic file creation on Linux 3.11+. The anonymous file has no
directory entry until linkat materializes it, eliminating crash-window
partial files and temp name collisions.

Includes o_tmpfile_available() probe with process-wide atomic cache,
non-Linux stubs returning Unsupported, and Linux-gated unit tests.
oferchen added a commit that referenced this pull request May 5, 2026
)

Add open_anonymous_tmpfile() and link_anonymous_tmpfile() to fast_io
for atomic file creation on Linux 3.11+. The anonymous file has no
directory entry until linkat materializes it, eliminating crash-window
partial files and temp name collisions.

Includes o_tmpfile_available() probe with process-wide atomic cache,
non-Linux stubs returning Unsupported, and Linux-gated unit tests.
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