Repository navigation
lib: Load detached commit metadata as untrusted - #3700
Merged
Merged
Conversation
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
approved these changes
Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-keysprints 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.