Repository navigation
fix(fs): harden file backends from second review - #890
Merged
Merged
Conversation
Cap writes at MaxFileBytes, bound in-memory FIFO buffers, require write on hard-link sources, stop host ReadDir blocking on FIFOs, apply the read cap to O_RDWR, resolve .. after symlinks, reject unsupported seeded type bits, refuse O_EXCL on dangling links, roll back failed cross-mount renames, refuse overlay symlinks over lower entries, mask cloned special modes, and fix a shared-handle read race.
Merged
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.
Fixes the fs/ and policy findings from the second review of main at 19ff56a.
User-visible behavior
CommandFS.OpenFilenow stop atMaxFileBytes. A write that crosses the cap stores what fits and then fails withFile too large.printf "%0200000d" 0 > bigunder--max-file-bytes 1024now fails, andcat /dev/zero > bigstops right away at 1024 bytes instead of running until the timeout. The cap is afs.LimitFileSizewrapper. It only exposesSeekandTruncatewhen the wrapped file has them, so callers that check for those methods keep their fallbacks.CommandFS.Linknow also requires write access to the source. Before, a link created in a writable root could be used to modify a file in a read-only root.O_DIRECTORY|O_NONBLOCK.gbash --readwrite-root DIR -c 'mkfifo /p; echo /p/*'no longer hangs.O_RDWR...after a symlink is now applied to the link's target, as POSIX does. This coversCommandFSoperations and the builtins' shared stat/open helpers.rm -rf /lnk/../datanow removes/a/data, like bash, instead of the top-level/data. The newCommandFS.ResolveAt(ctx, name)does this. Shell-level redirection paths are still cleaned lexically.EINVAL, which removes the nil children-map panic. FIFO and char-device bits are still allowed, because the snapshot clone path seeds device nodes on purpose.cloneSpecialFile) now keeps only the permission bits and the allowed type bits.O_CREATE|O_EXCLnow fails withEEXISTon a dangling symlink inMemoryFSandTrieFS, instead of creating the link's target.OverlayFS.Symlinknow fails withEEXISTwhen the lower layer already has the entry.memoryFile.Readnow advances the offset under the write lock.Notes
MemoryFSreturnsEEXISTfor it.fs/:commands/invocation_capabilities.gofor Link, the write cap andResolveAt;internal/shell/core.gofor capping redirections; andinternal/builtins/command_helpers.gofor physical...TestWCFiles0FromMaterializedReportsMaxFileBytesnow seeds its oversized file, since writing it is now refused.commands/AGENTS.mdare updated.Testing
go test -race ./fs/... ./policy/... ./commands/passes, with new regression tests for each finding.make lintis clean.