Skip to content

fix(agent): do not hand a pty to a wrapped owner id - #6987

Merged
otavio merged 1 commit into
masterfrom
fix/pty-owner-uid-bound
Aug 29, 2026
Merged

fix(agent): do not hand a pty to a wrapped owner id#6987
otavio merged 1 commit into
masterfrom
fix/pty-owner-uid-bound

Conversation

@otavio

@otavio otavio commented Aug 29, 2026

Copy link
Copy Markdown
Member

What

ptyStartOptions converted a uint32 uid to int for gliderssh.WithOwner, which hands it to os.Chown. The conversion is now bounded.

Why

int is 32 bits on a 32-bit build, and the agent ships for ARM. An id above MaxInt32 wraps negative, and 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. 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)-1 is 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:gosec that suppressed nothing — gosec does not raise G115 here, so the directive silenced a linter that was never speaking. nolintlint flagged 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 //nolint looks like it documents a decision.

Testing

TestPtyStartOptionsBoundsTheOwnerID covers 1000, MaxInt32, MaxInt32+1 and MaxUint32, plus a non-root case. Verified it fails without the bound: widening the check to MaxUint32 fails exactly the two cases that should wrap.

Agent lints and tests clean under both docker and native.

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.
@github-actions

github-actions Bot commented Aug 29, 2026

Copy link
Copy Markdown

Code Review Complete

The 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 /review.

View job

@otavio
otavio merged commit e848f93 into master Aug 29, 2026
37 checks passed
@otavio
otavio deleted the fix/pty-owner-uid-bound branch August 29, 2026 13:28
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