Repository navigation
fix: walk the data home repair without following a swapped symlink - #32944
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: running each Notes
[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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix changes the one string that is the cause, Not checked: whether BSD find on macOS runs What this change shipsInventory (4 items) — 4 justifiedIntent: make sure the
[FIRST-PRINCIPLES-REVIEWED] 8facdbb Description read[DESCRIPTION-READ] 136c9542b415da96fd08967674e3a2723776eb1b984a9a0442e427fcb84260dc That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
8e3a550 to
fcf8b47
Compare
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.
fcf8b47 to
8facdbb
Compare
|
On the design review notes for fcf8b47: both are now documented in the
|
bolichen97
left a comment
There was a problem hiding this comment.
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 -Pnever follows a symlink while walking, and-execdir chown -h ... \;runs eachchownon./<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-pathchownwould have done undersudo.\;instead of+because BSDfinddoes 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
findwith a fakechownthat 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'ssecure_path), and the-links 1race on macOS, as ashortcut:.
No product regex and no new restriction on any Kiro Crew path.
…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)
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/statusand the Bot create refusal. On main that line issudo find <home> -xdev ! -user <user> \( -type d -o -links 1 \) -exec chown -h <user> {} + && chmod -R u+rwX <home>.findcollects full path names andchownruns 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/etcbetween the walk and thechown.chown -hprotects 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
sudobecause 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
chmod -R u+rwXtail. It runs as the person, so it cannot change anything they do not already own.check_data_homedetects 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 atchowntime.The fix is
find -P <home> ... -execdir chown -h <user> {} \;:-Pmakes the walk never follow a symlink. This is GNU's default, and now it is stated explicitly.-execdirruns eachchownfrom 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-hkeeps 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 withsudo, which is a bigger surface than one changed shell line.fix_command's docstring and the repair-line description indocs/system-specs/modules/cli.mdare updated to match, and both now name the two limits the design review raised: GNU find's refusal of-execdirwith a relativePATHentry, 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 eachchownis 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_followedruns the root half of the real line (withoutsudo) against a temp home with a stand-inchownonPATH. The stand-in swapshome/afor a symlink to an outside directory as soon as it is asked to changea/f, then records whatchown -hwould change. The test asserts that the reala/fis still reached and that nothing outside the home is. With the old-exec ... +line it recordsoutside/fand fails.test_the_privileged_part_skips_hard_links_and_symlink_targetsnow pins-P,-execdir, the;terminator and the absence of-exec.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-Pand-execdir ... \;with the same meaning.GNU find refuses
-execdirwhenPATHcontains a relative entry. Undersudo,secure_path(the default on common distributions) sets an absolutePATH, 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 -Ron a user-writable tree)Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.