Skip to content

fix(fs): fix FIFO hangs, overlay copy-up, and handle and mode bugs - #870

Merged
ewhauser merged 7 commits into
mainfrom
claude/fix-fs-review-074c78
Oct 19, 2026
Merged

ewhauser merged 7 commits into
mainfrom
claude/fix-fs-review-074c78

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Fixes the fs/ findings from the security and bug review against 83b31f1.

What changed

FIFOs no longer hang past timeout or cancel

  • In-memory FIFOs: blocking reads and writes now stop with the error of the context they were opened under. Data already in the pipe can still be read. Runtime.Run with Timeout now returns 124 for mkfifo /tmp/p; echo hi > /tmp/p, and cancel returns 130.
  • HostFS and ReadWriteFS open host entries with O_NONBLOCK (new fs/host_open_posix.go). Host FIFOs get a handle whose open, reads and writes wait in 20ms polls and stop when the context ends. A writer's open still waits for a reader, as open(2) would. Host devices, sockets and other special files are refused with EPERM.

OverlayFS copy-up

  • Copying up a lower regular file records its mode, owner, size and mtime but reads the content only when it is opened. A host file larger than --max-file-bytes can now be overwritten, truncated, chmodded, chowned, linked and renamed. Reading or appending to it still fails with EFBIG, the same as on the lower layer.
  • Every upper create (open with O_CREATE, Symlink, Link, Mkfifo, MkdirAll, Rename) first copies up lower parent directories with their mode, owner and mtime, as SPEC §10 requires. Before this, touch sub/new turned a host sub with mode 700 into 755.
  • Rename moves nodes that are already in the upper layer instead of copying them, so hard links and lazily copied files survive the move.
  • The lowerDirs cache is still trusted for whether a path prefix is a directory. That assumption is now written in the code and SPEC, and directory metadata copied up is always re-read from the lower layer.

MemoryFS / TrieFS

  • Open handles keep a pointer to the file itself, not its path, like a POSIX descriptor. exec 3>a; mv a b; echo hi >&3 now writes to b, and exec 4<c; rm c; echo new > c; cat <&4 reads the old content.
  • Caller-supplied perms are masked to permission plus setuid, setgid and sticky bits. Before this, MkdirAll(p, ModeSymlink|0755) (reachable from nodejs fs.mkdirSync) created corrupt dir+symlink nodes that could not be deleted.
  • TrieFS creating ops now fail with ENOENT/ENOTDIR instead of creating missing parents, matching MemoryFS and OverlayFS. Rename checks the parent before changing anything, so Rename("/a","/a/x/y") no longer leaves /a/x behind. Chmod keeps setuid, setgid and sticky.

Reviewer notes

  • newMemoryFIFOFile now takes ctx as its first argument.
  • Copied-up files now keep the lower file's mtime instead of getting the current time.
  • SPEC.md: localized bullets in §10 only.
  • Outside fs/, the only additions are two new test files: internal/runtime/fifo_timeout_test.go and internal/runtime/open_fd_binding_test.go.
  • examples/internal/agentfsfs/fifo.go has its own copy of the FIFO code with the same hang. It is not changed here.

Testing

  • make lint: clean.
  • go test ./fs/... ./internal/runtime/ passes, and go test -race ./fs/ passes. make build passes.
  • Each finding has a regression test that checks errors, output and filesystem effects.
  • Host FIFO handling was only run on macOS. Linux was cross-compiled with go vet but not run.
  • A full go test ./... also shows these failures, which are pre-existing or environmental:
    • the ripgrep/diff oracle tests need the Nix oracles;
    • scripts/bench-compare and the timing-sensitive TestRunCLIHostUtilityTail* tests also fail on the base commit.

CLI check of the repros:

$ gbash --root ro --max-file-bytes 100 -c 'echo x > big; cat big; chmod 600 big; mv big big2; touch sub/new; stat -c "%a %n" sub'
x
700 sub
$ gbash --readwrite-root R -c 'mkfifo /p; echo hi > /p & cat /p; wait; echo rc=$?'
hi
rc=0

@ewhauser
ewhauser enabled auto-merge (squash) October 19, 2026 18:11
@ewhauser
ewhauser merged commit ed5f677 into main Oct 19, 2026
17 checks passed
@ewhauser
ewhauser deleted the claude/fix-fs-review-074c78 branch October 19, 2026 18:14
@ewhauser ewhauser mentioned this pull request Oct 20, 2026
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.

1 participant