Skip to content

reject hardlink and create/truncate opens on a read-only server - #682

Merged
puellanivis merged 1 commit into
pkg:masterfrom
likitha011:readonly-hardlink-creat-trunc
Oct 19, 2026
Merged

puellanivis merged 1 commit into
pkg:masterfrom
likitha011:readonly-hardlink-creat-trunc

Conversation

@likitha011

Copy link
Copy Markdown
Contributor

Repro: serve with sftp.NewServer(rwc, sftp.ReadOnly()), then from the client call Link(existing, new), OpenFile(new, os.O_RDONLY|os.O_CREATE) or OpenFile(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 sftpServerWorker trusts readonly(). sshFxpExtendedPacketHardlink.readonly() returns true, and sshFxpOpenPacket.readonly() only looks at SSH_FXF_WRITE, while respond still maps SSH_FXF_CREAT/SSH_FXF_TRUNC to O_CREATE/O_TRUNC on an O_RDONLY open.
Fix: report hardlink as a write, and treat CREAT/TRUNC pflags as write access. TestReadOnlyServerRejectsWrites fails on master and passes with the patch. make integration and make integration_w_race pass locally on macOS (apart from the existing TestClientReadDir/TestRequestStatVFS flakes, which also show up on master).

@puellanivis

Copy link
Copy Markdown
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
likitha011 force-pushed the readonly-hardlink-creat-trunc branch from 9bdc0e0 to 9336ec5 Compare October 19, 2026 08:37
@likitha011

Copy link
Copy Markdown
Contributor Author

Rebased onto current master. Same single commit, and TestRequestStatVFS now passes locally alongside TestReadOnlyServerRejectsWrites.

@puellanivis
puellanivis merged commit de6aa98 into pkg:master Oct 19, 2026
4 checks passed
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