Repository navigation
heavy: minors from the #764 reviews (#767) - #770
Conversation
- As root, a HOME others can write to (/tmp) or / is not used for the state folder; ~/.local must be a real folder of this user's before heavy makes ~/.local/state under it (a planted link is never followed). - The timeout check covers iter(pipe.readline), enumerate/map/zip/ filter/join over a pipe, `import subprocess as sp`, getoutput, os.waitpid/wait4 without WNOHANG and a bound wait/communicate passed on; its claim is narrowed to the listed forms. The two os.waitpid uses in the tests now go through a timed wait_pid. - Note cleanup checks labelled/, heavy/ and the base, like heavy's own folder rule. - With nothing sent by hand, a 1 s look instead of none, so processes that end anyway are not named as still running. - README: how to give back a root-owned ~/.local/state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lens A (safety and bypass), head c2e1eff: SAFEVerdict: SAFE. Nothing blocking and nothing major. I found two minors and two nits. Each one fails closed or needs root to be set up oddly, and none is new in this PR. What I ran (temp worktree, each run gated on
|
Lens B (correctness and tests), head c2e1eff: SAFEVerdict: SAFE. Nothing blocking and nothing major. All three items and the nits are fixed as the body says. Each fix line I removed made its test go red. The findings below are small gaps around What I ranAll runs were in a temporary worktree, each gated on
The two copies of the folder rule
No false refusal for a normal user? (probed with
|
| HOME | Second notes folder |
|---|---|
| a 0755 home | yes |
| HOME a symlink to a 0755 home | yes (os.stat follows it; the realpath is not /) |
| a 2755 (setgid) home | yes |
<home>/./ |
yes |
| a 0770 home (group can write) | no: falls back to the passwd home, as designed |
~/.local a symlink to the user's own folder (stow, HPC scratch) |
no (minor 1) |
an existing ~/.local/state that is 0775 (umask 002) |
no (not new: main does the same) |
NFS or odd owners: a home owned by someone else, such as nobody under idmap, is skipped the same way as before. That is not new.
Timeout check
- The table: every sample form passes, and today's files have no findings.
measure.test.pyandfake_tools.pyare also clean, although Hygiene does not read them (nit 3). - Named forms written differently, all caught:
'\n'.join(l for l in p.stdout)iter(p.stderr.readline, b'')import subprocess as sp; sp.getstatusoutput(...)import subprocess as s2; addCleanup(s2.run, [...])for i, l in enumerate(p.stdout)os.wait4(pid, 0)addCleanup(proc.communicate, b'x')os.wait()(caught by thewait()rule)
- The claim: now narrowed to the table, which holds. Forms outside the table still get through:
with subprocess.Popen(...) as q:(its exit waits with no time limit),from os import waitpid,import os as o,os.wait3,os.waitid,p.stdout.buffer.read(),read1,readinto,os.read(p.stdout.fileno(), n),shutil.copyfileobj(p.stdout, f), andout = p.stdout; out.read(). None of them is in today's files. One false alarm is possible:executor.submit(ev.wait)is flagged.
SETTLE
- Bounded: it runs only after a step that sent nothing, so there are at most 2 steps (TERM and KILL), each at most 1 s plus one 50 ms poll.
leftis re-read on each poll, so the returned list is the latest one, and an empty list stops at once. When pidfds are missing butcgroup.killis there, the KILL now comes 1 s later than before. That is harmless.
State question
- Runs again:
.local, the base andheavy/labelledare reused (FileExistsErroris passed over, then lstat-checked). A second sweep removes nothing more (tested). - Stopped half-way: a
.localmade with nostateyet is checked again and finished on the next run. A note behind a linked or open parent stays (tested). - Old, empty or missing state: a missing home, a 1777 home,
/, a planted.locallink and a root-owned~/.local/stateare each covered and fail closed. Two gaps: the README fix misses an old root-owned~/.local(minor 2), and~/.localis now made 0700 where makedirs made it 0755 or 0775. That is harmless.
Blocking
None.
Major
None.
Minor
fork-kit/heavy/bin/heavy:395-402(own_folder, make_base): a symlinked~/.localis refused, even one that points at the user's own folder.- Who it hits:
~/.local -> /scratch/$USER/.local(HPC homes with small quotas) and stow-style dotfiles are common. Those users silently get no second notes folder. That costs nothing while/run/userworks, but it removes the fallback this folder exists for. - Why the check adds little now: a planted link needs a home that someone else can write, and
state_basenow refuses such a home. - Suggested fix: follow the link, then require the target to be a folder this user owns that no one else can write. That still blocks root following a link into a victim's or a root-owned folder, because the owner or mode check fails there. Or keep the refusal but name it in
heavy doctorordocker-label's reason. - Documented: the README says "
~/.localmust be a real folder (not a link)", so this is a design choice to confirm, not a bug.
- Who it hits:
fork-kit/heavy/README.md:64: the repair line fixes only~/.local/state.- Why it falls short: an older heavy (
os.makedirs(base)as root with a user's HOME) also made~/.localroot-owned when it was missing. The new.localcheck then refuses it, and the user cannot make~/.local/shareeither. - Suggested fix:
sudo chown "$USER:" ~/.local && sudo chown -R "$USER:" ~/.local/state. The chown on.localis not recursive, and it is a no-op when.localis already the user's.
- Why it falls short: an older heavy (
Nits
- One rule, two copies, at
~/.local: heavy (bin/heavy:401) checks.local(a real folder of this uid, with no mode check), whilenote_in(lib/heavy_sweep.py:1263) andprune_notes(:950) do not check it at all. The effect is harmless: docker-label's note there is rejected by the HEAVY_MARKS dev:ino check, and the prune touches only same-user files. But a 0777~/.localpasses heavy's check, while every other level requires& 0o022clear. Add the mode check, so all levels use the same rule. - README:72 says "a 1 s look": it is up to 1 s per step, so 2 s in all when neither pidfds nor
cgroup.killis there. tests/heavy.test.py:1380(Hygiene.FILES, not new): it omitsmeasure.test.pyandfake_tools.py. Both are clean today. A glob overtests/*.pywould keep a new test file from being missed.untimeddocstring (tests/heavy.test.py:1310-1318): "any read of a process's stdout or stderr" is wider than the rules..buffer.read(),read1,readintoandos.read(fileno)get through. Say "read/readline/readlines of" instead.- The
HOME=/root row (tests/heavy.test.pystate-folder test): under real root (CI), a regression would make/.local/state/heavy/labelledon the runner before the test fails. Mockingos.mkdirfor the/row, or usingSTATE_ROOTthere, would keep a failing run clean.
Read-only review: nothing pushed or installed, and nothing run as root. The temporary worktree and scratch copies were removed.
- As root, a HOME others can write to (/tmp) or / is not used for the state folder; ~/.local must be a real folder of this user's before heavy makes ~/.local/state under it (a planted link is never followed). - The timeout check covers iter(pipe.readline), enumerate/map/zip/ filter/join over a pipe, `import subprocess as sp`, getoutput, os.waitpid/wait4 without WNOHANG and a bound wait/communicate passed on; its claim is narrowed to the listed forms. The two os.waitpid uses in the tests now go through a timed wait_pid. - Note cleanup checks labelled/, heavy/ and the base, like heavy's own folder rule. - With nothing sent by hand, a 1 s look instead of none, so processes that end anyway are not named as still running. - README: how to give back a root-owned ~/.local/state. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
- As root, a HOME others can write to (/tmp) or / is not used for the state folder; ~/.local must be a real folder of this user's before heavy makes ~/.local/state under it (a planted link is never followed). - The timeout check covers iter(pipe.readline), enumerate/map/zip/ filter/join over a pipe, `import subprocess as sp`, getoutput, os.waitpid/wait4 without WNOHANG and a bound wait/communicate passed on; its claim is narrowed to the listed forms. The two os.waitpid uses in the tests now go through a timed wait_pid. - Note cleanup checks labelled/, heavy/ and the base, like heavy's own folder rule. - With nothing sent by hand, a 1 s look instead of none, so processes that end anyway are not named as still running. - README: how to give back a root-owned ~/.local/state. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
- As root, a HOME others can write to (/tmp) or / is not used for the state folder; ~/.local must be a real folder of this user's before heavy makes ~/.local/state under it (a planted link is never followed). - The timeout check covers iter(pipe.readline), enumerate/map/zip/ filter/join over a pipe, `import subprocess as sp`, getoutput, os.waitpid/wait4 without WNOHANG and a bound wait/communicate passed on; its claim is narrowed to the listed forms. The two os.waitpid uses in the tests now go through a timed wait_pid. - Note cleanup checks labelled/, heavy/ and the base, like heavy's own folder rule. - With nothing sent by hand, a 1 s look instead of none, so processes that end anyway are not named as still running. - README: how to give back a root-owned ~/.local/state. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
What and why
Fixes the minors and the small nits from the two #764 reviews, at the root.
HOME=/tmp(root's, but 1777), another user could plant/tmp/.localas a link first, and root would make empty root-owned folders where it points.state_base(inbin/heavyandlib/heavy_sweep.py, the same rule) now also requires a home that no group or other user can write, and not/(lens B nit 1). SoHOME=/tmpandHOME=/fall through to the passwd home.~/.local/state, heavy makes~/.localwithmkdirand checks it withlstat: a real folder this user owns. A planted.locallink is never followed, even in a home only root can write.iter(p.stdout.readline, '')(any uncalled read of a pipe),enumerate/map/zip/filter/''.joinand similar over a pipe,import subprocess as sp,getoutput/getstatusoutput(no timeout at all),os.waitpid/os.wait4withoutWNOHANG, and a boundwait/communicatepassed on (addCleanup(p.wait)). The claim is narrowed: the check promises the forms in its sample table (test_the_check_finds_each_listed_form), not every way Python can wait. The two existingos.waitpiduses now go through a newwait_pidhelper with a time limit.prune_notesnow requireslabelled/,heavy/and the base each to be a real folder of this user's that no one else can write, like heavy's own folder rule.cgroup.kill, heavy still looks for 1 s (SETTLE) after a step that sent nothing, so processes that systemd's failed stop already signalled are not named "still running" while they end. Still no 30 s grace wait.~/.local/statean older heavy left (sudo chown -R "$USER:" ~/.local/state).lstatin the note cleanup (lens B nit 3): a note that links to an old empty file stays.Lens B nits 2 (a dry run does not count notes) and 4 (the
HEAVY_KEEPabsence check) are left out to keep this small.Tests
Run on this branch (each under the machine's capacity gate):
heavy.test.pyParts + Hygiene: 13 OKsweep.test.py: 82 OK, 1 skipped (includes RedCheck with two new rules)install.test.py16 OK,queue.test.py70 OK,measure.test.py47 OKheavy.test.pyrun (HEAVY_REAL_TESTS=1) is left to CI.Red on the old code. The new tests against
origin/main'sbin/heavyandlib/heavy_sweep.py:[pid]named as still running)Each fix line goes red when removed (each in a scratch copy, named test run):
not st.st_mode & 0o022on the home (heavy)test_the_state_folder_is_made_only_in_a_home_this_user_ownsrealpath(home) != '/'(heavy).locallstat check inown_folderSETTLE = 1to0test_processes_that_end_a_moment_later_are_not_named_still_runningjoin, uncalled read,import as, getoutput, waitpid, bound wait)test_the_check_finds_each_listed_formwait_pidback toos.waitpid(pid, 0)test_every_wait_for_a_test_process_has_a_timeoutlstatMUTATIONS(automatic)Root is only mocked (
getuid/geteuid0, and this user's files read as root's); nothing runs as root.State question.
.localmade but nostateyet is checked and used next time; a note behind a linked or open parent stays until the folder is fixed./, a planted.locallink and a root-owned~/.local/statefrom an older heavy (skipped; README says how to fix) are each covered.fork-seam-check.cjs --config-ref origin/main origin/main HEADpasses;vp fmt --checkon the README passes.General vs project
All general:
fork-kit/heavyhas no project facts, and nothing here is project-specific.Closes #767
🤖 Generated with Claude Code