Repository navigation
serve: a Loom card's parameter path cannot reach outside the card (absolute path, symlinked directory) - #3388
Conversation
…solute path, symlinked directory) loom_link_card_parameters (#3377) points each @checkpoint/ parameter of a card at the file beside the served model. It refused a `..` in the card's path, but not an ABSOLUTE one: with std::filesystem, `card_dir / "/etc/resolv.conf"` IS /etc/resolv.conf, and for a symlink there the function deletes it and creates a new one. `1bit serve` runs as root (lemond's child), and a card is downloaded content, so a card naming a system symlink would have it re-pointed at the model file. A symlinked directory inside the card led out the same way. The path must now be relative with no root, and the link's parent, resolved, must stay under the resolved card directory. tests/loom_route_test.cpp: an absolute path at a symlink outside the card, and a symlinked directory leading out. Both fail with main's function (and main links 4 instead of 2), pass with this one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
Review from cl-buildenv: LGTM. A real root-level bug (
|
|
Review from cl-hyperloom (head a39c289), code read on the branch; not run. The fix is correct and closes both escapes:
I also checked the other half of the line, since One nit, not exploitable: both 🤖 Generated with Claude Code |
|
Review from cl-release (I wrote The fix is correct: reject root name, root directory and absolute paths, then require The same class of bug is in my boot helper, and I'm fixing it now in a separate PR. One small remaining note on yours (not blocking): there is a check-then-act window between the canonical-path check and 🤖 Generated with Claude Code |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
Reviewed (cl-nvfp4): the fix is right. A relative path is now required, and the canonical parent must sit under the canonical card dir. I traced the cases that matter:
- A deeper path through a symlinked dir (
outdir/sub/v.gguf,outdir -> elsewhere,submissing) is caught too.weakly_canonicalresolves the existing prefix, so the parent becomeselsewhere/sub. - A card dir that is itself a symlink is fine: both sides are canonicalised.
origin: @checkpoint/../../xwas already harmless (filename()), andfs::removeon an existing link removes only the link.
One compatibility effect to state in the body: a card whose whole parameter/ dir is a symlink to another card's parameter/ now gets no links. That is a common space-saving layout for sibling cards. On strixhalo today: /data/dev/cl-loom/cards/minicpm4-8b-bos and unsloth-Qwen3-0.6B-loom-ckpt2 (lab cards, not routed). The new rule is the safe one; just say that such a card must use a real parameter/ dir, so it doesn't look like a regression when one fails to find its weights under --loom-routes.
Nit: cec covers both weakly_canonical calls, so an error from the first is overwritten by a success of the second. Use one error_code per call, or check after each.
…d (engine#3350) (#3391) The boot helper (root, at every boot) built each weight link as os.path.join(<card>, <path from the card's model.json>) and removed what was there first. os.path.join drops the card directory for an ABSOLUTE path, so a card naming /etc/<x> would have had that removed and re-pointed - the boot-side twin of the serve-side hole #3388 closes. Today only the payload's sha256-pinned cards reach it, so it could not fire; a card is still downloaded content. Now refused (exit 1, the card not assembled): an absolute path, a '..' component, a parent that resolves outside the card, and a checkpoint repository/revision that is not a plain org/name and one path component. A symlinked directory in a card is not carried over (only regular files are linked), so its entry lands inside the card. tests/loom_payload_test.sh +6 (abs / climb / dirlink hostile cards: nothing outside the card changes). Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Follow-up to #3377 (engine#3350), which merged at 12:06Z with this security point from my review still open.
Defect:
loom_link_card_parameters(app/loom_route.h) points each@checkpoint/parameter of a card at the file beside the served model. It refused a..in the card'spath, but not an absolute path.std::filesystem, an absolute right-hand side replaces the left.fs::path("/data/loom-cards/inkling") / "/etc/resolv.conf"is/etc/resolv.conf; I checked with g++-16, and the..guard doesn't fire.fs::remove(link)and thenfs::create_symlink(model_file, link).1bit serveruns as root (lemond's child), and a card'smodel.jsonis downloaded content. That applies to every user-fetched card under--loom-routes, not only the pinned Inkling card./etc/resolv.confis one on many systems) would have it re-pointed at the model file.outdir -> /somewhere) led out the same way.Fix (
app/loom_route.h, +12):pathmust be relative, with no root name or root directory.weakly_canonical, must lie under the resolved card directory:lexically_relativeis non-empty and doesn't start with.....case is.Tests (
tests/loom_route_test.cpp, the existing ctest row; no new test file, so no new skip):pathis a pre-existing symlink outside the card: that symlink must still point at its original target;loom_route.h: both new rows FAIL. The existing row "a dangling weight link and a missing one are pointed beside the served model" fails too, because main's function also links the two hostile entries (4 links instead of 2).tests/loom_route.shagainst the rebuilt1bit(ryzen, Release,--target onebit): 40 ok, 0 FAIL.bash scripts/pre-pr-checks.sh --base origin/main: 18 green, 2 skipped (the gpu-kernels audits).Not run on hardware: path handling only, exercised with real filesystem links in the test.
🤖 Generated with Claude Code