8434 Commits

Author SHA1 Message Date
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
3c843932aa tests: Use meson to enumerate the tests
This gets rid of the test-matrix generation, and instead enumerates all
the tests in meson.

Some people (including me) constantly modified the generated meson
instead of the test-matrix generator file because they find it so
uncommon and unusual that a meson file is generated.

This looses the combinatorial combination of the generated system, but
in practice, six lines of enumeration is not bad, and it makes things
easier to understand.
2026-04-16 12:00:46 +00:00
Sebastian Wick
e556544833 doc: Document the new has-usb-device and has-usb-portal conditionals 2026-04-16 10:37:45 +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
Cathy Hu
74027a9642 selinux: flatpak.if should be installed in distributed (bsc#1262051)
instead of `contrib`. Otherwise interfaces might clash with the
interfaces from the main policy on fedora and openSUSE.

See the independent policy guideline:
https://fedoraproject.org/wiki/SELinux/IndependentPolicy#Using_custom_interfaces

And:
https://bugzilla.opensuse.org/show_bug.cgi?id=1262051
2026-04-14 13:54:41 +00:00
Sebastian Wick
6fc45b139a portal: Actually use the AppInfo hash table
Before this change, the hash table was populated with the keyfile as key
and value, but the lookup and invalidate was done on the sender as the
key.

We never found a previous sender, and never invalidated one.

Fix this by actually using the sender as the key.
2026-04-13 17:21:33 +00:00
razzeee
655ddb42ec tests: add test-run-custom.sh to test matrix source
test-run-custom.sh was only manually appended to test-matrix/meson.build
and would be lost on regeneration. Add it to update-test-matrix so it is
properly managed.
2026-04-13 16:00:54 +00:00
Sebastian Wick
71034dd024 subprojects: Update dbus-proxy.wrap to v0.1.7
Versions up to 0.1.6 contain a security vulnerability, so let's bump it
to a version which does not.
2026-04-13 17:02:22 +01: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
Razze
51cff37bea tests: fix copy-paste bug checking mid_high instead of highest 2026-04-12 07:37:43 +05:30
Razze
758a096d72 tests: remove duplicate g_mkdir_with_parents call for dont_hide in test_full 2026-04-12 07:25:11 +05:30
Simon McVittie
0337cfde00 subprojects: Ignore .wraplock file generated by recent Meson
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-04-12 07:23:58 +05:30
Sebastian Wick
ed048c91b9 Post-branching version bump 2026-04-10 19:54:10 +02:00
Sebastian Wick
9b21874f1a 1.17.6 1.17.6 2026-04-10 19:51:18 +02:00
Sebastian Wick
1d1d189ada Update translation files for 1.17.6 2026-04-10 19:51:18 +02:00
Sebastian Wick
7776457bfa Post-branching version bump (for 1.17.5 which was forgotten) 2026-04-10 19:50:49 +02:00
razzeee
39dda201c9 tests: fix copy-paste bug using is_arch instead of is_branch in test_decompose 2026-04-10 16:01:35 +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
razzeee
f5f70a511e tests: Add messages for missing os-release and pre-create directory checks 2026-04-10 15:52:46 +00:00
razzeee
cff9812514 repair: disable auto-pin to preserve pin state across reinstalls
When repair (re)installs runtimes via a transaction, the transaction
auto-pins every runtime it touches. This causes repair --reinstall-all
to pin every installed runtime, cluttering the pin list with runtimes
that were never explicitly pinned by the user and preventing
flatpak remove --unused from cleaning them up.

Fix this by disabling auto-pinning on the repair transaction so that
the pin state is left exactly as it was before the repair.

Fixes https://github.com/flatpak/flatpak/issues/6565
2026-04-10 15:36:00 +00:00
Sebastian Wick
1364527683 tests: Check that flatpak-run fd-arguments do not leak to the command
flatpak-run takes a number of arguments which are file descriptor
numbers. Those file descriptors are supposed to set something up in the
way the instance gets spawned, but should never make it to the wrapper
command.
2026-04-10 14:50:21 +00:00
razzeee
3eadc2c379 tests: remove duplicate g_set_print_handler call in test_format_choices teardown 2026-04-10 14:50:09 +00:00
Simon McVittie
50dda82eb0 libtest: Allow adding a new ref to an existing temporary ostree repo
When we run `tests/test-run-custom.sh` as a build-time test,
we expect to already have the necessary runtimes, apps, etc. in
`${builddir}/tests/runtime-repo`. However, when running "as-installed"
tests, we're using a fresh temporary ostree repo for each test.
Merely having the repo exist is not enough: for some tests, and in
particular `tests/test-run-custom.sh`, it needs to have more than one
runtime available.

Resolves: https://github.com/flatpak/flatpak/issues/6591
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-04-10 14:13:39 +00:00
Simon McVittie
28634c7f52 portal: Reinstate flatpak_get_path_for_fd() checks
As with the previous commit, historically we would debug-log but
otherwise silently ignore attempts to expose a file in a sandboxed
subsandbox that doesn't have a suitable path.

For example, org.gnome.Epiphany (or possibly WebKitGTK) asks to expose
files from /app and /usr in the subsandbox. When we ignored those
requests (because /app and /usr have a different meaning on the host
system), the app worked as intended anyway, because the subsandbox has
access to the app's /app and the runtime's /usr whether they're
explicitly added or not, so it all worked out OK. However, treating
this as a fatal error (as it arguably should have been) broke
Epiphany's subsandboxes.

Fixes: 3c500145 "portal: Use --bind-fd, --app-fd and --usr-fd options to avoid races"
Resolves: 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
75ab6eebb8 portal: Log and ignore unusable sandbox-expose fds instead of erroring
For the sandbox expose fds, a historical quirk of this code is that if
the checks in get_path_for_fd() failed, we would merely log at g_info()
level (usually only shown when debugging the portal), and otherwise
silently ignore the request to expose the fd in the sandbox.

With hindsight this was probably not the right thing to do, but apps
could well be relying on it now. For example, there are indications
that Epiphany might send a memfd from the main instance to a subsandbox,
which never actually worked, but will break that subsandbox process
if that's treated as a fatal error.

Fixes: 3c500145 "portal: Use --bind-fd, --app-fd and --usr-fd options to avoid races"
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
4ef2421bd2 portal: Avoid crash if sandbox-expose-[ro-]fd is out of range
If the handle is not in the range `0 <= handle < fds_len`, but no
GError is set, we'd have crashed when we dereferenced error->message.
Instead, log an error and early-return, matching what we do for
app-fd, usr-fd and the array of inheritable fds.

Fixes: 3c500145 "portal: Use --bind-fd, --app-fd and --usr-fd options to avoid races"
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
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
bbhtt
79cb10e880 tests: Add test for NoRuntime extra-data app 2026-04-10 11:37:40 +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
Sebastian Wick
2a196e0bde 1.17.5 1.17.5 2026-04-09 01:42:16 +02:00
Sebastian Wick
2994060fc7 Update translation files for 1.17.5 2026-04-09 01:42:16 +02:00
Sebastian Wick
8599a5109c tests/test-run-custom: Test --bind-fd and --ro-bind-fd 2026-04-08 23:19:02 +00:00
Sebastian Wick
a8e3c72454 tests/test-run-custom: Test --usr-path, --usr-fd, --app-path, --app-fd 2026-04-08 23:19:02 +00:00
Alberto Garcia
c75d7e2c49 portal: update max_fd after creating the instance ID pipe
fd_map_remap_fd() is called several times after this, and without this
change it can allocate a target fd that collides with instance_id_fd.

Only the write end of the pipe needs to be considered because that's
the one passed to the child.

Closes: https://github.com/flatpak/flatpak/issues/6570
2026-04-08 22:04:46 +00:00
Sebastian Wick
e127ed5aea run: Add bind-fd and ro-bind-fd binds after all other binds
This is only moving it a bit down because
flatpak_run_add_environment_args still adds a whole bunch of binds which
then can over-mount the user requested binds (bind-fd, ro-bind-fd).
2026-04-08 20:48:43 +00:00
Sebastian Wick
db446ef998 run: Use the same FD validation for all FD options 2026-04-08 20:48:43 +00:00
Sebastian Wick
68113de38e run: Do not close --bind/--ro-bind 2026-04-08 20:48:43 +00:00
Sebastian Wick
fdc4f963a1 utils: Improve error message when passing an FD numer which is not a FD 2026-04-08 20:48:43 +00:00
Sebastian Wick
abd44a6d8d run: Fix fd tracking in flatpak_run_add_app_info_args
Calls to flatpak_bwrap_add_args_data_fd take ownership over the fd they
take. Closing them while they are still in the bwrap struct will abort
later when the bwrap struct gets freed and it tries to close the already
closed fd.

Fix this by using glnx_autofd and g_steal_fd.
2026-04-08 20:48:43 +00:00
Alberto Garcia
3b0bd01263 portal: use g_array_index() to read from expose_fds / expose_fds_ro
The data field of a GArray is a gchar* but we're storing integers
here, so use the proper method to ensure that we're getting the
element at the right offset and with the correct type.
2026-04-08 20:05:50 +00:00
Simon McVittie
fde4716f67 run: Mount original app on /run/parent/app when using --app-path=""
Before addressing CVE-2026-34078, we would always mount the original app
*somewhere*, either /app (in the normal case) or /run/parent/app (when
using a custom or empty /app for the subsandbox). The empty-app case
regressed during the fix for CVE-2026-34078; bring back previous behaviour.

Fixes: ac62ebe3 "run: Use O_PATH fds for the runtime and app deploy directories"
Resolves: https://github.com/flatpak/flatpak/issues/6568
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-04-08 12:21:09 +00:00
Xiangzhe
066babba75 run: Fix checking wrong variable in runtime fd selection
In flatpak_run_app(), the else-if branch that handles
FLATPAK_RUN_APP_DEPLOY_USR_ORIGINAL was checking custom_app_fd instead
of custom_runtime_fd. When custom_app_fd is APP_EMPTY (-3) and
custom_runtime_fd is USR_ORIGINAL (-2), the condition would not match
and fall through to g_assert_not_reached(), aborting the process.

This broke sub-sandbox spawning with --app-path="" (empty app), which
is used by steam-runtime-check-requirements to verify that Flatpak's
sub-sandbox mechanism works.

Fixes: ac62ebe3 "run: Use O_PATH fds for the runtime and app deploy directories"
Helps: https://github.com/flatpak/flatpak/issues/6568
2026-04-08 12:21:09 +00:00
Sebastian Wick
c52cca2d73 Post-branching version bump 2026-04-08 02:44:33 +02:00
Sebastian Wick
2c7f24dcbf 1.17.4 1.17.4 2026-04-08 02:37:05 +02:00