Commit Graph

2490 Commits

Author SHA1 Message Date
Kalev Lember
4bf4f32c16 dir: Make sure all parse_ref_file out params are consistently cleared
parse_ref_file() cleared all its out params to NULL, with the exception
of collection_id_out. Make sure to clear this one as well to avoid
surprises in the future.

Fixes commit ae7d96037 that added collection ID support to flatpakref.
2024-07-16 17:55:31 +01:00
Daniel Winzen
07f55b32a5 run: Test whether sysfs mountpoints are accessible before mounting them
In some restrictive environments like Whonix, access to /sys/ is blocked by file
permissions (chmod 0700 /sys). Previously, Flatpak would give bwrap a
command-line that will fail altogether in these locked-down environments.
Instead, fall back to running the app with no access to these /sys
subdirectories.

The application will be unable to enumerate game controllers and similar
hardware devices in this situation, but that's the same limited functionality
that would be seen for a non-sandboxed application.

Resolves: https://github.com/flatpak/flatpak/issues/5138
2024-07-16 17:54:27 +01:00
Simon McVittie
33212f5c11 utils: Remove flatpak-variant-private.h, no longer necessary
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
4add324060 prune: Include flatpak-variant-private.h before its -impl-private.h
This ensures that declarations are visible.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
25d38bab0a utils: Remove unnecessary flatpak-ref-utils-private.h inclusion
Include flatpak-ref-utils-private.h explicitly in each remaining
module that needs it (mostly for FlatpakDecomposed).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
87360c96e0 utils: Move remaining direct ostree dependencies to repo-utils
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
97cddd6e48 utils: Move more repository functionality to repo-utils
This further reduces circular dependencies: utils no longer has a
circular dependency with repo-utils or xml-utils.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
3271f9c25d utils: Export flatpak_get_compat_arch()
This will allow its caller to be moved into repo-utils.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
1b85a2c090 utils: Move more summary parsing into repo-utils
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
06970e015f utils: Move more repository functionality into repo-utils
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
31590889f8 ref-utils: Move flatpak_get_arch_for_ref() to here
The declaration was already in flatpak-ref-utils-private.h.

Fixes: 5dae1fc6 "Break out ref helper functions to separate file"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
c98a7c024f utils: Move OstreeRepo configuration accessors to a new translation unit
This is a step towards removing the libostree dependency from
flatpak-utils, which should be one of the lowest-level components.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
485f6bc5c5 common: Explicitly include ostree.h where needed
A subsequent commit will remove it from flatpak-utils-private.h.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
14db9d48cf common: Break out the parts of flatpak-utils that deal with FlatpakDir
This breaks the circular dependency between flatpak-utils and flatpak-dir.
There is still a circular dependency between flatpak-dir and
flatpak-dir-utils, but I don't want to make flatpak-dir even larger.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
3c82620bab repo-utils: New header for some implementation details of a repository
This will reduce circular dependencies involving FlatpakDir.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
89f8f3767a common: Move OCI registry manipulation into FlatpakOciRegistry
This is a step towards making flatpak-utils conceptually "smaller"
than all other translation units, with no dependencies beyond GLib and
libglnx. In particular, consolidating all the OCI registry manipulation
into one place means we can build other translation units without
libarchive.

This would also be a step towards being able to provide a build-time
option to build a libostree-only version of Flatpak without the OCI
feature or the direct libarchive dependency, if someone wanted to
implement that.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
722fec4581 utils: Include flatpak-metadata-private.h instead of -run-private.h
This avoids a circular dependency between -run and -utils.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Georges Basile Stavracas Neto
1b4ff8d526 flatpak-run-dbus: Allow two AT-SPI Registry signals in
These signals can be used by apps to monitor whether they need to emit
signals on the a11y bus or not. This can very significantly reduce
chattery on the a11y bus, and at least WebKit relies on these signals
to be broadcasted in.

The PR https://github.com/flatpak/xdg-dbus-proxy/pull/61 is required
for this changeset to work as expected, but it can land independently
as `--broadcast` is supported by xdg-dbus-proxy.
2024-07-09 09:23:32 -03:00
Sebastian Wick
24a4c2464e dir: Free the returned GVariant of g_dbus_connection_call_sync
Closes: https://github.com/flatpak/flatpak/issues/5856
Fixes: 9532c8d3 ("dir: Reload DBus daemon config to ensure services get picked up")
Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
2024-06-26 11:47:53 +01:00
Sebastian Wick
c12a5da619 run: Support zoneinfo dirs from $TZDIR env 2024-06-21 11:12:57 -03:00
Sebastian Wick
36b6c86065 common: Simplify tzdir logic in flatpak_get_timezone 2024-06-21 11:12:57 -03:00
Sebastian Wick
da71c451fc common: Add flatpak_get_tzdir() helper 2024-06-21 11:12:57 -03:00
Hubert Figuière
9d60df4d0c flatpak-dir: Fix a memory leak when installing a package
The path was clobbered make the g_autoptr no work

Signed-off-by: Hubert Figuière <hub@figuiere.net>
2024-05-13 13:44:26 +01:00
vgdaut
739065e432 dir: Uniformize two similar strings
Related to issue #4746. Unnecessary end whitespaces were removed. Write "remote %s" instead of "remote '%s'".
2024-05-05 13:03:11 -05:00
Simon McVittie
363fffcb08 xml-utils: Don't expose symbols that don't need to be visble
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-03 13:21:29 +01:00
Simon McVittie
6e81bc6f28 common: Move functions for dealing with AppStream XML to their own file
This seems like an obvious set of functionality to be grouped together
in service of the wider goal of making flatpak-utils smaller and more
manageable.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-03 13:21:29 +01:00
Simon McVittie
ad0aa467d0 common: Don't depend on generated D-Bus code in utils module
Each of these is only needed in one place, so move them there. This is
another step towards the utils module being the lowest-level.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-03 13:21:29 +01:00
Simon McVittie
a01371ce02 common: Move flatpak_context_get_allowed_exports to FlatpakContext
This allows us to break a circular dependency between utils and context.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-03 13:21:29 +01:00
Simon McVittie
74abbbebfd exports: Remove unused headers
The exports module doesn't actually need these, and this removes a
circular dependency: previously, exports both depended on and was
depended on by dir.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-03 13:21:29 +01:00
Daniel Stone
18b85083b9 run: Unset more Vulkan layer/driver paths
Following on from b8d8d80c61, add more environment variables used by
the Vulkan loader which expect paths to be provided.

These paths are typically referencing the host filesystem; if the user
is referencing paths only available in the sandbox, they can use --env
or overrides for them.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2024-04-24 18:13:17 +01:00
Daniel Stone
0f2661045d run: Unset EGL driver paths
Similar to how b8d8d80c61 inhibited passthrough of environment
variables pointing the Vulkan loader towards a specific ICD, do the same
for the EGL paths used by libglvnd to discover the GL driver to use, as
well as for NVIDIA's EGLStream shim.

These paths are typically referencing the host filesystem; if the user
is referencing paths only available in the sandbox, they can use --env
or overrides for them.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2024-04-24 18:13:17 +01:00
Patrick Griffis
abcc001da8 run: Don't inherit LD_PRELOAD/LD_AUDIT from the host
I don't think this env var makes much sense to pass into the sandbox
for similar reasons to LD_LIBRARY_PATH. Libraries from the host
just aren't relevant.

Users can still pass `--env=LD_PRELOAD=/foo` to use this functionality.
2024-04-24 10:03:59 -05:00
Simon McVittie
c95214b62b flatpak-dir: For completeness, always add "--" to bwrap arguments
This particular bwrap invocation cannot cause a sandbox escape because
the command to run is hard-coded, but it's more clearly correct if we
pass "--" to every bwrap invocation.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-04-17 18:10:43 +01:00
Alexander Larsson
bbab7ed1e6 When starting non-static command using bwrap use "--"
This ensures that the command is not taken to be a bwrap option.

Resolves: CVE-2024-32462
Resolves: GHSA-phv6-cpc2-2fgj
Signed-off-by: Alexander Larsson <alexl@redhat.com>
[smcv: Fix DISABLE_SANDBOXED_TRIGGERS code path]
[smcv: Make flatpak_run_maybe_start_dbus_proxy() more obviously correct]
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-04-17 18:10:31 +01:00
Virtuti Militari
1f770f3d92 Fix export dynamic linker option
As of LLVM/Clang 18 and LLD18 linker with the -export-dynamic option compilation ends with an error:
cc: error: unknown argument: '-export-dynamic'

For GCC and the default compiler this is not a problem. The problem occurs in Clang/LLD 18.

Fix tested on Mandriva via 39f1c03e91
2024-04-08 14:44:08 +01:00
Chris Williams
d900529a24 run: Ignore leftover eol-rebase data dir symlink
If the current app data dir is removed, flatpak would try to migrate the
symlink that it had previously created, creating a symlink loop.

Fixes: #5668
2024-03-27 14:24:59 +00:00
Chris Williams
55283a062b locale-utils: Always get system locale languages from localed
This restores support for 'mixed' system locales where different locale
categories are configured with different languages. AccountsService
currently only includes the LC_MESSAGES language from the system locale.

Helps #5497
2024-03-27 14:22:45 +00:00
Simon McVittie
f9cbfe1fd6 flatpak-prune: Make sure to calculate hash in the unsigned domain
Otherwise, an out-of-bounds left shift can occur, as diagnosed by
UBSan here:

    ../../../../src/flatpak/common/flatpak-prune.c:387:14: runtime error: left shift of 253 by 24 places cannot be represented in type 'int'

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-03-21 20:20:29 +00:00
Simon McVittie
2fc71b1f80 Fix missing declaration for g_fdwalk_set_cloexec() with GLib 2.80.x
With older GLib, it's provided by libglnx, but with newer GLib, we need
to include the correct header.

Fixes: 7b1cd206 "Replace flatpak_close_fds_workaround() with g_fdwalk_set_cloexec()"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-03-21 20:20:15 +00:00
Sebastian Wick
9532c8d333 dir: Reload DBus daemon config to ensure services get picked up
This is best effort. There is a 2s timeout and if something fails
everything continues on.

This is called from flatpak_dir_run_triggers because it gets called
whenever we might have changes to the exported service files.

Fixes #3342

Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
2024-03-20 20:08:58 +00:00
Chris Williams
73d4a3b062 appdata: exclude <name> element inside <developer>
<developer_name> has been deprecated in favor of <developer> with a
<name> child. We need to ensure that this developer name isn't parsed
as the application name.

Fixes: #5700
2024-03-12 08:31:08 -05:00
Pablo Correa Gómez
2cb17b4eb8 Do not hard-code fusermount, add option or auto-detect instead
The hard-coding is not appropriate. According to libfuse 3.0.0 release
notes: "The fusermount and mount.fuse binaries have been renamed to
fusermount3 and mount.fuse3 to allow co-installation of libfuse 2.x
and 3.x". Some distributions seem to install a symlink, but this is
not upstream's default behavior.

In addition, fusermount might be provided from non-distro sources. So
a build-time option takes precedence over auto-detection logic.

Fixes #5104

Fixes #5694
2024-02-19 12:05:05 +00:00
Simon McVittie
8e63eda867 Remove Autotools build system
As discussed in #5695, I think we're reaching a point where removing
Autotools is preferable to fixing it.

1.14.x continues to use Autotools, so platforms whose Meson version is
too old can stay on that branch until it becomes unsupported. We have
a very conservative Meson dependency (Ubuntu 20.04).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-16 19:30:32 +00:00
Philip Withnall
7268ff628e common: Fix use of deprecated libmalcontent symbols
These symbols were soft-renamed in libmalcontent 0.5.0 (released in
February 2020). We can probably now safely depend on that, and use the
renamed versions.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-15 20:44:53 +00:00
Simon McVittie
7b1cd20696 Replace flatpak_close_fds_workaround() with g_fdwalk_set_cloexec()
flatpak_close_fds_workaround() wasn't technically async-signal-safe,
because the requirement for sysconf() to be async-signal-safe was
removed in POSIX.1-2008.

It could also leave high fds open in some cases: in practice
sysconf(_SC_OPEN_MAX) returns the soft resource limit, but if our
resource limit has been reduced by an ancestor process, we could
conceivably still have fds open and inherited above that number.

We can fix this by using g_fdwalk_set_cloexec() with GLib >= 2.79.2,
or the backport in libglnx with older GLib. This uses close_range()
if possible, falling back to rummaging in /proc with async-signal-safe
syscalls.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 16:06:41 +00:00
Simon McVittie
ec796ec37f flatpak-bwrap: Don't leak runtime_dir_members
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 11:06:30 +00:00
Simon McVittie
14846313f9 flatpak_remote_commit_filter: Don't leak config GKeyFile
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 11:06:30 +00:00
Simon McVittie
a96834bb32 populate_commit_data_cache: Don't leak a floating GVariant
var_variant_dup_to_gvariant() returns a floating GVariant, and
g_variant_get_child_value() won't sink it, so we need to free it.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 11:06:30 +00:00
Simon McVittie
fd56fb85f8 populate_commit_data_cache: Don't leak child value
g_variant_get_child_value() returns a non-floating reference, so
g_variant_builder_add() will not sink it.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 11:06:30 +00:00
Simon McVittie
b97704dee6 dir: Don't store a pointer in a gsize
This is, strictly speaking, not allowed. On uncommon architectures like
CHERI, a pointer can be larger than a gsize.

This might also help to avoid AddressSanitizer losing track of
reachability, so that it won't think the array and its contents have
been leaked.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 11:06:30 +00:00