Repository navigation
reject hardlink and create/truncate opens on a read-only server - #682
Merged
Merged
Conversation
Collaborator
|
We should have resolved the flaky test. Please rebase. |
The ReadOnly() server option relies on readonly() to classify requests. [email protected] reported itself as read-only, and an OPEN was considered read-only whenever SSH_FXF_WRITE was absent, so a client of a read-only server could create hard links, create new files with SSH_FXF_READ|SSH_FXF_CREAT, and truncate existing files to zero bytes with SSH_FXF_READ|SSH_FXF_TRUNC. Treat hardlink as a write operation and SSH_FXF_CREAT/SSH_FXF_TRUNC as requiring write access.
likitha011
force-pushed
the
readonly-hardlink-creat-trunc
branch
from
October 19, 2026 08:37
9bdc0e0 to
9336ec5
Compare
Contributor
Author
|
Rebased onto current master. Same single commit, and |
puellanivis
approved these changes
Oct 19, 2026
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.
Repro: serve with
sftp.NewServer(rwc, sftp.ReadOnly()), then from the client callLink(existing, new),OpenFile(new, os.O_RDONLY|os.O_CREATE)orOpenFile(existing, os.O_RDONLY|os.O_TRUNC). All three succeed: the link and the new file are created, and the existing file is truncated to 0 bytes.Cause: the read-only gate in
sftpServerWorkertrustsreadonly().sshFxpExtendedPacketHardlink.readonly()returns true, andsshFxpOpenPacket.readonly()only looks atSSH_FXF_WRITE, whilerespondstill mapsSSH_FXF_CREAT/SSH_FXF_TRUNCtoO_CREATE/O_TRUNCon anO_RDONLYopen.Fix: report hardlink as a write, and treat
CREAT/TRUNCpflags as write access.TestReadOnlyServerRejectsWritesfails on master and passes with the patch.make integrationandmake integration_w_racepass locally on macOS (apart from the existingTestClientReadDir/TestRequestStatVFSflakes, which also show up on master).