Commit Graph

8394 Commits

Author SHA1 Message Date
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
Sebastian Wick
6b1e65dc79 Update translation files for 1.17.4 2026-04-08 02:36:29 +02:00
Sebastian Wick
f1bdc6aeae system-helper: Only remove an ongoing pull if users match
The code would always remove a pull from the hashtable, and then check if the
users match and abort if they don't. Either way, the pull gets dropped.

Fix this by only removing the pull if the dir and the user match.
2026-04-07 16:30:26 -04:00
Sebastian Wick
3c111d9e19 utils: Do not follow symlinks in flatpak_open_file_at
We use flatpak_open_file_at in the context of the system helper to open
files written by a user. This means that we want to prevent DOS and
exposing files which only the system helper has access to.

To prevent DOS and avoid side-effects, the file is opened with
O_NONBLOCK and O_NOCTTY.

To prevent leaking files, the file is supposed to not open symlinks.
This part, we failed at. We check if the opened file is a regular file,
but what we actually checked is, if the file a symlink might point at is
a regular file.

Fix this by also specifying O_NOFOLLOW in openat.
2026-04-07 16:24:24 -04:00
Sebastian Wick
c94b780e58 utils: Only remove cached files in the cache directory
The function flatpak_switch_symlink_and_remove is used to implement a
cache for ld.so (regenerate_ld_cache). If the active symlink changes to
a new cache file, the old cache file is supposed to get removed.

The symlink still points to the old cache file, so we would remove the
file that it points to and then point at the new file.

Because the symlink is under the app's control, the symlink can point
anywhere, and the removal happens in the host context, which allows an
app to remove arbitrary files on the host.

The filename of the cache files are checksums, which means that we can
ensure that the link is a file in the same directory of the link by
checking that it only contains the chars a-zA-Z0-9.
2026-04-07 16:21:14 -04:00
Sebastian Wick
3c500145fd portal: Use --bind-fd, --app-fd and --usr-fd options to avoid races
Now that flatpak_run_app accepts fds for app and runtime deploy, as well
as bind and ro-bind fds, and flatpak-run exposes the functionality, we
can finally hook this all up to the flatpak portal!
2026-04-07 16:17:51 -04:00
Sebastian Wick
b5ae89ed33 run: Add --(ro-)bind-fd options
Exposes the functionality added to flatpak_run_app in the previous
commit with two new options.
2026-04-07 16:17:51 -04:00
Sebastian Wick
2ed87aff36 run: Add (ro-)bind fds to flatpak_run_app
The flatpak portal allows apps to expose files and folders from within
the sandbox to a side-sandbox using flatpak-spawn. So far it has used
the --filesystem option to mount those files and folders, but it takes a
path. Paths are inherently racy and they allow the app to swap out any
component of the path with a symlink after handing it off. If they win
the race, flatpak will mount a completely different directory.

This adds a new way to mount files and directories based on O_PATH
file descriptor that needs to provided when execing the flatpak binary.
2026-04-07 16:17:51 -04:00
Sebastian Wick
1b5e886d7f run: Add --usr-fd and --app-fd options
Exposes options to pass in a fd for the runtime and app deploy. The
flatpak portal will make use of this in a following commit.
2026-04-07 16:17:51 -04:00
Sebastian Wick
ac62ebe308 run: Use O_PATH fds for the runtime and app deploy directories
This also allows us to use glnx_chaseat, and other at-functions to
traverse the filesystem tree in a safe way.

This is important because the app and runtime deploy directories can be
under an attackers control. The flatpak portal for example allows
sandboxed apps to provide them.

In particular, attacks where the deploy dirs get replaced by a symlink
pointing into the host system will be stopped by this.

Note that this change alone is not enough to avoid the attack, and the
portal has to be changed as well.
2026-04-07 16:17:51 -04:00
Sebastian Wick
aab3f42374 flatpak-bwrap: Use glnx_close_fd as clear func
We already have a function which clears a fd that a pointer points to,
so let's use it instead of duplicating the code.

Will become useful in a later commit as well.
2026-04-07 16:17:51 -04:00
Sebastian Wick
50af610ff4 utils: Add flatpak_parse_fd
This is meant to parse file descriptor strings passed via the command
line. It is not a security mechanism and will happily accept fds 0-3 as
well.
2026-04-07 16:17:51 -04:00
Sebastian Wick
2acdd330d8 flatpak-bwrap: Add dup-ing variant flatpak_bwrap_add_args_data_fd_dup 2026-04-07 16:17:51 -04:00
Simon McVittie
1293a6441b Update subtree: libglnx 2026-04-07
* fdio: Avoid relying on VLAs or gcc-specific constant-folding
* errors: Fix URL to an old libgsystem commit
* lockfile: Assert non-null path in make_lock_file for analyzers
* backports: Add g_clear_fd
* glnx-errors.h: add glnx_fd_throw[_*] variants
* fdio: Add glnx_fd_reopen
* local-alloc: Remove duplicate definition of glnx_unref_object
* fdio: Add glnx_statx
* chase: Add glnx_chaseat which functions similar to openat2
* chase: Add glnx_chase_and_statxat

Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-04-07 20:41:49 +01:00
Sebastian Wick
02fc9738a0 Revert "run: Add --no-scope to flatpak run"
This reverts commit c7824ae5f3.

We want to use the cgroup as authentication for flatpak instances in the
future. Giving explicit control over this to the user destroys the
invariant we need without a backwards incompatible change.
2026-04-07 15:13:44 +00:00
Simon McVittie
ccea836b79 Merge branch 'wip/smcv/autotools' into 'master'
build: Include glnx-chase in the Autotools build system, too

See merge request GNOME/libglnx!71
2026-04-07 14:54:55 +00:00
Simon McVittie
e3006ead94 build: Include glnx-chase in the Autotools build system, too
Fixes: a973baad "chase: Add glnx_chaseat which functions similar to openat2"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-04-06 21:29:01 +01:00
fortime
c7824ae5f3 run: Add --no-scope to flatpak run
Don't run an app inside a transient systemd scope.

Closes: #6497
Fixes: #5870

Signed-off-by: fortime <palfortime@gmail.com>
2026-04-06 06:46:38 +05:30
Sebastian Wick
406129532f run: Allow /dev/ntsync unconditionally
It seems to not expose any new capabilities and neither seems to greatly
affect the kernel attack surface, so let's just enable it
unconditionally.

If this turns out to be a bad decision, we can remove it again and maybe
guard it behind a new --device permission.

Closes: #6199
2026-04-01 13:09:03 +00:00
Sebastian Wick
10470a82d3 tty-utils: Flush stdin before and after issuing Cursor Position command
If the user presses any key while we the CLI transaction UI is being
shown, it ends up in stdin. When we issue the Cursor Position command,
the result is appended to stdin and we fail to match on it because of
the proceeding bytes.

Similarily, if we fail to match the command output (bad data, too slow,
..), we leave behind data in stdin which will be echoed back to the
terminal when we restore the initial termios which icnludes ECHO in
c_lflag.

Let's use TCSAFLUSH to flush out stdin data before we issue the command,
which should help with matching the expected response.

Let's also use TCSAFLUSH when we restore the previous termios to make
sure the stdin is clean and we don't echo whatever remains in stdin.

Closes: #2712
2026-03-31 10:46:13 +00:00
Baurzhan Muftakhidinov
759d6c8615 Add Kazakh translation 2026-03-30 06:23:49 +00:00
Kolja Lampe
3178d97321 common: allow automatic branch following for extensions
When an application or runtime is updated and its metadata requests a
new branch of an extension, Flatpak should automatically pull the new
branch if the user already has at least one branch of that extension
installed.

This ensures that "no-autodownload" extensions (like GIMP plugins)
stay functional after an update that requires a new branch, while still
respecting the user's explicit opt-in (the existing installation of
a previous branch).

Fixes: https://github.com/flatpak/flatpak/issues/4208
2026-03-29 19:25:09 +00:00
Kolja Lampe
f2ff272157 tests: Add test-preinstall.sh to the test matrix source
test-preinstall.sh was present in the generated test-matrix/meson.build
but missing from TEST_MATRIX_SOURCE in update-test-matrix, meaning it
would be dropped if the matrix were regenerated.
2026-03-28 14:23:02 +00:00
Simon McVittie
aae4505722 Merge branch 'wip/smcv/chase' into 'master'
chase: Fix a memory leak and some undefined behaviour

See merge request GNOME/libglnx!69
2026-03-24 20:45:24 +00:00
Simon McVittie
6dbe18bcda chase: Factor out a function to append to the queue
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-03-24 20:43:47 +00:00
Simon McVittie
46205a62d2 chase: Don't leak struct glnx_statx when we go up a level
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-03-24 20:43:47 +00:00
Simon McVittie
916b70619c chase: Don't left-shift signed integer 1 by 31 places
This overflows, which is undefined behaviour (in practice it will usually
wrap around into unsigned space, but this can't be guaranteed).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-03-24 20:43:45 +00:00
Sebastian Wick
7c1e8bd756 Merge branch 'wip/chaseat' into 'master'
chase: Safely traversing the filesystem

See merge request GNOME/libglnx!64
2026-03-24 11:21:17 +00:00
Марко М. Костић (Marko M. Kostić)
6601295c36 Add Serbian translation 2026-03-20 19:07:51 +05:30
Kristjan ESPERANTO
3cad41b163 Add Esperanto translation 2026-03-20 19:05:47 +05:30
Debarshi Ray
66bf6c76c7 dir: Fix the order of architecture and branch in triplets in comments
Fallout from 0a9d5ac7f2
2026-03-19 23:40:29 +00:00
Debarshi Ray
70ddf44b40 builtins-utils, dir: Be more strict about what is acceptable
The 'arch' parameter of flatpak_dir_remote_fetch_indexed_summary() is
used to construct the names of the caches, and can't be NULL.  This
function is used by flatpak_remote_state_ensure_subsummary(), which is
used by ensure_remote_state_arch().  So, the parameter can't be NULL in
those either.
2026-03-19 23:40:29 +00:00
Debarshi Ray
00f22d406d installation: Avoid dereferencing a potentially NULL pointer
... in flatpak_decomposed_get_ref().

Fallout from db11607016
2026-03-19 23:40:29 +00:00
Debarshi Ray
1fa71d98db repo-utils: Remove dead code
The first two conditional branches in the loop are beyond the
terminating condition of the loop.

Fallout from 2c6fec556f
2026-03-19 23:40:29 +00:00
Debarshi Ray
52d10816c7 completion: Avoid buffer overrun with strings having too many elements
Here are some strings representing valid refs:
  app/org.test.App/x86_64/stable - full ref
  org.test.App/x86_64/stable - full ref without prefix
  org.test.App - only app ID
  org.test.App/x86_64 - only app ID and arch
  org.test.App//stable - only app ID and branch

Therefore, if a ref's prefix (ie., 'app/' or 'runtime/) is skipped,
then there can only be a maximum of 3 other elements in it.

Right now, it's possible for find_current_element() to return a count
of 4, if the string being completed is invalid and has some extra
elements or slashes in it.  This count is later used to index the
cur_parts array which only has 4 elements in it.  This opens up the
possibility of a buffer overrun.

Invalid strings with extra elements or slashes can't be further
completed because none of the existing refs will match them.
Therefore, such strings should be outright skipped.

For the rest of the valid strings, the exact intended branch name is
never known, because the branch element doesn't have a trailing slash
and hence appears to be a prefix.  Therefore, it's not possible to use
the branch to find a list of existing refs that could possibly
complete the string.

Fallout from 7018717ce2
2026-03-19 23:40:29 +00:00
Debarshi Ray
c0ad159e4a system-helper: Remove redundant (and misleading) NULL check
First of all, g_strcmp0() is NULL-safe, so there's no need to check if
ref_str is NULL or not.

Secondly, the NULL check triggers Coverity.  It thinks that ref_str
might be NULL in the 'else' branch, where ref_str is unconditionally
accessed by flatpak_decomposed_new_from_ref().  There's no need to be
concerned about this because ref_str can't be NULL.  It's one of the
parameters of the o.fd.Flatpak.SystemHelper.Deploy D-Bus method.  It's
defined as an 's', and NULL is not a valid value for 's'.  In fact,
this D-Bus argument is assumed to be not NULL when the Deploy method is
handled.

Fallout from 701602c6ca
2026-03-19 23:40:29 +00:00
Debarshi Ray
81d8ca7a1f system-helper: Improve the errors on failure to get a remote's URL
As codified in flatpak_dir_get_remote_disabled(), a NULL URL caused by
a corrupt configuration file or a missing "url" key doesn't represent
a disabled remote.  It's only disabled if ostree_repo_remote_get_url()
successfully returns an empty URL (ie., "").

It might be less confusing if the error messages are consistent with
this subtle difference.
2026-03-19 23:40:29 +00:00
Debarshi Ray
ab69f8ef7e dir, system-helper: Don't ignore errors when getting a remote's URL
Of the 27 instances where ostree_repo_remote_get_url() is used, these
are the only ones where the return value is ignored.  This triggers
Coverity.

It might not always be strictly necessary to handle the errors, but
doing so can only help with debugging.  However, in the case of
flatpak_dir_get_remote_disabled() this clarifies the subtle difference
between an empty URL (ie., ""), and a NULL URL caused by a corrupt
configuration file or a missing "url" key.
2026-03-19 23:40:29 +00:00
lumingzh
74501ad08a update Chinese translation 2026-03-19 21:22:39 +05:30
Simon McVittie
0c9a818f8d tests: Mention [systemd-]localed in debug messages, not "located"
This was not a typo for "located": the daemon is systemd-localed,
or localed for short.

Fixes: bb549168 "fix: cross typos, detail below"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-03-19 21:16:19 +05:30
Sebastian Wick
0a0e9faa04 context: Fix make-sandboxed with multiarch by owning the old permission
We would get a reference to the old permission, then free it, and then
insert the freed pointer into the new hashtable again.

Closes: #6524
Fixes: 6667e1d3 ("context: Use the new permission system for shares and features")
2026-03-19 15:06:24 +00:00