Skip to content

lib: Load detached commit metadata as untrusted - #3700

Merged
cgwalters merged 1 commit into
ostreedev:mainfrom
Usamak06:commitmeta-untrusted
Nov 20, 2026
Merged

cgwalters merged 1 commit into
ostreedev:mainfrom
Usamak06:commitmeta-untrusted

Conversation

@Usamak06

Copy link
Copy Markdown
Contributor

ostree_repo_read_commit_detached_metadata() loads .commitmeta with trusted=TRUE, but detached metadata is not covered by the commit checksum, and pulling from a local repo (pull-local --untrusted, a file:// remote, or a USB repo from OstreeRepoFinderMount) copies the source's file through this function verbatim, since g_variant_get_normal_form() returns a trusted variant unchanged. A key that isn't NUL-terminated then reads into the following bytes: ostree show --list-detached-metadata-keys prints key and value together, and with the key at the end of the file strlen() runs past the buffer (ASan heap-buffer-overflow on a 13-byte file, SIGSEGV past the mapping for a file over 16 KiB). Reading it untrusted at both call sites fixes this, the same change as #3666 and #3679 for other loaders, and the new basic-test case overwrites a key's NUL and checks show and pull-local --untrusted; I checked the GVariant behaviour with standalone GLib reproducers but couldn't run the ostree build or test suite since I don't have a Linux machine here.

ostree_repo_read_commit_detached_metadata() built the .commitmeta
GVariant with trusted=TRUE. Detached metadata isn't covered by the
commit checksum, so neither the --untrusted import path nor fsck ever
validates it. A trusted variant skips GVariant's normal-form checks, so
g_variant_get_string() on a key that isn't NUL-terminated within its
bounds returns a pointer that runs into the following bytes: `ostree
show --list-detached-metadata-keys` prints the key together with its
value, and for a key at the end of the file strlen() reads past the
buffer (past the mapping for files over 16 KiB, which are mmap()ed).

When pulling from a local repo (pull-local --untrusted, a file://
remote, or a repo found by OstreeRepoFinderMount), copy_detached_metadata()
reads the source repo's .commitmeta through this function, and
g_variant_get_normal_form() returns a trusted variant unchanged, so
ostree_repo_write_commit_detached_metadata() wrote the crafted bytes
verbatim into the destination repo.

Read it untrusted at both call sites, as 05c9dce and ee36f11 did for
content object headers and static delta superblocks. The import path
now also writes out the normal form.

The test overwrites the NUL terminating a detached metadata key and
checks that neither show nor a pull-local --untrusted copy reads the key
into its value.
@cgwalters
cgwalters merged commit 5c24167 into ostreedev:main Nov 20, 2026
37 of 40 checks passed
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.

2 participants