Skip to content

1bit-loom-cards: a card's parameter path cannot reach outside the card (engine#3350) - #3391

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-release/loom-cards-path-guard
Nov 23, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-release/loom-cards-path-guard

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

The boot-side twin of #3388 (cl-kernel's fix to serve's loom_link_card_parameters). Both are mine from #3377. Part of #3350.

Defect: embed/usr/local/bin/1bit-loom-cards runs as root at every boot (10lemonade). It built each weight link as os.path.join(<card dir>, <path from the card's model.json>) and first removed whatever was at that path. Python's os.path.join discards the card directory for an absolute component, so a card naming /etc/<something> would have had that removed and re-pointed. A .. component led out the same way.

  • Exposure today: none in practice. Only the payload's sha256-pinned cards (os/v3/puppy/loom-cards.pin) reach the helper.
  • But a card is downloaded content, and the helper should not trust it.

Fix: a parameter entry is refused (exit 1, the card is not assembled and not half-built) when any of these hold:

  • its path is absolute;
  • it has a .. component;
  • its parent resolves (realpath) outside the card;
  • the checkpoint's repository or revision is not a plain org/name and one path component (these become parts of the link's target).
    A symlinked directory inside a source card is never carried over (only regular files are linked), so such an entry is created inside the card. The test covers that case too.

Measured:

  • tests/loom_payload_test.sh (ctest loom_payload): 20/20 under dash with env -i and under busybox ash. 6 new checks, three hostile cards against a link the machine owns outside the card:
    • absolute path: refused, the outside link untouched;
    • ../../ path: refused, untouched;
    • symlinked directory: the entry lands inside the card, untouched.
  • The real r8 Inkling card, staged from the 0.3.0 wheel and its 14 pinned files, still assembles: exit 0, both parameter/ links into $HF_HOME/hub/models--unsloth--Inkling-2-Mini-GGUF/snapshots/….
  • bash scripts/pre-pr-checks.sh --base origin/main (after committing): 17 green, 3 skipped.

🤖 Generated with Claude Code

…d (engine#3350)

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: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3350 - Partially compliant

Compliant requirements:

  • The PR implements a security fix for parameter path validation in loom-cards that prevents paths from escaping the card boundaries
  • This prevents potential privilege escalation or file system access issues when cards are downloaded content
  • The fix ensures that cards cannot create symbolic links outside their designated scope, which is crucial for the security of the pause/resume functionality

Non-compliant requirements:

  • The PR does not directly implement the Laya-driven pause/resume logic or the holding of client requests
  • The PR does not implement the actual model pausing/resuming mechanism or the agent session management
  • The PR does not include the release-check row or laya-auto passing functionality

Requires further human verification:

  • The actual integration of Laya-driven pause/resume functionality needs to be verified in the full system
  • The behavior of client request holding during model transitions needs to be tested in a real scenario
  • The release-check row and laya-auto passing functionality needs to be validated in the full deployment
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Path Traversal Vulnerability

The fix addresses a potential path traversal vulnerability where a card's parameter path could escape the card's directory boundaries. This could allow an attacker with control over a downloaded card to create symbolic links outside of the intended scope, potentially leading to privilege escalation or unauthorized file access. The fix correctly validates absolute paths, paths containing '..' components, and ensures that resolved paths stay within the card directory.

if os.path.isabs(rel) or ".." in rel.replace("\\", "/").split("/"):
    sys.exit("parameter path %r is not inside the card" % rel)
real_out = os.path.realpath(out)
if os.path.commonpath([real_out, os.path.realpath(os.path.dirname(os.path.join(out, rel)) or out)]) != real_out:
    sys.exit("parameter path %r leads out of the card" % rel)
if "/" in repo.strip("/").split("/", 1)[-1] or ".." in repo.split("/") or "/" in rev or rev in (".", ".."):
    sys.exit("checkpoint %r@%r is not a plain repository and revision" % (repo, rev))
Test Coverage for Hostile Cards

The test suite now includes coverage for hostile cards that attempt to create symbolic links outside the card scope. This ensures that the path validation logic in the loom-cards helper correctly prevents such attacks. The tests cover absolute paths, paths with '..' components, and symlinked directories to verify that nothing outside the card is touched.

# hostile cards (a card is downloaded content; the helper runs as root at boot): nothing outside the card is touched
for shape in abs climb dirlink; do
    hc=$t/hostile-$shape/evil; rm -rf "${t:?}/hostile-$shape" "${t:?}/data-$shape" "${t:?}/victim-$shape"; mkdir -p "$hc" "$t/victim-$shape"
    ln -s "$t/victim-$shape/real-target" "$t/victim-$shape/link"     # a link the machine owns, outside the card
    case $shape in
        abs)     p="$t/victim-$shape/link" ;;
        climb)   p="../../victim-$shape/link" ;;
        dirlink) p="out/link" ;;
    esac
    printf '{"model":{"files":[{"path":"%s","origin":"@checkpoint/m.gguf"}]}}\n' "$p" > "$hc/model.json"
    printf '%s\n' '{"origins":{"checkpoint":{"requested":{"kind":"hf","repository":"org/M","revision":"r1"}}}}' > "$hc/model.json.lock"
    [ "$shape" = dirlink ] && ln -s "$t/victim-$shape" "$hc/out"
    sh "$boot" "$t/hostile-$shape" "$t/data-$shape" "$HF" 2> "$t/err.$shape"; rc=$?
    [ "$(readlink "$t/victim-$shape/link")" = "$t/victim-$shape/real-target" ] && [ "$(ls "$t/victim-$shape")" = link ]
    check $? "a card whose parameter path is $shape touches nothing outside the card"
    if [ "$shape" = dirlink ]; then
        # only regular files are carried over, so the card's directory link never reaches /data: out/ is made inside
        [ $rc = 0 ] && [ -d "$t/data-$shape/evil/out" ] && [ ! -L "$t/data-$shape/evil/out" ]
        check $? "a symlinked directory in a card is not carried over: its parameter/ entry lands inside the card"
    else
        [ $rc = 1 ] && [ ! -e "$t/data-$shape/evil" ]; check $? "a card whose parameter path is $shape is refused, not half-built"
    fi
done

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review (lane cl-hrxtest): correct, approve, two edge nits. I read the diff and the test; I didn't run them.

  • The three escapes are closed, in the right order:

    • isabs stops os.path.join from dropping out;
    • a .. component check on a /-normalised path;
    • then realpath + commonpath on the parent of the target, which catches a symlinked directory the card ships, without following the final component the helper is about to replace.

    sys.exit before anything is created means a refused card isn't half-built, and the test asserts that ([ ! -e "$t/data-$shape/evil" ]).

  • The hostile-card tests bite: each of abs, climb and dirlink points at a link the test owns outside the card and checks it's untouched. dirlink also checks the entry lands inside the card, as a real directory, not the shipped symlink.

Nits:

  1. path of "" or "." passes every check. os.path.join(out, "") is out/, the card directory itself, and its parent is inside the card. The helper's remove-then-link step would then replace the card directory with a link. That stays inside /data and can't reach outside, but it's a card destroying itself. Refusing an empty path, a . component, or a trailing / alongside the .. check costs one line.
  2. The repository check accepts a bare name (no org/) and a . component (./x), because split("/", 1)[-1] of a one-part name is the name itself. These only become parts of a models--… cache name, so no path is reached. If the intent is "exactly org/name", re.fullmatch(r"[A-Za-z0-9._-]+/[A-Za-z0-9._-]+", repo) with ./.. refused per part says it directly. The same goes for rev being empty.

🤖 Generated with Claude Code

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Verdict: APPROVE (review by lane cl-kernel). This is the right twin for #3388: the same escape class (os.path.join drops the card directory for an absolute component, just as fs::path::operator/ does), and in a helper that runs as root at every boot.

  • Refusing absolute paths, .., a parent that realpaths outside the card, and a non-plain org/name or revision (since those become parts of the link target) covers the target side as well as the link side, which #3388 doesn't need to.
  • Refusing the whole card (exit 1, not half-built) is the safer outcome for a boot helper.
  • Ran on ryzen (git archive of this head, env -i): tests/loom_payload_test.sh ok, including abs, climb and dirlink each touching nothing outside the card, and a symlinked source directory not carried over.
  • No merge-order constraint with #3388 (different files); both should land before the rc1 cut.

@bong-water-water-bong
bong-water-water-bong enabled auto-merge (squash) November 23, 2026 13:26
@bong-water-water-bong
bong-water-water-bong merged commit 7acd807 into main Nov 23, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-release/loom-cards-path-guard branch November 23, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant