Skip to content

UAPI.16 Manifest tooling and support in systemd-sysupdate - #44292

Merged
poettering merged 8 commits into
systemd:mainfrom
poettering:sysupdate-uapi16
Nov 5, 2026
Merged

poettering merged 8 commits into
systemd:mainfrom
poettering:sysupdate-uapi16

Conversation

@poettering

@poettering poettering commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

This adds UAPI.16 support to systemd-sysupdate, systemd-importd, systemd-repart. It also adds a new tool for generating and verifying manifests.

It also adds support for additional matches in sysupdate transfer files, against xattrs on files. This is then also replicated in vpick.

Fixes: #44448
Fixes: #38772
Fixes: #32819
Fixes: #35571
Fixes: #38774
Fixes: #37931

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Reviewed b8d6a06 (architecture, correctness, lifetimes, security, style, tests). All findings are resolved 🎉

Must fix

  • src/libsystemd/sd-json/json-util.c:71 r is 0 here because the preceding dispatch succeeded, so json_log() returns 0. A hash of the wrong length is then silently accepted and the field stays unset. Pass SYNTHETIC_ERRNO(EINVAL) instead of r.
  • src/sysupdate/sysupdate-transfer.c:1839 The old URL→partition systemd-pull call passed transfer_zero_fill(t) ? "--zero-fill=yes" : "--zero-fill=no", and this path drops it. Verity signature partitions and PartitionZeroFill=yes are no longer zero-filled from web sources. Add it after --size-max=.
  • src/sysupdate/sysupdate-resource.c:815 This is a shallow copy, so slot k keeps the pointers moved to slot n. If a later iteration returns an error (OOM, URL build), n_contents is unchanged and uapi16_object_done() frees both slots: a double free. Reset *c = UAPI16_CONTENTS_NULL after the move.
  • src/sysupdate/sysupdate-resource.c:968 The web cache is still keyed only by (rr->path, verify), but the content now also depends on manifest_format and manifest_path. Transfers sharing Path= get each other's manifest, e.g. SHA256SUMS data fed to uapi16_process(). Key the cache on the effective manifest URL and format.
  • src/sysupdate/sysupdate-resource.c:466 For UAPI.16, --verify is forced to no because signatures are inline, but uapi16_process() only logs and ignores signature objects. With the default Verify=yes, unauthenticated manifests are trusted. Verify the inline signature, or refuse uapi16 while verify is on.
  • src/shared/manifest-util.c:1612 manifest_stat_file() heap-allocates a digest into hash for every regular file, but verify_object() never uses or frees it, and manifest_verify_hash() hashes the file again. Pass NULL for ret_hash.
  • src/shared/manifest-util.c:1450 The digest buffer that manifest_stat_file() allocates into hash is never freed, so it leaks once per SHA256SUMS line. Declare it _cleanup_(iovec_done) struct iovec hash = {};.
  • src/shared/manifest-util.c:1803 dispatch_uapi16_signature_object() fills media_type, key and data in sig, but nothing frees them, so every signature object leaks, including on the early-return paths. Use _cleanup_(uapi16_signature_done).
  • src/shared/uapi16-manifest.c:477 The iovec_memdup(source, ret) arguments are swapped: this copies the unset sha256 into a temporary literal, so zero-length objects never get the empty hash. Use iovec_memdup(&IOVEC_MAKE(SHA256_EMPTY, SHA256_DIGEST_SIZE), sha256).
  • src/repart/repart.c:8743 This ignores --dry-run=, which defaults to yes. A plain systemd-repart --manifest-match-…= run leaves the partition table alone but still sets user.match_* xattrs on the image (fsetxattr works on the O_RDONLY fd). Return early if context->dry_run.
  • test/units/TEST-50-DISSECT.manifest.sh:247 uapi16_signer_new() refuses Ed25519 on OpenSSL < 3.2, so this block fails on Ubuntu noble (3.0.13), which is in the mkosi CI matrix. The unit test skips that case but this script doesn't. Gate the Ed25519 block on openssl version ≥ 3.2.
  • src/shared/manifest-util.c:1066 Every non-regular inode (e.g. the /bin symlink) bumps n_skipped, and systemd-dissect has no --graceful, so --sha256sums returns EUCLEAN on nearly every image. The man page says these are just skipped. Only count missing STATX_TYPE; log the rest at debug level.
  • src/sysupdate/sysupdate-transfer.c:2118 run_callout() returns -ECANCELED on SIGINT/SIGTERM, but this loop treats it as an ordinary failure and moves on to the next source. sysupdated's Cancel() sends SIGTERM, so each source swallows one cancel request. Break out of the loop on -ECANCELED.
  • src/sysupdate/sysupdate-transfer.c:54 Since the per-attribute settings were folded into a single bool match_xattr, nothing in this file uses xattr-match.h any more. resource_xattr_match_mask() is declared in sysupdate-resource.h. misc-include-cleaner will flag the include and CI fails on clang-tidy warnings, so drop it.
  • src/sysupdate/sysupdate-transfer.c:2092 For URL tar resources, a source that fails leaves its partly extracted, unverified tree in temporary_partial_path. In --direct mode pull/import accept EEXIST and never clean up, so the next source extracts on top and the leftovers get installed. rm_rf() the partial path before trying the next source.
  • src/shared/vpick.c:719 The xattr filter matches against root_path, the chase root. mstack passes its own directory there (mstack.c:142), so host properties load from <dir>/etc/… and restricted layers get rejected. Callers with NULL root_path but an image root_fd match the host instead. Pass the match root explicitly.
  • src/repart/repart.c:9116 The man page says the GPT manifest works with sysupdate, but each partition object only lists a source at a non-zero offset with originalSize set to the whole disk. sysupdate drops these as partial downloads and skips the file (sysupdate-resource.c:775/803). Support offset sources or drop the claim.
  • src/repart/repart.c:7604 user-xattr is in the default field set, and this manifest is built from the staging tree, which gets every xattr via COPY_ALL_XATTRS. A vfat filesystem filled through mcopy drops those xattrs, so the manifest lists attributes the partition doesn't have and verification fails. Clear MANIFEST_FIELD_USER_XATTR for vfat here. (dismissed)
  • src/sysupdate/sysupdate-resource.c:693 The manifest's mode is parsed without SD_JSON_STRICT, so values up to 07777 are accepted, and fchmodat() later applies them as-is. A manifest can install setuid/setgid or world-writable files, which the pattern and directory paths block with & 0775. Mask it the same way here. (dismissed)
  • src/sysupdate/sysupdate-resource.c:915 UAPI.16 says a missing contents means the same as [{"file": name}], resolved next to the manifest. Here it resolves against Path=, while [{}] and file entries resolve against ManifestPath=. With ManifestPath= set, the two equivalent manifests fetch different URLs. Resolve objects without contents next to the manifest too.

Suggestions

  • src/shared/varlink-io.systemd.SysUpdate.Provider.c:189 This symbol comment has no type after it, so it attaches to vl_type_TransferSource, which then carries two comments. Drop it, or add the type it was meant to describe.
  • src/shared/varlink-io.systemd.SysUpdate.Provider.c:122 The new [Source] ManifestFormat=/ManifestPath= settings are missing from TransferSource and dispatch_transfer_source(), while MatchXAttr*= is mirrored. Provider-supplied transfers therefore can't use UAPI.16 manifests.
  • src/sysupdate/sysupdate-resource.c:911 sha256sums_line() accepts both PATTERN_MATCH_YES and PATTERN_MATCH_YES_AND_RETRY, but this path accepts only YES. With multiple MatchPattern= entries, matching files get dropped for UAPI.16. Use IN_SET() as the SHA256SUMS path does.
  • src/sysupdate/sysupdate-resource.c:922 The SHA256SUMS path refuses % in names because curl percent-decodes it, which can produce .. after the normalization check. UAPI.16 name and contents[].file are put into URLs without that check. Apply the same rejection to both.
  • src/sysupdate/sysupdate-resource.c:767 A manifest fetched over HTTP can list file:// URLs as sources, which makes root-run sysupdate read local files as payloads. Only accept file:// sources when the manifest itself came from a file:// URL. (dismissed)
  • src/sysupdate/sysupdate.c:583 The xattr filter also applies to installed target instances. Non-matching ones (e.g. after IMAGE_VERSION moves past a constraint) become invisible, so InstancesMax= vacuuming and current-version tracking miss them. Consider filtering sources only.
  • src/import/pull-common.c:354 Uapi16Manifest is now always tried before .sha256/SHA256SUMS. A server that publishes both makes a default --verify=signature pull fail with ENOKEY on hosts without VOA import certificates, where the gpg path used to work. Fall back to the old files when no certificates are installed.
  • src/import/pull-common.c:589 uapi16_load_voa_certificates() already logs on every failure path, so this logs each error twice. Return r directly, as context_load_manifest_certificates() does.
  • test/units/TEST-58-REPART.sh:1584 This passes even without the new validation: $imgs/invalid doesn't exist and there is no --empty=create/--definitions=, so repart fails anyway. Grep for the specific parse error for --manifest-match-os-version-id= instead.

Nits

Workflow run

@github-actions github-actions Bot added tree-wide please-review PR is ready for (re-)review by a maintainer and removed sysupdate util-lib labels Oct 19, 2026
Comment thread src/libsystemd/sd-json/json-util.c Resolved
Comment thread src/sysupdate/sysupdate-transfer.c Resolved
Comment thread src/sysupdate/sysupdate-resource.c Resolved
Comment thread src/sysupdate/sysupdate-resource.c Resolved
Comment thread src/sysupdate/sysupdate-resource.c Resolved
Comment thread src/shared/manifest-util.c Resolved
Comment thread src/shared/manifest-util.c Resolved
Comment thread src/shared/manifest-util.c Resolved
Comment thread src/shared/uapi16-manifest.c Resolved
Comment thread src/sysupdate/sysupdate-resource.c Resolved
Comment thread src/sysupdate/sysupdate-resource.c Resolved
Comment thread src/sysupdate/sysupdate-resource.c Resolved
Comment thread src/sysupdate/sysupdate.c Resolved
Comment thread src/shared/uapi16-manifest.c Resolved
Comment thread src/shared/manifest-util.h Resolved
Comment thread src/libsystemd/sd-json/json-util.c Resolved
Comment thread src/shared/manifest-util.c Resolved
Comment thread src/shared/manifest-util.c Resolved
Comment thread src/sysupdate/sysupdate-instance.h Resolved
Comment thread src/sysupdate/sysupdate-instance.h Resolved
Comment thread src/sysupdate/sysupdate-transfer.c Resolved
@daandemeyer

Copy link
Copy Markdown
Collaborator

I did an AI review as well:

Reviewed #44292 at 8a606b2..f8c0450. Found two blockers, both reproduced:

B1 [Medium] — GPT-type filtering never takes effect (sysupdate-resource.c:847). The check reads the source’s partition type, but MatchPartitionType= sets the target’s type. A usr-x86-64 manifest object was offered for a root-x86-64 target; destination selection does not reject that mismatch.
B2 [Medium] — Ranged tar downloads cannot be acquired (sysupdate-transfer.c:1752). Sysupdate accepts and lists a tar source embedded at an offset, then passes range options to systemd-pull tar, which rejects them. Updating fails with “–source-offset=/–source-size= are not supported for tar images.”

Two smaller findings:

C1 [Low]: The man page promises full downloads and encoded-digest verification, although unencoded ranges deliberately skip those. The acquisition commit message also incorrectly describes ranges as unsupported and compression autodetection as preserved.
M1 — Minimalism: literal_to_memfd() can use memfd_new_and_seal() directly. That helper writes with pwrite_full(), leaving the position at zero, so the wrapper’s rewind and error path are redundant.

@daandemeyer daandemeyer added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels Nov 4, 2026
@github-actions github-actions Bot added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Nov 4, 2026
@poettering

Copy link
Copy Markdown
Member Author

Addressed all, including the AI stuff you listed.

@daandemeyer

daandemeyer commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

B3 [Medium, blocker] — Valid contents sources are discarded (sysupdate-resource.c:765).
The resolver rejects entries without file or url when iovec_is_set(literal) is false. This incorrectly excludes:
{"literal":""} for an empty file.
{}, which should imply a file reference using the enclosing object’s name under the UAPI.16 contents rules.
With no alternative source, the entire instance disappears from available updates. Reproduced both cases; an explicit-file control remained visible. This was missed in round 1 and already existed in the original acquisition code.

C2 [Low] — The tar restriction is overstated (sysupdate.d.xml:753). The documentation excludes ranges for every url-tar source, but unencoded inline tar data supports ranges. Only downloaded tar sources require the whole file.
Minimalism

M1 remains in the replacement helper (data-fd-util.c:248). data_fd_from_iovec() duplicates memfd_new_and_seal()’s allocation, writing and sealing. Using that constructor followed by fd_reopen(O_RDONLY) preserves empty-data handling, ownership, seals and initial position while removing the duplicate implementation.

M2: copy_data_fd_full() rewinds before reopening, which already resets the position. Returning before the seek on success removes an unnecessary syscall; the fallback still needs the seek.

M3: Every memfd_seal_and_reopen() caller effectively requests O_RDONLY. Its mode parameter can go; fd_reopen() supplies the optional O_CLOEXEC itself.

Unresolved, speculative [Low]: Small stdin copies now require /proc/self/fd on kernels without O_EMPTYPATH. That could regress pcrlock lock-pe/lock-uki in proc-less chroots. Whether that environment is supported remains open; an old/new stdin comparison there is the next check.

@daandemeyer daandemeyer added good-to-merge/with-minor-suggestions and removed please-review PR is ready for (re-)review by a maintainer labels Nov 4, 2026
This places literal data in a sealed memfd and returns a read-only fd to
it, positioned at the beginning, so that it can be passed to other
processes, for example as standard input. It's a thin wrapper around
memfd_new_and_seal() plus a read-only reopen.

The final "seal and reopen read-only" step of memfd_clone_fd() is split
out into a helper, and copy_data_fd_full() now uses it too, so that its
memfd case returns an O_RDONLY fd like its temporary file cases already
do, instead of a sealed O_RDWR one.
The "literal" field of a contents object may carry empty data, which
encodes an empty file. iovec_is_set() returns false for that though, so
such a field was considered absent, and the check that "file", "url"
and "literal" are mutually exclusive did not refuse an empty "literal"
next to one of the others.

Add uapi16_contents_has_literal(), which checks whether the field was
set instead of whether it carries data, and use it for the check.
Comment thread src/sysupdate/sysupdate-resource.c Resolved
So far we ignored the "contents" arrays of UAPI.16 file objects, and
always downloaded a file by its name relative to the source URL. Let's
make use of them: each entry is an alternative location of the file's
data, and we now try them in the listed order until one works out.

All three kinds of sources are supported: "file" entries name a file
relative to Path= (also if ManifestPath= is used, which only redirects
the acquisition of the manifest itself), "url" entries carry an absolute
URL, and "literal" entries carry the data inline. Sources may embed the
file in more data, in which case the range at the specified offset is
used and checked against the file's digest. Inline data is cut in memory
and handed to systemd-import via a memory fd as standard input.
Downloads are passed to systemd-pull with --source-offset= and
--source-size=, so that for unencoded sources only the range making up
the file is downloaded. systemd-pull supports ranges for raw images
only, and we cannot cut into encoded inline data, hence such sources
must consist of the file and nothing else; sources that do not qualify
are ignored with a warning.

Everything is still run through systemd-pull or systemd-import, so that
decompression, sparse file handling and sandboxing work the same for
all sources. The encoding declared in the manifest is passed down to
the tools via --compression= (or "none" if none is declared), so that
they strictly decode with that algorithm rather than guessing from the
data.

If a file object carries no "contents" array, it is acquired by its
name as before. For UAPI.16 manifests it is taken as is (i.e. with
--compression=none), since the manifest declares encodings explicitly
via "contents"; for SHA256SUMS manifests the tools keep detecting the
compression on their own.

Fixes: systemd#38772
Fixes: systemd#32819
Fixes: systemd#35571
Fixes: systemd#38774
Fixes: systemd#37931

(Of course, these issues are only fixed if people use UAPI.16 instead of
SHA256SUMS, but I think this is an OK requirement to make)
UAPI.16 manifests carry their signatures inline, hence systemd-pull is
invoked with --verify=no for them, but so far nothing else verified the
signature either, i.e. with the default of Verify=yes unauthenticated
manifests were trusted.

Pass the X.509 certificates found in the VOA hierarchy (UAPI.11, role
"manifest", context "sysupdate") to uapi16_manifest_read(), so that the
manifest signature is verified while the manifest is parsed. If
verification is enabled and no certificates are found, the transfer is
refused.
… instances

UAPI.16 file objects may carry an "extendedAttributes" field. When
installing a file or directory from a source with a UAPI.16 manifest,
let's apply the extended attributes in the "user" namespace listed there
to the inode we create, so that they are retained on the target.

This is done on a best-effort basis: if the file system does not support
extended attributes, or setting them fails for other reasons, this is
logged but not fatal, the instance is fully usable without them.
…systems

Let's add a boolean MatchXAttr= setting to the [Source] and [Target]
sections of transfer files that allows restricting individual instances
to specific systems, via extended attributes attached to them. If
enabled, the following extended attributes are checked:

  user.uapi.match_hostname      → the hostname
  user.uapi.match_machine_id    → the machine ID
  user.uapi.match_machine_tags  → the machine tags (TAGS= in machine-info)
  user.uapi.match_image_id      → IMAGE_ID= from os-release
  user.uapi.match_image_version → IMAGE_VERSION= from os-release
  user.uapi.match_os_id         → ID= from os-release
  user.uapi.match_os_version    → VERSION_ID= from os-release

In the [Source] section it is enabled by default, so that whoever
publishes instances can restrict them to specific systems without every
transfer file having to opt in. In the [Target] section it is off by
default, i.e. installed instances are only filtered if requested.

The checks are applied to the extended attributes listed in UAPI.16
manifests (relevant for sources) as well as to the extended attributes
of files and directories found on disk (relevant for targets and local
sources). Instances that do not match are entirely ignored, i.e. they are
neither installed nor vacuumed. Since the extended attributes listed in
UAPI.16 manifests are applied to the installed instances, the
restrictions are retained on the target.

The local system properties (hostname, machine ID, machine tags and the
relevant os-release fields) are only read when they are needed for the
first time, i.e. when a candidate actually carries one of these
attributes. If --root=/--image= is used they are read from there.

The setting is also exposed as boolean matchXAttr field of transfers
defined via the io.systemd.SysUpdate.Provider Varlink interface.
@poettering poettering added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed good-to-merge/with-minor-suggestions labels Nov 5, 2026
@poettering
poettering merged commit 27281f9 into systemd:main Nov 5, 2026
73 of 75 checks passed
@github-actions github-actions Bot removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

6 participants