Skip to content

repository: Verify pinned digests with open_digest and mount_digest - #439

Merged
cgwalters merged 1 commit into
composefs:mainfrom
jmarrero:advisory-fix-1
Nov 5, 2026
Merged

cgwalters merged 1 commit into
composefs:mainfrom
jmarrero:advisory-fix-1

Conversation

@jmarrero

@jmarrero jmarrero commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

open_image(name) falls back to images/refs/{name} when images/{name} does not exist and returns that file without measuring it, so a lookup by digest can return an image whose fs-verity digest is not the one asked for. Boot-time callers pass the digest pinned on the kernel command line, so with write access to the repository an attacker can remove images/ and point images/refs/ at any image with fs-verity enabled, and it is mounted as the pinned root with verity=require still on. The repository's mode, auto-detected from meta.json, is a second thing on disk such a caller shouldn't trust: meta.json lives on the same unverified filesystem as the images.

Add Repository::open_digest and mount_digest, which take the digest as a typed value, only look at images/, and require the measured fs-verity digest to match. In secure mode an image without fs-verity is refused; in insecure mode it is returned unverified, like everywhere else, while a measurable digest still has to match. open_image delegates to open_digest for a digest in secure mode, so images/refs/ is never consulted there; the insecure path keeps the fallback but verifies what it can measure. A mismatch is the typed
CompareVerityError::DigestMismatch from both.

To let a caller with its own source of trust decide the mode, the repository now tracks an IntegrityPolicy: Detected when open_path read it from meta.json, Explicit when the caller set it. Only an explicit policy can be set, and once set it is final for the handle, so a handle made secure can't be flipped back to insecure by later code. set_insecure() becomes a wrapper for Explicit(Disabled) and so now returns a Result, which is an API break.

composefs-setup-root parses the command line digest, sets an explicit policy from the ? marker and calls mount_digest. It no longer calls require_verity(): the digest and verity=require are enforced regardless of meta.json, and keeping it would refuse to boot installations whose meta.json was written without fs-verity although their images carry it.

A privileged integration test, run in a VM on ext4 with fs-verity, covers the refs fallback, a stripped image and the policy staying final; a unit test covers the policy transitions.

Generated-by: AI

open_image(name) falls back to images/refs/{name} when images/{name}
does not exist and returns that file without measuring it, so a lookup
by digest can return an image whose fs-verity digest is not the one
asked for. Boot-time callers pass the digest pinned on the kernel
command line, so with write access to the repository an attacker can
remove images/<pinned> and point images/refs/<pinned> at any image with
fs-verity enabled, and it is mounted as the pinned root with
verity=require still on. The repository's mode, auto-detected from
meta.json, is a second thing on disk such a caller shouldn't trust:
meta.json lives on the same unverified filesystem as the images.

Add Repository::open_digest and mount_digest, which take the digest as a
typed value, only look at images/<digest>, and require the measured
fs-verity digest to match. In secure mode an image without fs-verity is
refused; in insecure mode it is returned unverified, like everywhere
else, while a measurable digest still has to match. open_image delegates
to open_digest for a digest in secure mode, so images/refs/<digest> is
never consulted there; the insecure path keeps the fallback but verifies
what it can measure. A mismatch is the typed
CompareVerityError::DigestMismatch from both.

To let a caller with its own source of trust decide the mode, the
repository now tracks an IntegrityPolicy: Detected when open_path read
it from meta.json, Explicit when the caller set it. Only an explicit
policy can be set, and once set it is final for the handle, so a handle
made secure can't be flipped back to insecure by later code.
set_insecure() becomes a wrapper for Explicit(Disabled) and so now
returns a Result, which is an API break.

composefs-setup-root parses the command line digest, sets an explicit
policy from the `?` marker and calls mount_digest. It no longer calls
require_verity(): the digest and verity=require are enforced regardless
of meta.json, and keeping it would refuse to boot installations whose
meta.json was written without fs-verity although their images carry it.

A privileged integration test, run in a VM on ext4 with fs-verity,
covers the refs fallback, a stripped image and the policy staying
final; a unit test covers the policy transitions.

Generated-by: AI
Signed-off-by: Joseph Marrero Corchado <[email protected]>

@cgwalters cgwalters left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This was in an embargoed branch, we had a long discussion about it but merging from the embargo branch bypasses our CI etc and I think it's better to merge as normal.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Regression tests do not cover mounting with unprotected metadata, rejecting non-verity external data on read, or detecting pinned-digest mismatches through open_digest under both explicit policies.

2 open issues
What changed in this PR

This PR hardens pinned-image lookups and boot-time mounting by verifying the requested fs-verity digest and letting trusted callers override the repository’s detected integrity policy.

Changes:

  • Add typed open_digest and mount_digest APIs that bypass named-ref fallback.
  • Introduce explicit, final integrity policies and use them for boot-time mounts.
  • Add verification and policy regression tests, and propagate errors from set_insecure().
File Description
crates/​composefs/​src/​repository.rs Add digest-verifying APIs, integrity policies, and policy unit tests.
crates/​composefs-setup-root/​src/​main.rs Mount pinned digests using an explicit command-line-derived policy.
crates/​composefs-integration-tests/​src/​tests/​privileged.rs Test digest lookup, missing verity, and policy finality.
crates/​composefs-ctl/​src/​lib.rs Propagate errors from the fallible set_insecure() API.

Review effort: Balanced

Err(Errno::NOENT) => return Err(anyhow::Error::new(ImageNotFound { name: hex })),
Err(e) => return Err(e).with_context(|| format!("Opening image 'images/{hex}'")),
};
match ensure_verity_equal(&image, digest) {
Comment on lines +3076 to +3079
let verity = if enable_verity {
VerityRequirement::Required
} else {
VerityRequirement::Disabled
@cgwalters
cgwalters added this pull request to the merge queue Nov 5, 2026
Merged via the queue into composefs:main with commit b43c311 Nov 5, 2026
33 of 35 checks passed
jmarrero added a commit to jmarrero/bootc that referenced this pull request Nov 6, 2026
composefs-rs now provides Repository::mount_digest, which takes the
expected digest as a typed value, only looks at images/<digest> and
requires the measured fs-verity digest to match before mounting. That
is the check the previous commit open-coded around open_image; use the
library API instead so there is one implementation of it, shared with
composefs-setup-root.

composefs-rs also records whether a repository's fs-verity requirement
was detected from meta.json or chosen by the caller, and an explicit
choice is final for the handle. The initramfs sets
`IntegrityPolicy::Explicit(Enabled)` for a strict `composefs=` digest
and `Explicit(Disabled)` for one with the `?` marker, then mounts by
digest either way. With the marker a missing fs-verity digest is
tolerated, but one that can be measured still has to match.

The name-based mount() no longer runs in the initramfs, so images/refs/
is never consulted for a boot, with or without the marker. An image
that only exists under images/refs/<digest> is now reported as not
found rather than as a digest mismatch, so the boot moves on to the
next command line candidate the same way it does for a missing image.

`Repository::set_insecure` now returns a `Result`, so the remaining
callers propagate it. They all run on a freshly opened repository,
where the detected policy may still be replaced, so their behavior is
unchanged.

The booted verity test lists each case's expected result in a table
per mode, matches on the typed CompareVerityError::DigestMismatch
rather than on the message, and gains a case where images/<digest> is
repointed at another verified image, which both modes must reject as a
digest mismatch.

Bump composefs-ctl to 0.10.0, the release that carries these APIs
(composefs/composefs-rs#439).

Generated-by: AI
Signed-off-by: Joseph Marrero Corchado <[email protected]>
cgwalters pushed a commit to bootc-dev/bootc that referenced this pull request Nov 6, 2026
composefs-rs now provides Repository::mount_digest, which takes the
expected digest as a typed value, only looks at images/<digest> and
requires the measured fs-verity digest to match before mounting. That
is the check the previous commit open-coded around open_image; use the
library API instead so there is one implementation of it, shared with
composefs-setup-root.

composefs-rs also records whether a repository's fs-verity requirement
was detected from meta.json or chosen by the caller, and an explicit
choice is final for the handle. The initramfs sets
`IntegrityPolicy::Explicit(Enabled)` for a strict `composefs=` digest
and `Explicit(Disabled)` for one with the `?` marker, then mounts by
digest either way. With the marker a missing fs-verity digest is
tolerated, but one that can be measured still has to match.

The name-based mount() no longer runs in the initramfs, so images/refs/
is never consulted for a boot, with or without the marker. An image
that only exists under images/refs/<digest> is now reported as not
found rather than as a digest mismatch, so the boot moves on to the
next command line candidate the same way it does for a missing image.

`Repository::set_insecure` now returns a `Result`, so the remaining
callers propagate it. They all run on a freshly opened repository,
where the detected policy may still be replaced, so their behavior is
unchanged.

The booted verity test lists each case's expected result in a table
per mode, matches on the typed CompareVerityError::DigestMismatch
rather than on the message, and gains a case where images/<digest> is
repointed at another verified image, which both modes must reject as a
digest mismatch.

Bump composefs-ctl to 0.10.0, the release that carries these APIs
(composefs/composefs-rs#439).

Generated-by: AI
Signed-off-by: Joseph Marrero Corchado <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants