Skip to content

fix(security): 2 improvements across 2 files#1377

Open
tomaioo wants to merge 13 commits into
agntcy:mainfrom
tomaioo:fix/security/pid-file-trust-can-allow-signaling-arbit
Open

fix(security): 2 improvements across 2 files#1377
tomaioo wants to merge 13 commits into
agntcy:mainfrom
tomaioo:fix/security/pid-file-trust-can-allow-signaling-arbit

Conversation

@tomaioo
Copy link
Copy Markdown

@tomaioo tomaioo commented Apr 22, 2026

Summary

fix(security): 2 improvements across 2 files

Problem

Severity: Medium | File: cli/cmd/daemon/stop.go:L24

The runStop function reads a PID from a PID file and unconditionally sends SIGTERM to that process ID after a basic liveness check. If an attacker can tamper with the PID file (or if it becomes stale and PID is reused), this can terminate an unintended process. This is especially risky when the CLI is run with elevated privileges.

Solution

Harden PID handling by validating process identity before signaling (e.g., verify executable path/command line matches daemon binary, optionally verify start time), ensure PID file is created with strict permissions/ownership, and reject PID files not owned by expected user.

Changes

  • cli/cmd/daemon/stop.go (modified)
  • cli/cmd/export/format/skill.go (modified)

tomaioo added 2 commits April 21, 2026 23:21
- Security: PID file trust can allow signaling arbitrary processes
- Security: Potential path traversal in batch export file path construction

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
- Security: PID file trust can allow signaling arbitrary processes
- Security: Potential path traversal in batch export file path construction

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
@tomaioo tomaioo requested a review from a team as a code owner April 22, 2026 06:21
@github-actions github-actions Bot added the size/S Denotes a PR that changes 50-199 lines label Apr 22, 2026
Comment thread cli/cmd/daemon/stop.go
Comment on lines +83 to +86
targetExe, err := os.Readlink(fmt.Sprintf("/proc/%d/exe", pid))
if err != nil {
return fmt.Errorf("failed to verify process identity for pid %d: %w", pid, err)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

will this only work on certain os/architectures? my concern is that the daemon will no longer work for windows

Comment thread cli/cmd/daemon/stop.go
return nil
}

func validateDaemonProcess(pid int) error {
Copy link
Copy Markdown
Contributor

@tkircsi tkircsi Apr 22, 2026

Choose a reason for hiding this comment

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

Thanks @tomaioo for the PR! My concern is it only checks “same executable path”, not “same daemon process”. Since dirctl is a single multi-command binary, any other live dirctl process can satisfy that predicate. Besides the validation of the binary identity, we should validate the subcommand identity, start time, PID-file ownership, or another daemon-specific marker.

@tomaioo
Copy link
Copy Markdown
Author

tomaioo commented Apr 22, 2026

Great callout — the strict PID identity checks (e.g., /proc executable/start-time validation) are Unix-specific, so they should not be applied unconditionally. I’ll split this behind OS-specific helpers/build tags (*_unix.go / *_windows.go) so Windows keeps a compatible stop path and doesn’t regress. I’ll also add a Windows CI check to verify daemon stop still works.

… is it only checks “

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
@tomaioo
Copy link
Copy Markdown
Author

tomaioo commented Apr 22, 2026

Great callout — the strict PID identity checks (e.g., /proc executable/start-time validation) are Unix-specific, so they should not be applied unconditionally. I’ll split this behind OS-specific helpers/build tags (*_unix.go / *_windows.go) so Windows keeps a compatible stop path and doesn’t regress. I’ll also add a Windows CI check to verify daemon stop still works.

… is it only checks “

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
@tomaioo
Copy link
Copy Markdown
Author

tomaioo commented Apr 23, 2026

Great callout — the strict PID identity checks (e.g., /proc executable/start-time validation) are Unix-specific, so they should not be applied unconditionally. I’ll split this behind OS-specific helpers/build tags (*_unix.go / *_windows.go) so Windows keeps a compatible stop path and doesn’t regress. I’ll also add a Windows CI check to verify daemon stop still works.

… is it only checks “

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
@tomaioo
Copy link
Copy Markdown
Author

tomaioo commented Apr 23, 2026

Great callout — the strict PID identity checks (e.g., /proc executable/start-time validation) are Unix-specific, so they should not be applied unconditionally. I’ll split this behind OS-specific helpers/build tags (*_unix.go / *_windows.go) so Windows keeps a compatible stop path and doesn’t regress. I’ll also add a Windows CI check to verify daemon stop still works.

… is it only checks “

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
@ramizpolic
Copy link
Copy Markdown
Member

@tomaioo i think your agent is bugging :D

@tomaioo
Copy link
Copy Markdown
Author

tomaioo commented Apr 23, 2026

Great callout — the strict PID identity checks (e.g., /proc executable/start-time validation) are Unix-specific, so they should not be applied unconditionally. I’ll split this behind OS-specific helpers/build tags (*_unix.go / *_windows.go) so Windows keeps a compatible stop path and doesn’t regress. I’ll also add a Windows CI check to verify daemon stop still works.

… is it only checks “

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
@tomaioo
Copy link
Copy Markdown
Author

tomaioo commented Apr 23, 2026

Great callout — the strict PID identity checks (e.g., /proc executable/start-time validation) are Unix-specific, so they should not be applied unconditionally. I’ll split this behind OS-specific helpers/build tags (*_unix.go / *_windows.go) so Windows keeps a compatible stop path and doesn’t regress. I’ll also add a Windows CI check to verify daemon stop still works.

… is it only checks “

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
@tomaioo
Copy link
Copy Markdown
Author

tomaioo commented Apr 24, 2026

Great callout — the strict PID identity checks (e.g., /proc executable/start-time validation) are Unix-specific, so they should not be applied unconditionally. I’ll split this behind OS-specific helpers/build tags (*_unix.go / *_windows.go) so Windows keeps a compatible stop path and doesn’t regress. I’ll also add a Windows CI check to verify daemon stop still works.

… is it only checks “

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
@tomaioo
Copy link
Copy Markdown
Author

tomaioo commented Apr 24, 2026

Great callout — the strict PID identity checks (e.g., /proc executable/start-time validation) are Unix-specific, so they should not be applied unconditionally. I’ll split this behind OS-specific helpers/build tags (*_unix.go / *_windows.go) so Windows keeps a compatible stop path and doesn’t regress. I’ll also add a Windows CI check to verify daemon stop still works.

… is it only checks “

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
@tomaioo
Copy link
Copy Markdown
Author

tomaioo commented Apr 24, 2026

Great callout — the strict PID identity checks (e.g., /proc executable/start-time validation) are Unix-specific, so they should not be applied unconditionally. I’ll split this behind OS-specific helpers/build tags (*_unix.go / *_windows.go) so Windows keeps a compatible stop path and doesn’t regress. I’ll also add a Windows CI check to verify daemon stop still works.

… is it only checks “

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
@tomaioo
Copy link
Copy Markdown
Author

tomaioo commented Apr 24, 2026

Great callout — the strict PID identity checks (e.g., /proc executable/start-time validation) are Unix-specific, so they should not be applied unconditionally. I’ll split this behind OS-specific helpers/build tags (*_unix.go / *_windows.go) so Windows keeps a compatible stop path and doesn’t regress. I’ll also add a Windows CI check to verify daemon stop still works.

… is it only checks “

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
@github-actions github-actions Bot added size/M Denotes a PR that changes 200-999 lines and removed size/S Denotes a PR that changes 50-199 lines labels Apr 24, 2026
@tomaioo
Copy link
Copy Markdown
Author

tomaioo commented Apr 25, 2026

Great callout — the strict PID identity checks (e.g., /proc executable/start-time validation) are Unix-specific, so they should not be applied unconditionally. I’ll split this behind OS-specific helpers/build tags (*_unix.go / *_windows.go) so Windows keeps a compatible stop path and doesn’t regress. I’ll also add a Windows CI check to verify daemon stop still works.

… is it only checks “

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 200-999 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants