Skip to content

Stop ps from exposing process argv#269

Merged
AlexandreYang merged 4 commits into
mainfrom
ps-vuln
May 22, 2026
Merged

Stop ps from exposing process argv#269
AlexandreYang merged 4 commits into
mainfrom
ps-vuln

Conversation

@AlexandreYang

@AlexandreYang AlexandreYang commented May 22, 2026

Copy link
Copy Markdown
Member

What does this PR do?

  • Stops ps from reading /proc//cmdline on Linux and kern.procargs2 argv on macOS.
  • Makes CMD report only the process comm/executable name across Linux, macOS, and Windows.
  • Deletes argv-reading helpers, updates docs/feature metadata, and cleans stale analysis allowlist entries.

Motivation

Allowed ps could expose other processes' CLI arguments, including tokens commonly passed as flags. The secure default is to avoid argv entirely.

Before / After

Observed excerpt from running the actual command with a controlled process in the same session:

./rshell --allow-all-commands -c "ps"

Before this change, CMD included full argv:

   PID TTY              TIME CMD
 78381 ?            00:00:00 /Users/alexandre.yang/.pyenv/versions/3.10.13/bin/python3 -c import time; time.sleep(30) --token=RSHELL_DEMO_SECRET_BEFORE
 78382 ?            00:00:00 ./rshell --allow-all-commands -c ps

After this change, CMD contains only the process comm/executable name:

   PID TTY              TIME CMD
 78528 ?            00:00:00 python3.10
 78529 ?            00:00:00 rshell

Testing

  • make fmt
  • go test ./builtins/ps ./builtins/internal/procinfo ./builtins/tests/ps
  • go test ./tests/ -run 'TestShellScenarios/cmd/ps' -timeout 120s
  • TMPDIR=/Users/alexandre.yang/worktrees/rshell/ps-vuln/.tmp RSHELL_BASH_TEST=1 go test ./tests/ -run TestShellScenariosAgainstBash -timeout 120s
  • GOOS=linux GOARCH=amd64 go test -c ./builtins/ps -o /tmp/rshell-ps-linux.test
  • GOOS=windows GOARCH=amd64 go test -c ./builtins/internal/procinfo -o /tmp/rshell-procinfo-windows.test.exe
  • go test ./...

Checklist

  • Tests added/updated
  • Documentation updated

@AlexandreYang AlexandreYang changed the title Fix ps Stop ps from exposing process argv May 22, 2026
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented May 22, 2026

Copy link
Copy Markdown

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 1 Pipeline job failed

Static Analysis Verification | Static Analysis Label Check   View in Datadog   GitHub Actions

🛟 This job is unlikely to succeed on retry. Please review your pipeline configuration. Files in analysis/ have been modified but the 'verified/analysis' label is missing, blocking PR merge.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: c3ce251 | Docs | Datadog PR Page | Give us feedback!

@AlexandreYang

Copy link
Copy Markdown
Member Author

@codex review this PR

Please use the following severity format for all findings:

  • P0 (red): Exploitable vulnerability with high impact (RCE, sandbox bypass, data breach). Blocking merge.
  • P1 (orange): Likely exploitable or high-risk — correctness bugs vs bash, data races, panics.
  • P2 (yellow): Potential vulnerability, bash divergence, missing test coverage, missing docs.
  • P3 (blue): Style, minor simplification, hardening suggestion, nice-to-have test.

Prefix each finding title with its priority label, e.g. "P0: ...", "P1: ...", etc.
Include a summary table at the top with columns: # | Priority | File | Finding.

@AlexandreYang

Copy link
Copy Markdown
Member Author

Iteration 1 self-review result: 0 P0 findings, 0 P1 findings, 0 P2 findings, 0 P3 findings.

Summary: reviewed the ps argv leak mitigation across Linux, macOS, and Windows. The implementation now uses process comm/executable names only, removes argv readers, updates documentation, and includes regression coverage for secret-bearing cmdline data.

@AlexandreYang AlexandreYang left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Review Summary

Reviewed the PR diff for the ps argv leak mitigation.

Overall assessment: safe to merge.

# Priority File Finding
No findings

Coverage Summary

Code path Test Status
Linux ps ignores /proc//cmdline argv and reports stat comm builtins/ps/ps_procpath_linux_test.go Covered
Linux ps handles missing cmdline using unbracketed comm builtins/ps/ps_procpath_linux_test.go Covered
macOS kinfo conversion uses P_comm only builtins/internal/procinfo/procinfo_darwin_test.go Covered
Windows process entry conversion uses executable name only builtins/internal/procinfo/procinfo_windows_test.go Covered
Docs and feature metadata describe the argv-safe behavior README.md, SHELL_FEATURES.md, builtins/features.go Covered by review

P0/P1/P2 findings: 0

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@AlexandreYang

Copy link
Copy Markdown
Member Author

@codex review this PR

Please use the following severity format for all findings:

  • P0 (red): Exploitable vulnerability with high impact (RCE, sandbox bypass, data breach). Blocking merge.
  • P1 (orange): Likely exploitable or high-risk — correctness bugs vs bash, data races, panics.
  • P2 (yellow): Potential vulnerability, bash divergence, missing test coverage, missing docs.
  • P3 (blue): Style, minor simplification, hardening suggestion, nice-to-have test.

Prefix each finding title with its priority label, e.g. "P0: ...", "P1: ...", etc.
Include a summary table at the top with columns: # | Priority | File | Finding.

@AlexandreYang

Copy link
Copy Markdown
Member Author

Iteration 1 self-review result: 0 P0 findings, 0 P1 findings, 0 P2 findings, 0 P3 findings.

Summary: reviewed the ps argv leak mitigation across Linux, macOS, and Windows. The implementation uses process comm/executable names only, removes argv readers, updates docs/feature metadata, and includes regression coverage for secret-bearing cmdline data.

@AlexandreYang AlexandreYang left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Review Summary

Reviewed the current PR diff for the ps argv leak mitigation.

Overall assessment: safe to merge.

# Priority File Finding
No findings

Coverage Summary

Code path Test Status
Linux ps ignores /proc//cmdline argv and reports stat comm builtins/ps/ps_procpath_linux_test.go Covered
Linux ps handles missing cmdline using unbracketed comm builtins/ps/ps_procpath_linux_test.go Covered
macOS kinfo conversion uses P_comm only builtins/internal/procinfo/procinfo_darwin_test.go Covered
Windows process entry conversion uses executable name only builtins/internal/procinfo/procinfo_windows_test.go Covered
Docs and feature metadata describe argv-safe behavior README.md, SHELL_FEATURES.md, builtins/features.go Covered by review

P0/P1/P2 findings: 0

@AlexandreYang

Copy link
Copy Markdown
Member Author

Review-Fix Loop Summary

Iteration log

# Unresolved threads P0/P1/P2 findings Fixes applied CI status
1 0 0 Failing: Static Analysis Label Check

Final state

  • Unresolved threads: 0 (trusted authors counted only)
  • P0/P1/P2 findings: 0 (P3 findings are not blocking)
  • CI: Failing due to Static Analysis Label Check; CodeQL and Analyze checks pass; mergegate is pending.

Remaining issues

  • Human review must add verified/analysis for the intentional analysis/symbols_internal.go allowlist cleanup. I did not add labels from the agent side.

@AlexandreYang
AlexandreYang marked this pull request as ready for review May 22, 2026 15:03
@AlexandreYang AlexandreYang added the verified/analysis Human-reviewed static analysis changes label May 22, 2026
@AlexandreYang
AlexandreYang added this pull request to the merge queue May 22, 2026
Merged via the queue into main with commit 00bdc03 May 22, 2026
40 of 41 checks passed
@AlexandreYang
AlexandreYang deleted the ps-vuln branch May 22, 2026 18:20
AlexandreYang added a commit that referenced this pull request May 26, 2026
- Stops ps from reading /proc/<pid>/cmdline on Linux and kern.procargs2
argv on macOS.
- Makes CMD report only the process comm/executable name across Linux,
macOS, and Windows.
- Deletes argv-reading helpers, updates docs/feature metadata, and
cleans stale analysis allowlist entries.

Allowed ps could expose other processes' CLI arguments, including tokens
commonly passed as flags. The secure default is to avoid argv entirely.

Observed excerpt from running the actual command with a controlled
process in the same session:

```bash
./rshell --allow-all-commands -c "ps"
```

Before this change, `CMD` included full argv:

```text
   PID TTY              TIME CMD
 78381 ?            00:00:00 /Users/alexandre.yang/.pyenv/versions/3.10.13/bin/python3 -c import time; time.sleep(30) --token=RSHELL_DEMO_SECRET_BEFORE
 78382 ?            00:00:00 ./rshell --allow-all-commands -c ps
```

After this change, `CMD` contains only the process comm/executable name:

```text
   PID TTY              TIME CMD
 78528 ?            00:00:00 python3.10
 78529 ?            00:00:00 rshell
```

- make fmt
- go test ./builtins/ps ./builtins/internal/procinfo ./builtins/tests/ps
- go test ./tests/ -run 'TestShellScenarios/cmd/ps' -timeout 120s
- TMPDIR=/Users/alexandre.yang/worktrees/rshell/ps-vuln/.tmp
RSHELL_BASH_TEST=1 go test ./tests/ -run TestShellScenariosAgainstBash
-timeout 120s
- GOOS=linux GOARCH=amd64 go test -c ./builtins/ps -o
/tmp/rshell-ps-linux.test
- GOOS=windows GOARCH=amd64 go test -c ./builtins/internal/procinfo -o
/tmp/rshell-procinfo-windows.test.exe
- go test ./...

- [x] Tests added/updated
- [x] Documentation updated
gh-worker-dd-mergequeue-cf854d Bot pushed a commit to DataDog/datadog-agent that referenced this pull request May 26, 2026
### What does this PR do?

[backport] rshell v0.0.14-1 to fix ps

Rshell release link: https://github.com/DataDog/rshell/releases/tag/v0.0.14-1

### Motivation

Backport needed for this fix: DataDog/rshell#269

### Describe how you validated your changes

### Additional Notes


Co-authored-by: axel.vonengel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

verified/analysis Human-reviewed static analysis changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants