Skip to content

fix: walk the data home repair without following a swapped symlink - #32944

Merged
bolichen97 merged 1 commit into
mainfrom
crew/slack/data-home-chown-race
Nov 8, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
crew/slack/data-home-chown-race

Conversation

@buluoray

@buluoray buluoray commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The data home repair line can no longer be tricked into giving a system path to the person's account.

When the data home holds files another account owns (an earlier sudo kirocrew ... run), Kiro Crew shows one repair line in the gateway log, kirocrew doctor, /api/status and the Bot create refusal. On main that line is sudo find <home> -xdev ! -user <user> \( -type d -o -links 1 \) -exec chown -h <user> {} + && chmod -R u+rwX <home>. find collects full path names and chown runs on them later, as root. Anything that can write the data home, including an agent, can swap a parent directory inside it for a symlink to a system directory such as /etc between the walk and the chown. chown -h protects only the last name, so root then re-owns the file under the system directory. This was raised in review of the 0.12.0 release batch.

Why it matters

The person runs this line with sudo because we told them to. A data home is writable by the agent, so a prompt-injected agent could turn the repair into a way to take ownership of root-owned system files on that machine.

Not a goal

  • Replacing the shell line with a new CLI command or an fd-relative Python repair. The line stays copyable as it is today.
  • Changing the user-run chmod -R u+rwX tail. It runs as the person, so it cannot change anything they do not already own.
  • Changing what check_data_home detects or how the line is shown.

What changed (motivation → approach → change)

Symptom: the root half of the repair resolves full path names after the walk. Root cause: -exec ... {} + passes <home>/a/b/f, and every directory in that path is resolved again at chown time.

The fix is find -P <home> ... -execdir chown -h <user> {} \;:

  • -P makes the walk never follow a symlink. This is GNU's default, and now it is stated explicitly.
  • -execdir runs each chown from inside the directory find is already holding, on ./<name>. A parent swapped for a symlink after the walk entered it is never resolved again, and -h keeps the last name from being followed.
  • \; instead of +, because BSD find (macOS) does not batch -execdir.

I considered an os.fwalk + os.chown(dir_fd=..., follow_symlinks=False) repair as well. It needs a new privileged CLI entry point that people would run with sudo, which is a bigger surface than one changed shell line.

fix_command's docstring and the repair-line description in docs/system-specs/modules/cli.md are updated to match, and both now name the two limits the design review raised: GNU find's refusal of -execdir with a relative PATH entry, and the hard-link time-of-check gap below.

Backwards compatibility

Compatible: the line is still one copyable sudo find ... && chmod ... command that re-owns the same entries; only how each chown is invoked changes.

Removes nothing: the same entries are selected and re-owned; no key, field or route changes.

Tests

  • test_a_parent_swapped_for_a_symlink_mid_repair_is_not_followed runs the root half of the real line (without sudo) against a temp home with a stand-in chown on PATH. The stand-in swaps home/a for a symlink to an outside directory as soon as it is asked to change a/f, then records what chown -h would change. The test asserts that the real a/f is still reached and that nothing outside the home is. With the old -exec ... + line it records outside/f and fails.
  • test_the_privileged_part_skips_hard_links_and_symlink_targets now pins -P, -execdir, the ; terminator and the absence of -exec.
  • The two prefix assertions now expect sudo find -P.

Proof: PROVEN test/test_data_home_owner.py::test_files_another_account_owns_are_reported_with_the_fix, test/test_data_home_owner.py::test_the_privileged_part_skips_hard_links_and_symlink_targets, test/test_data_home_owner.py::test_a_parent_swapped_for_a_symlink_mid_repair_is_not_followed, test/test_data_home_owner.py::test_a_linked_home_is_checked_and_repaired_at_its_real_folder (head 8facdbb)

Manual verification

Ran the new test with GNU findutils 4.8.0 on Linux. It passes with the fix and fails on the old line, where the stand-in records outside/f. I did not run it on macOS. BSD find supports -P and -execdir ... \; with the same meaning.

GNU find refuses -execdir when PATH contains a relative entry. Under sudo, secure_path (the default on common distributions) sets an absolute PATH, so the line runs as shown.

builder-security checked: this change opens no listener, port or auth path. The skill's fix-what-you-find rule applies, and that is this PR.

Related Issues

Raised in review of #32825.

Sibling sweep

Swept: git grep -nE "sudo[^"']*chown|chown -R|exec chown" -- src/ scripts/ website/src
Sibling: src/kiro_crew/cloud/ssm.py:442 -- not affected -- it gives a third account's install tree to root, so a swapped symlink can only hand a path to root, never take one from it
Sibling: src/kiro_crew/dashboard/source_providers/runner.py:190 -- not affected -- it gives a root-created system directory to root; nothing the agent writes is on that path

Pattern harvest

Rule candidate: review-prompt
Pattern: a privileged command that acts on full path names inside a tree a less-privileged writer controls (sudo find ... -exec <cmd> {} +, sudo chown -R on a user-writable tree)

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners November 8, 2026 05:19
@buluoray
buluoray requested a review from Zedmor November 8, 2026 05:19
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 8facdbb9a67d522a0dc840adc62e7ea4e503c882 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 8facdbb9a67d522a0dc840adc62e7ea4e503c882 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: running each chown through -execdir on ./<name> stops the walk-then-chown race through a swapped parent directory, the line can still be copied as-is, and the PR documents its remaining limits.

Notes

  • The hard-link gap the docstring admits (-links 1 is checked during the walk, so on macOS a file swapped for a hard link before its chown is still re-owned) can only close with the fd-relative repair the PR rules out. Open an issue for it so the "shortcut:" note has an owner.

[DESIGN-REVIEWED] 8facdbb

Description read

[DESCRIPTION-READ] 04c0996dbb40bbda30934d76a2fb012f90cf1c9bdf8392316f90fdb87df5ee5d

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 8facdbb9a67d522a0dc840adc62e7ea4e503c882 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. The fix changes the one string that is the cause, fix_command, in the code. No second copy of the repair line exists, and no default or capability changes.

Not checked: whether BSD find on macOS runs -P and -execdir ... \; as described.

What this change ships

Inventory (4 items) — 4 justified

Intent: make sure the sudo repair line Kiro Crew suggests for a data home owned by another account can't be turned into a way to take ownership of system files through a symlink swapped in during the repair. FIX.

  1. The suggested repair line now runs find -P … -execdir chown -h <user> {} \; instead of -exec chown -h <user> {} + — justified
  2. The fix_command docstring and cli.md now state the two limits that remain: a relative PATH entry, and the hard-link window — justified
  3. A regression test replays the swap race against the real line and fails on the old -exec … + form — justified
  4. The existing tests that check the line's position and prefix now expect -P, -execdir, ; and no -exec — justified

[FIRST-PRINCIPLES-REVIEWED] 8facdbb

Description read

[DESCRIPTION-READ] 136c9542b415da96fd08967674e3a2723776eb1b984a9a0442e427fcb84260dc

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 8facdbb9a67d522a0dc840adc62e7ea4e503c882 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 8facdbb

Verdict parsed from the review's SHA-scoped output markers for commit 8facdbb9a67d522a0dc840adc62e7ea4e503c882.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 8facdbb9a67d522a0dc840adc62e7ea4e503c882 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 8facdbb9a67d522a0dc840adc62e7ea4e503c882 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 8facdbb

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 8facdbb9a67d522a0dc840adc62e7ea4e503c882 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 8, 2026
@buluoray
buluoray force-pushed the crew/slack/data-home-chown-race branch from 8e3a550 to fcf8b47 Compare November 8, 2026 05:36
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 8, 2026
The data home repair line ran `sudo find <home> ... -exec chown -h
<user> {} +`, which hands chown full path names after the walk. Anything
that can write the home could swap a parent directory for a symlink to a
system path in between, and root would re-own that path.

The line now uses `find -P` and `-execdir chown -h <user> {} \;`: the
walk never follows a symlink, and each chown runs inside the entry's own
directory on `./<name>`, so a swapped parent is never resolved. A new
test replays the swap with a stand-in chown and fails on the old line.
@buluoray
buluoray force-pushed the crew/slack/data-home-chown-race branch from fcf8b47 to 8facdbb Compare November 8, 2026 05:58
@buluoray

buluoray commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

On the design review notes for fcf8b47: both are now documented in the fix_command docstring (as a shortcut: note) and in cli.md, in 8facdbb.

  • Hard links: -links 1 is still checked during the walk, so a file swapped for a hard link to a root-owned file before its chown is re-owned where the kernel lets that link be made. Linux's default fs.protected_hardlinks=1 refuses to create a link to a file the writer does not own; macOS has no such setting. This gap existed before this PR and is outside its goal, which is the symlinked-parent race. Closing it needs the fd-relative repair command listed under Not a goal.
  • PATH: GNU find refuses -execdir when PATH holds a relative entry. Under sudo with secure_path this does not happen, and where it does, find exits with an error before it changes anything.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 8, 2026
@buluoray
buluoray requested a review from bolichen97 November 8, 2026 07:10

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving head 8facdbb. The gate shows 103 checks passed. The 4 red entries are cancelled duplicate runs, and each of those checks has a newer successful run on this head.

This changes only the repair line fix_command prints for the person to run, not any check Kiro Crew enforces:

  • find -P never follows a symlink while walking, and -execdir chown -h ... \; runs each chown on ./<name> from inside the entry's own directory. A parent swapped for a symlink to a system path after the walk entered it is therefore not followed, which a full-path chown would have done under sudo. \; instead of + because BSD find does not batch -execdir.
  • The selection is unchanged: other-account entries only, -xdev, and a non-directory only while -links 1.
  • The new test runs the real find with a fake chown that swaps the parent mid-walk, and asserts nothing outside the home is touched.
  • The docstring and spec name the two remaining limits: GNU find's relative-PATH refusal (avoided by sudo's secure_path), and the -links 1 race on macOS, as a shortcut:.

No product regex and no new restriction on any Kiro Crew path.

@bolichen97
bolichen97 merged commit 3c09c74 into main Nov 8, 2026
103 of 107 checks passed
@bolichen97
bolichen97 deleted the crew/slack/data-home-chown-race branch November 8, 2026 07:16
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 8, 2026
buluoray added a commit that referenced this pull request Nov 8, 2026
…32944)

The data home repair line ran `sudo find <home> ... -exec chown -h
<user> {} +`, which hands chown full path names after the walk. Anything
that can write the home could swap a parent directory for a symlink to a
system path in between, and root would re-own that path.

The line now uses `find -P` and `-execdir chown -h <user> {} \;`: the
walk never follows a symlink, and each chown runs inside the entry's own
directory on `./<name>`, so a swapped parent is never resolved. A new
test replays the swap with a stand-in chown and fails on the old line.

(cherry picked from commit 3c09c74)
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