Skip to content

fix(util): avoid UID/GID wraparound when parsing process credentials#3808

Merged
fiftin merged 1 commit intodevelopfrom
cursor/critical-bug-inspection-3318
May 5, 2026
Merged

fix(util): avoid UID/GID wraparound when parsing process credentials#3808
fiftin merged 1 commit intodevelopfrom
cursor/critical-bug-inspection-3318

Conversation

@cursor
Copy link
Copy Markdown

@cursor cursor Bot commented Apr 28, 2026

Summary

Fixes incorrect handling of UID/GID strings from user.Lookup when configuring child process credentials.

Bug and impact

  • Scenario: process.user is set to a Linux account whose UID or GID string is outside the uint32 range (for example 4294967296), or is otherwise non-numeric.
  • Impact: strconv.Atoi succeeds for large values, then uint32(u) silently truncates (e.g. 42949672960). GetSysProcAttr then sees uid <= 0 and does not set syscall.Credential, so git/ansible children may run as the wrong user (no privilege drop). That is a security/correctness failure on systems with unusual UID assignments.

Root cause

UID/GID from the password database are strings. Parsing with strconv.Atoi + uint32() allows wraparound; the removed u <= math.MaxUint32 check did not help because MaxUint32 equals int max on typical 64-bit Go, so overflow already happened at Atoi for larger strings.

Fix

  • Parse with strconv.ParseUint(s, 10, 32) so values that do not fit in 32 bits are rejected instead of truncated.
  • Centralized in parseLinuxCredentialUint with unit tests.

Validation

  • go test ./util/... -short
Open in Web View Automation 

user.Lookup returns string UIDs. strconv.Atoi followed by uint32()
truncates values > MaxUint32 (e.g. 4294967296 becomes 0), which could
skip dropping privileges or apply wrong credentials. Use ParseUint
with 32-bit width and add tests.

Co-authored-by: Denis Gukov <fiftin@outlook.com>
@fiftin fiftin marked this pull request as ready for review April 28, 2026 18:12
Copy link
Copy Markdown
Author

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security review (automation)

Outcome: No medium, high, or critical vulnerabilities identified in the added or modified code.

What changed: parseLinuxCredentialUint replaces strconv.Atoi + uint32() for passwd-derived UID/GID. The previous pattern could silently wrap values ≥ 2³² to 0 (root) when setting syscall.Credential. The new path uses strconv.ParseUint(s, 10, 32), which rejects out-of-range values and rejects 0, avoiding truncation/wraparound.

Prior threads: Previous automation security-review threads were cleared so this assessment is the active one.

Slack-style summary: PR3808 security pass — no exploitable issues in diff; change closes a credential truncation/wrap risk on Linux process credentials.

Open in Web View Automation 

Sent by Cursor Automation: Find vulnerabilities

@fiftin fiftin merged commit 8822421 into develop May 5, 2026
19 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