fix(agent): do not hand a pty to a wrapped owner id - #6987
Merged
Conversation
ptyStartOptions converted a uint32 uid to int for gliderssh.WithOwner, which passes it to os.Chown. int is 32 bits on a 32-bit build, and the agent ships for ARM, so an id above MaxInt32 wraps negative. os.Chown reads a negative id as "leave this alone", so the pty would quietly stay owned by the agent while the code read as though it had been handed over. No real account has such an id, and (uid_t)-1 is explicitly not one, so the hand-over is skipped rather than attempted with a wrapped value. Found by CodeQL (go/incorrect-integer-conversion), which had been reporting it for a while behind a //nolint:gosec that suppressed nothing: gosec does not raise G115 here, so the directive silenced a linter that was never speaking.
Code Review CompleteThe automated review ran but did not post an updated summary — this usually means no new issues were found since the previous review. If you've pushed changes and want a fresh pass, comment |
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.
What
ptyStartOptionsconverted auint32uid tointforgliderssh.WithOwner, which hands it toos.Chown. The conversion is now bounded.Why
intis 32 bits on a 32-bit build, and the agent ships for ARM. An id aboveMaxInt32wraps negative, andos.Chownreads a negative id as "leave this alone" — so the pty would quietly stay owned by the agent while the code read as though it had been handed over. A silent no-op is the worst shape for this: the failure looks like success.No real account has such an id, and
(uid_t)-1is explicitly not one, so the hand-over is skipped rather than attempted with a wrapped value.How it was found
CodeQL (
go/incorrect-integer-conversion) has been reporting it, behind a//nolint:gosecthat suppressed nothing — gosec does not raise G115 here, so the directive silenced a linter that was never speaking.nolintlintflagged the directive as unused in #6986, which is what surfaced the finding.Two tools, two answers, and the suppression named the one that had nothing to say. Worth remembering when a
//nolintlooks like it documents a decision.Testing
TestPtyStartOptionsBoundsTheOwnerIDcovers 1000,MaxInt32,MaxInt32+1andMaxUint32, plus a non-root case. Verified it fails without the bound: widening the check toMaxUint32fails exactly the two cases that should wrap.Agent lints and tests clean under both
dockerandnative.