Commit Graph
2704 Commits
Author SHA1 Message Date
Sebastian Wick 37fe50fc9c installation: Avoid races when caching the display name
We specifically have to avoid holding the lock while calling
flatpak_installation_get_dir_maybe_no_repo, so we just double check if
it is unset.
2026-07-27 13:41:00 +00:00
Sebastian Wick 2a0c49ef89 flatpak-json: Fix strict struct JSON parsing
The code checked the wrong flags. struct_props is the array of child
properties, so struct_props->flags is the flags of the first child
property. What we need to chech is the flags of the current property,
and if it contains FLATPAK_JSON_PROP_FLAGS_STRICT.
2026-07-27 13:41:00 +00:00
Sebastian Wick c4d12fa6ad zstd-compressor: Abort on ZSTD_initCStream error
This doesn't seem to happen in practice, but the API says it's possible,
so we better abort than run into weird states.
2026-07-27 13:41:00 +00:00
Sebastian Wick a68d120bc1 image-source: Handle NULL commit subjects and bodies 2026-07-27 13:41:00 +00:00
Sebastian Wick 1825293e27 run: Add error handling for g_unix_fd_list_append
It also adds autofd cleanup and simplifies the control flow a bit.
2026-07-27 13:41:00 +00:00
Sebastian Wick 59ef3bc49a usb: Parse the vnd rule into the vendor union member
It was accidentally parsed into the product union member but because it
has the same layout as the vendor one, this didn't turn into a bug in
practice, but it probably is UB.
2026-07-27 13:41:00 +00:00
Sebastian Wick e881563fd4 remote-ref: Fix the get_property of the download-size property 2026-07-27 13:41:00 +00:00
Sebastian Wick 027cd64af0 xml-utils: Escape XML attribute values when serializing 2026-07-27 13:41:00 +00:00
Sebastian Wick 7ecf90f1dd json-oci: Clean up dead code in flatpak_oci_index_get_manifest_for_arch 2026-07-27 13:41:00 +00:00
Sebastian Wick d2f364bbd7 locale-utils: Ensure the flatpak lang only contains a-zA-Z
This should be the case anyway right now and makes it easier to ensure
the code using it is correct.
2026-07-27 13:41:00 +00:00
Sebastian Wick c771d52887 dir-utils: Fix return type in flatpak_find_current_ref 2026-07-27 13:41:00 +00:00
Maximiliano Sandoval 59f9a7729f common: Stop using G_GNUC_CONST in _get_type funcs
As per g_type_ensure's documentation it is technically incorrect to mark
_get_type fns with G_GNUC_CONST since they have side-effects on their
first run.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/5223 for more
details.
2026-07-06 08:23:01 +00:00
John Cardullo f266346d6d run: Validate file object before checking cached path
Verify that the file object is valid before checking its cached path
to avoid a potential NULL pointer dereference.

Fixes: c4fce9e4 ("run: Error out if file forwarding of empty paths is attempted")
2026-07-03 17:16:06 +00:00
razzeee 4006907ba3 transaction: Add flatpak_transaction_progress_get_bytes_per_second() 2026-06-23 09:50:04 +00:00
bbhtt 5fcf748ac9 dir: Don't pass temp repo path to flatpak_dir_log during initial pull
During a system install with the system helper enabled, the initial
network pull goes to a temporary repo and then via pull local from that
repo to the final system repo while during user install there is only
one pull from network to the final repo.

c672c55 set the logger to use the temporary repo path as installation
but the history command afc87ad since the same day filters the initial
pull out as the installation name will never match the temporary path.

This causes the initial pull operation to be never show up in flatpak
history when using system installs while they work for user installs as
`INSTALLATION=user`.

This is presumably also broken for custom installations as they
will similarly not match the temp repo path.

So don't pass the path at all to flatpak_dir_log and we can later
fall back via flatpak_dir_get_name_cached() which sets the correct
`INSTALLATION` for system installs ie. `INSTALLATION=system`.

This also allows us to remove the workaround of adding two different
expected history outputs from ad1ff6d as both branches log the pull.

Without system helper `flatpak install` needs to be executed as
priviledged to operate on system install so the initial pull was
always logged correctly for that branch.
2026-06-23 09:11:59 +00:00
bbhtt f4946b206b flatpak-context: Add test for flatpak_permission_to_args negated output
Test for the bug fixed in db70882d. We test no(socket | device) anyway
to stop future regressions.
2026-06-23 08:46:20 +00:00
Sebastian Wick c4fce9e42a run: Error out if file forwarding of empty paths is attempted
The file forwarding feature errors out when the path or URI does not
lead to an actual file that can be forwarded. The empty path never
describes an actual file, so we always have to error out.

Without the check, we would get a NULL path from
`flatpak_file_get_path_cached` and crash later.

Closes: #6689
2026-06-23 08:44:34 +00:00
Owen W. Taylor 906affa13b Handle null properties as missing properties
We were handling null properties the same as missing properties
*except* that the MANDATORY flag allowed null properties but
not missing properties. Fix this, so null is disallowed by
MANDATORY.

When checking signatures, the image identity could only have
been NULL if it was null in the input file - so replace a
conditional check on it being non-null with an assertion.
2026-06-16 20:13:10 +00:00
Owen W. Taylor b15828e119 Fix crash on image indexes with missing architecture
It's legitimate to have manifests listed in an image index that
have no platform object, and hence no architecture - avoid crashing
if we encounter such a manifest.
2026-06-16 20:13:10 +00:00
Owen W. Taylor fa4b413c02 Make mandatory properties from OCI specifications mandatory
Mark all properties required by the OCI specification as required;
this eliminates a bunch of cases where we were assuming that
descriptor->digest was non-NULL, and potentially generating
critical errors from g_return_if_fail().
2026-06-16 20:13:10 +00:00
Mia McMahill 4d3f0bbb79 app, common: Remove duplicate directories from export functions
Both collect exports and flatpak_export_dir recursively export the
directories in their respective directory lists. Because of this,
including share/metainfo/releases when share/metainfo is already in the
lists is unnecessary and can cause exporting to fail because of
duplicate files.
2026-06-16 11:20:58 +00:00
Kolja Lampe 4ff158caea http: Propagate stream write failures to curl
We did not report the written bytes of the aborted stream before - so
curl thought that we wrote all bytes.
2026-06-15 10:02:12 +00:00
Kolja Lampe 420ce91428 http: Reset curl TLS options between transfers
Previously the curl object potentially leaked cert infos from different
urls
2026-06-15 10:02:12 +00:00
Razze 8ac2adefce oci-registry: Apply TLS certs to request
Signature downloads can use a different URL from the OCI registry
itself, so they must not depend on TLS options left on the reused curl
handle. Resolve certificates for the URI and pass them explicitly.
2026-06-15 10:02:12 +00:00
bbhtt 69bf837676 instance: Annotate flatpak_instance_get_all as (transfer container)
Annotating the return as (transfer full) causes bindings to additionally
unref each element on array free, resulting in a use-after-free.

Change the annotation to (transfer container) so bindings know to unref
the array only.

Fixes: https://github.com/flatpak/flatpak/issues/6666
2026-06-15 09:26:10 +00:00
asbytes db70882df1 context: Fixed negated permission string for allow and share options
It was solved partially in e0e1b20, but not for completely disallowed code path.
Steps to reproduce:
1. Run any flatpak with explicit --unshare option, e.g:
    [user@user-standardpc ~]$ flatpak run --unshare=network --command=bash io.gitlab.librewolf-community
2. Inside flatpak shell spawn any executable:
    [io.gitlab.librewolf-community ~]$ flatpak-spawn ls /
Result is:
error: Unknown option --noshare=network
2026-06-11 20:40:49 +00:00
Sebastian Wick 32baedaa7e oci-registry: Check signatures from mirrored repo in the system helper
In flatpak_pull_from_oci we can be in in the system helper where we pull
the mirrored OCI image into the system repo. However, to fetch the
signatures in GPG signed repos, we used a remote OciImageSource created
through `flatpak_remote_state_fetch_image_source`. This caused fetching
some data from the registry which we don't want in the deploy method,
and also fails if a token is required to access the repo.

This change fetches the signatures from the mirrored OCI repo instead of
pulling them from the remote OciImageSource. The signatures can come from
anywhere because we verify them against the GPG key in the system repo.

The important bit is the change in `flatpak_pull_from_oci` where we now
pass in the local image_source to fetch the signatures from, and in the
system helper, where we get the right metadata to check the signatures
against (eventually ends up in `flatpak_oci_signatures_verify`).
2026-06-11 18:26:52 +00:00
Sebastian Wick 1a33d1a15b oci-registry: Load the certificates from an ImageSource 2026-06-11 18:26:52 +00:00
Jordan PetridisandDan Nicholson 9a813ffba0 dir: Ignore system bus failures in parental controls check
Being unable to access the system-bus is nto a security boundry since,
in that case it's trivial to start your own session and set
DBUS_SYSTEM_BUS_ADDRESS. This is the same fix as 3afdfd2 but for handling
installation instead. See said commit for more details.

Adapted from #5609
Fixes #5076

Co-authored-by: Dan Nicholson <dbn@endlessaccess.org>
2026-05-27 14:39:32 +00:00
razzeee 8fd0f5d706 run: Add /dev/kfd to dri device permission
/dev/kfd is used for AMD ROCm/OpenCL compute. Add it to the dri
device list so apps can request GPU compute access without
needing --device=all.

Fixes: https://github.com/flatpak/flatpak/issues/5383
2026-05-27 14:36:25 +00:00
Ryan Gonzalez 588eef8e65 dir: Include found refs in "ref binding metadata" errors
I accidentally screwed up the arch I passed to a `flatpak update`
invocation and was very confused as to what actually went wrong. Adding
the actual refs in the commit should help make failure cause more
obvious.

Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com>
2026-05-13 02:44:17 +00:00
razzeee 7b17f13e5d http: Replace deprecated GTimeVal with g_get_real_time()
GTimeVal and g_get_current_time() are deprecated since GLib 2.62
and tv_sec is 32-bit on 32-bit platforms, causing Y2038 overflow.
g_get_real_time() returns gint64 and is safe on all platforms.
2026-05-13 01:08:29 +00:00
razzeee cc727e7f09 dir/http: Use gint64 for g_ascii_strtoll return values
g_ascii_strtoll returns gint64; storing the result in a narrower
type (int, gint) silently truncates large values.
2026-05-13 01:08:29 +00:00
Rudi Heitbaum 68ffa487ee dir: fix build when HAVE_LIBSYSTEMD but not USE_SYSTEM_HELPER
polkit_subject_to_string() is called inside the HAVE_LIBSYSTEMD guard
in flatpak_dir_log(), but <polkit/polkit.h> is only included when
USE_SYSTEM_HELPER is defined. This causes a build failure on
configurations that have libsystemd but no system helper.

Guard the polkit call with USE_SYSTEM_HELPER and fall back to "(none)"
so the subject string is always valid for the sd_journal_send() call.

Fixes: f9d5c5c ("dir: Free result of polkit_subject_to_string")
Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
2026-05-09 18:56:16 +05:30
Sebastian Wick 17cb1135cb context: Keep fallback-x11 separate from x11 conditionals
If we convert fallback-x11 internally to a conditional x11 permission,
we cannot express current fallback-x11 stacking behavior:

lower: empty + upper: !fallback-x11 -> no x11 access
lower: fallback-x11 + upper: !fallback-x11 -> x11 access

The reason is that conditionals have no view of the lower level.

This changes things in a way that fallback-x11 stays its own socket
permission with two interactions with the x11 socket permission:

* If a upper level resets x11 (--socket=x11, --nosocket=x11), the lower
  level fallback-x11 permission gets dropped
* When computing the allowed sockets, --socket=fallback-x11 gets
  converted to --socket=if:x11:!has-wayland

Fixes: #6556
2026-04-29 10:14:29 +00:00
razzeee 6dfe1ad4d0 dir: handle missing remote tracking ref in repo_pull so that Flatpak-Upgrade-From header is sent 2026-04-21 11:28:31 +00:00
Gordon Messmer fffe38a2b0 common: Report the age of the configuration
This change will allow applications to determine if their data
is older than the flatpak configuration, to aid cache invalidation.
2026-04-20 14:00:20 +00:00
Sebastian Wickandcraftyguy Clayton Craft 43642337e4 dir: Try to delete the remote if we failed to add it entirely
Ideally, we would be able to atomically add and remove remotes, but
we're very far from that ideal state. The current behavior is really
suboptimal and leaves the remotes in a inconsistent state if
initialization failed. We can at least make it better by trying to clean
up the half-initialized mess we're currently in. It does however not
protect against SIGKILL-like aborts, as that would require it to be
atomic.

Closes: #6449
Co-authored-by: craftyguy "Clayton Craft" <clayton@craftyguy.net>
2026-04-20 13:59:14 +00:00
Sebastian Wick 5314d8cf93 dir: Succeed ensure_repo with allow_empty when system helper fails
If _flatpak_dir_ensure_repo is called with allow_empty=true, it is
allowed to fail to create the repo, and is supposed to return success in
that case.

The system helper handles this correctly, but we then call to
ensure_repo_opened no matter if the repo actuall exists and return an
error when it does not, no matter if allow_empty is set or not.

Closes: #6618
2026-04-16 15:24:46 +00:00
Sebastian Wick 72576c8239 context: Add USB Portal conditional
This can be used by apps to restrict access to `--device=usb` by using
the portal and falling back to `--device=usb` if it is not available:

   --device-if=usb:!has-usb-portal

Closes: #6557
2026-04-16 10:37:45 +00:00
Sebastian Wick b9da5795ed context: Add always-true USB device conditional
This can be used by apps to restrict access from `--device=all` to
`--device=usb` in a backwards compatible way:

   --device-if=all:!has-usb-device --device=usb

Closes: #6557
2026-04-16 10:37:45 +00:00
Simon McVittie 333459c883 dir: Use flatpak_bwrap_child_setup_inherit_fds_cb() to apply extra-data
This is functionally equivalent to the local child_setup() deleted by
this commit, except that it ignores lseek() errors, which can
legitimately happen when inheriting a non-seekable file descriptor.
Since commit ac62ebe "run: Use O_PATH fds for the runtime and app
deploy directories", any extra-data helper that runs inside a runtime
will receive a non-seekable O_PATH fd as its /usr.

Resolves: https://github.com/flatpak/flatpak/issues/6608
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-04-12 21:47:03 +00:00
Simon McVittie dc9173b2d3 bwrap: Clarify a comment
Now that we're passing the app's /app and /usr down to bwrap as O_PATH
file descriptors, it will be even more common to have non-seekable fds
in the array.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-04-12 21:47:03 +00:00
Simon McVittie d42037c526 app, context: Factor out flatpak_accept_fd_argument()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-04-10 16:00:59 +00:00
Simon McVittie c4ab58cd2e app, context: Never close fds 0, 1 or 2
These fds are stdin, stdout and stderr respectively, and are expected
to remain open at all times (if they are not needed then they can point
to /dev/null, but they should always be open). If the user gives us
`--env-fd=2` or similar, we don't want to close fd 2 before exiting
unsuccessfully: that would give us nowhere to display the error message.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-04-10 16:00:59 +00:00
Simon McVittieandSebastian Wick 15dc818874 utils: Move flatpak_get_path_for_fd to here
This was originally in flatpak-portal, then was duplicated into
flatpak-run in commit ac62ebe3 "run: Use O_PATH fds for the runtime and
app deploy directories", and subsequently removed from the portal in
commit 3c500145 "portal: Use --bind-fd, --app-fd and --usr-fd options to
avoid races". Now we want to use it in the portal again.

Helps: https://github.com/flatpak/flatpak/issues/6584
Co-authored-by: Sebastian Wick <sebastian.wick@redhat.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-04-10 12:54:13 +00:00
Simon McVittie 0902090726 run, context: Mark fd arguments as close-on-exec
On entry to `flatpak run`, these fds have been inheritable (not
FD_CLOEXEC), otherwise they would not have been inherited; but we don't
want the "payload" command to inherit them, so set them as
non-close-on-exec as soon as we receive them. In the cases where we pass
them down to the underlying bwrap command, we'll either dup them, or
set them to be inheritable again (in practice we dup them).

In particular, Chromium-derived web browsers get very upset when their
subsandbox processes inherit unexpected fds, which has been causing crashes
with no useful diagnostic information since CVE-2026-34078 was fixed.

Fixes: 1b5e886d "run: Add --usr-fd and --app-fd options"
Fixes: b5ae89ed "run: Add --(ro-)bind-fd options"
Resolves: https://github.com/flatpak/flatpak/issues/6582
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-04-10 12:29:58 +00:00
Simon McVittie 8a989c790d utils: Add flatpak_set_cloexec()
Helps: https://github.com/flatpak/flatpak/issues/6582
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-04-10 12:29:58 +00:00
Simon McVittie c14ad37229 dir: In apply_extra_data(), don't assume there is always a runtime
org.freedesktop.Platform.openh264 is one example of an extension that
runs a statically-linked extra-data helper, with no runtime. Only open
the runtime if there is one.

Fixes: ac62ebe3 "run: Use O_PATH fds for the runtime and app deploy directories"
Resolves: https://github.com/flatpak/flatpak/issues/6583
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-04-10 11:37:40 +00:00
Simon McVittie aa1a54c9da run: Cope with an empty runtime
When FlatpakDir runs extra-data helpers in apply_extra_data(),
if the helper is statically linked, it might not need a runtime at all.
For example the helper for openh264 falls into this category.

Fixes: ac62ebe3 "run: Use O_PATH fds for the runtime and app deploy directories"
Helps: https://github.com/flatpak/flatpak/issues/6583
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-04-10 11:37:40 +00:00