Skip to content

config: preserve execute bit when self-protection locks a file - #172

Merged
codeyevsky merged 3 commits into
mainfrom
pr98-hamza
Oct 27, 2026
Merged

codeyevsky merged 3 commits into
mainfrom
pr98-hamza

Conversation

@codeyevsky

Copy link
Copy Markdown
Member

Summary

Self-protection locked the guard binary down to 0400 on Linux whenever chattr +i failed, which is the common case in containers and rootless installs. That strips the execute bit, so the launcher finds the binary but cannot exec it, and the guard fail-closes on every tool call until someone manually chmods it back.

Root cause

protectedTargets() (packages/core/install/paths.go) includes the guard binary path alongside config/settings files. lockFile() (packages/core/config/protect.go) runs chattr +i first, then unconditionally chmods to 0400 regardless of whether chattr succeeded. When chattr fails, that chmod is the one that actually applies, and it removes execute along with write.

Fix

Chmod to 0500 instead of 0400. This matches the windows branch of the same function, which already grants RX, and protectpaths.go's LockPath, which already uses 0500 on directories for exactly this reason. Write access is what self-protection needs to deny, not execute.

Test plan

  • go test ./config/... ./install/... in packages/core
  • go build ./... across every module in the workspace
  • Reproduced live on a real machine. A fresh install left the guard binary at mode 0400 with no execute bit, and the guard fail-closed on every tool call with "no guard binary found". Chmod 0500 by hand restored normal operation, confirming this is the exact bug.

lockFile's Linux fallback chmod'd every protected target to 0400
whenever chattr +i failed (no CAP_LINUX_IMMUTABLE, e.g. containers
and rootless installs), which is the common case. protectedTargets()
includes the guard binary, so every such install silently produced a
non-executable guard. The launcher found the file but could not exec
it, and the guard fail-closed on every tool call.

Use 0500 instead, matching the windows branch, which already grants
RX, and protectpaths.go's LockPath, which uses 0500 on directories
for the same reason. Write access is what self-protection needs to
deny, not execute.

Signed-off-by: codeyevsky <cinaryildirim2006@outlook.com>
@codeyevsky
codeyevsky requested a review from qarademir as a code owner October 27, 2026 18:15
@sonarqubecloud

Copy link
Copy Markdown

@codeyevsky
codeyevsky merged commit 8458514 into main Oct 27, 2026
35 checks passed
@codeyevsky
codeyevsky deleted the pr98-hamza branch October 27, 2026 18:38
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