sandlock icon indicating copy to clipboard operation
sandlock copied to clipboard

access queries in mediated metadata paths use supervisor credentials

Open jamesboyzj-design opened this issue 2 months ago • 0 comments

Per the scope decision in https://github.com/multikernel/sandlock/pull/274#issuecomment-5983350176, track caller-credential correctness separately from #274's chroot target pinning and COW compatibility changes.

The supervised access paths execute faccessat2 using the supervisor's credentials. Pinning a target with O_PATH and querying AT_EMPTY_PATH prevents a pathname reopen, but does not transfer the caller's IDs, namespace, groups or capabilities. This affects ordinary procfs/metadata.rs, chroot pathname/empty-path checks, and mediated modified COW targets. #274 now returns unchanged COW access queries to the caller's kernel; that bounded change does not fix these remaining mediated queries.

Reproduced outcomes

All objects are synthetic fixtures, mode 000, queried with R_OK. These differences are present on reviewed #274 head 49197ebc; the ordinary metadata/chroot CLI cases were also rechecked with the scoped follow-up 5749f7e.

Supervisor / child Native kernel Ordinary metadata Chroot
uid/gid 65534; child mapped to uid 0 OK EACCES EACCES
root; child verifies all effective/permitted/inheritable capabilities dropped EACCES OK OK

Both flags 0 and AT_EACCESS (512) show the differences. Separate real-sandbox integration comparisons also expose chroot held-O_PATH AT_EMPTY_PATH mismatches, with COW on/off. The earlier broader matrices had 8 COW and 32 chroot mapped-user mismatches on reviewed head; root capability-drop comparisons had 2 COW and 8 chroot mismatches. These are not assertions that every UID mapping behaves identically on every filesystem.

Runnable CLI reproduction

Use the updated #274 checkout (e.g. gh pr checkout 274 --repo multikernel/sandlock in a repository checkout), then build cargo build --locked -p sandlock-cli. The core build produces the static tests/rootfs-helper; its access-empty command makes raw faccessat2 calls, and access-drop-caps first performs capset/capget and fails if clearing capabilities did not succeed.

Save this as repro.py, then run:

python3 repro.py ./target/debug/sandlock ./tests/rootfs-helper

Run once as an ordinary user that can create a user namespace, and separately as root in an isolated test environment. The script checks both expected kernel answers and the observed mismatch, and fails on setup errors. It creates and removes only its own temporary synthetic fixture.

The CLI rejects --no-supervisor together with --user. Accordingly, the unprivileged CLI reproduction uses unshare --user --map-root-user for its native DAC reference; the Rust integration reference uses SandboxBuilder::no_supervisor(true).user(0, 0). The root capability-drop reference uses CLI --no-supervisor. An ordinary supervised sandbox is not an independent reference: it goes through the same metadata handler.

"""Linux: python3 reproduce_access_credentials.py /path/to/sandlock /path/to/rootfs-helper"""
import os, pathlib, shutil, subprocess, sys, tempfile

sandlock, helper = map(os.path.realpath, sys.argv[1:])
with tempfile.TemporaryDirectory(prefix='sandlock-credential-repro-') as directory:
    root = pathlib.Path(directory)
    (root / 'bin').mkdir()
    (root / 'data').mkdir()
    shutil.copy2(helper, root / 'bin/rootfs-helper')
    target = root / 'data/target'
    target.write_text('synthetic fixture')
    target.chmod(0)
    mapped = ['--user', '0:0'] if os.getuid() != 0 else []
    operation = 'access-empty' if mapped else 'access-drop-caps'
    for flags in [0, 512]:
        outputs = {}
        for view in ['kernel', 'metadata', 'chroot']:
            common = [sandlock, 'run'] + mapped
            if view == 'chroot':
                args = common + ['--chroot', directory, '-r', '/bin', '-r', '/data', '--',
                                 '/bin/rootfs-helper', operation, 'name', '/data/target', '4', str(flags)]
            elif view == 'kernel' and mapped:
                # CLI rejects --user with --no-supervisor; use a native
                # single-entry root user namespace for this DAC reference.
                args = ['unshare', '--user', '--map-root-user', helper,
                        operation, 'name', str(target), '4', str(flags)]
            else:
                if view == 'kernel': common += ['--no-supervisor']
                args = common + ['-r', helper, '-r', directory, '--', helper,
                                 operation, 'name', str(target), '4', str(flags)]
            result = subprocess.run(args, text=True, capture_output=True, timeout=20)
            if result.returncode:
                raise SystemExit(f'{view} setup failed: {result.returncode} {result.stderr}')
            outputs[view] = result.stdout.strip()
        print(f'uid={os.getuid()}, operation={operation}, flags={flags}: {outputs}', flush=True)
        expected = 'OK' if mapped else 'ERR:13'
        assert outputs['kernel'] == expected, outputs
        assert outputs['metadata'] != expected and outputs['chroot'] != expected, outputs

Verified environment: Linux aarch64 7.0.14-orbstack-00380-ga7e0a2dc9535, Landlock ABI 8, Rust 1.96.1; Docker --init --security-opt seccomp=unconfined, not --privileged; unprivileged run uses uid/gid 65534 with supplementary groups cleared. User namespaces are enabled. Native x86_64, additional filesystems, supplementary-group/ACL matrices and directory-search cases remain to be added; no skipped case is counted as verified.

Acceptance boundaries

  • Distinguish real-ID access/faccessat from AT_EACCESS; test pathname and held/deleted/anonymous fd queries.
  • Compare against genuinely caller-executed kernel queries with matched user namespaces, real/effective/fs IDs, supplementary groups and effective/permitted capabilities, including capability drops after exec.
  • Cover mode 0600/0400/0000, execute/group permissions, POSIX ACLs, directory search, uid mappings and filesystem ownership/mapping. Keep COW's intentionally mediated W_OK semantics explicit.
  • Keep authorization and queried object consistent under replacement. A final-fd check must not silently omit directory-search constraints.
  • Any isolated kernel executor must account for credential changes and setup failures. Joining a user namespace alone can grant capabilities the child has discarded. Do not approximate full semantics with mode bits/setfsuid alone or mutate credentials in the multithreaded supervisor.

This issue records unresolved permission semantics; the #274 pinning repair and unchanged-COW delegation must not be described as resolving it. No credential-matching executor is added to #274.

jamesboyzj-design avatar Oct 05 '26 13:10 jamesboyzj-design