Skip to content

FD corruption experiments#6576

Draft
theduke wants to merge 4 commits into
mainfrom
fd-corruption
Draft

FD corruption experiments#6576
theduke wants to merge 4 commits into
mainfrom
fd-corruption

Conversation

@theduke

@theduke theduke commented May 7, 2026

Copy link
Copy Markdown
Collaborator
  • fix stdio fd_close ordering race
  • fix stale fd cleanup removals
  • fix stale fd cleanup removals

theduke added 3 commits May 7, 2026 13:01
Close stdio descriptors before flushing so an async flush cannot remove a newer fd mapping installed at the same number. Add a regression test that keeps the replacement fd alive while the original stdout flush is still in flight.
Rely on close_fd() as the only fd-map removal path during async cleanup so close_all() and close_cloexec_fds() cannot delete descriptors created mid-cleanup. Keep the regression test enabled to guard the reproduced stale-clear race.
Copilot AI review requested due to automatic review settings May 7, 2026 11:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses file-descriptor (FD) reuse races during close/cleanup in WASIX by ensuring flush operations operate on captured file handles rather than fd numbers that may be reallocated concurrently.

Changes:

  • Refactors fd_close to close the FD first while retaining a flush handle, preventing async flush/close from impacting a newly-reused fd number.
  • Updates WasiFs::close_all and WasiFs::close_cloexec_fds to snapshot targets, remove them from the fd map under a write lock, then flush via captured handles to avoid stale cleanup removing newly-created/reused FDs.
  • Adds regression tests covering fd-slot reuse and concurrent descriptor creation during cleanup.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.

File Description
lib/wasix/src/syscalls/wasi/fd_close.rs Introduces close_fd_and_prepare_flush and adds a regression test for stdio fd reuse during delayed flush.
lib/wasix/src/fs/mod.rs Reworks cleanup routines to remove FDs before flushing via captured targets; adds tests for concurrent creation and fd-slot reuse during cleanup.

Comment thread lib/wasix/src/syscalls/wasi/fd_close.rs
@theduke theduke marked this pull request as draft May 7, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants