Commit Graph

2239 Commits

Author SHA1 Message Date
Phaedrus Leeds
6f5bb3597e Change how automatic pinning is implemented
This commit re-works how we automatically "pin" runtimes that are
explicitly installed, to prevent them from being removed automatically.
In this implementation we do the update to the config as part of the
deploy, which has the following advantages:
(1) It ensures that there's never a confusing polkit prompt about
configuring the software installation when the user asked for a runtime
to be installed (https://github.com/flatpak/flatpak/issues/4200)
(2) It means we don't have to rely on the code on the error path of
flatpak_transaction_real_run() to un-pin the runtime in case something
went wrong with the installation, since we pin it almost atomically with
the deploy.

Fixes #4200
2021-11-15 11:10:27 -08:00
Phaedrus Leeds
9dbd265cdd Don't use app title from flatpakref as remote title
On two different code paths we were using the "Title" field in
flatpakref files as the title of a remote, which is incorrect. In most
cases, the remote added via the RuntimeRepo key will be the same as the
remote the app is from, so when the remote is added for the runtime, its
title will be correctly set using the Title value from the flatpakrepo
file and the app will therefore have an origin remote with a title set.
This is not currently true for flatpakref files that use
SuggestRemoteName=, see https://github.com/flatpak/flatpak/pull/4513

For flatpakref files that use a different remote than the RuntimeRepo,
we don't currently have a way for the title to be set automatically;
perhaps we should (https://github.com/flatpak/flatpak/issues/4512).

Fixes https://github.com/flatpak/flatpak/issues/4499
2021-11-15 11:37:39 +01:00
Guido Günther
766bf5f08a build-finish: Export appstream metainfo into a single directory
This is similar to what is done for desktop files and allows
applications to use a flatpak's metainfo to retrieve e.g.  required
input controllers or the supported screen sizes. Similar to what can be
done for non-flatpak'ed apps by looking at
/usr/share/{metainfo,appdata}.

Since flatpak moves the metadata from metainfo/ to appdata/ during build
we only need to export files from that single directory.

Signed-off-by: Guido Günther <agx@sigxcpu.org>
2021-11-15 11:34:24 +01:00
Phaedrus Leeds
ad169f1224 transaction: Utilize runtime repo info for origin remote
Many of the fields allowed in flatpakrepo files are not allowed in
flatpakref files, e.g. Comment, Description, Homepage, etc. So there is
no straightforward way to ensure those are set correctly when the user
installs something with a flatpakref file. However in most cases the
repo specified by the RuntimeRepo key is also the repo providing the
main ref, so in those cases it makes sense to utilize all the metadata
provided in the flatpakrepo file when creating a remote to provide
updates for the app being installed. We were already doing this when the
SuggestRemoteName key was unset; this commit makes it so that we utilize
that metadata also when SuggestRemoteName is present.
2021-11-15 11:25:30 +01:00
Phaedrus Leeds
49d9052d22 Ensure refs are updated from their origin
It can happen that a related ref is installed from a different remote
than the thing it's related to. We always want to update things from
their origin remote. However as of now FlatpakTransaction resolves the
commit of a related ref to the one available from the main ref origin,
and later sets the remote for the operation to the installed origin (see
commit 6793d90b8). In case there is a newer commit in the main ref
origin than the installed origin, this leads to an update operation
being erroneously created, only to then error out with an HTTP 404
error, because the commit from the main ref origin is being pulled from
the installed ref origin. For specific steps to reproduce see
https://github.com/flatpak/flatpak/issues/3128#issuecomment-948948040

So, ensure that when a FLATPAK_TRANSACTION_OPERATION_INSTALL_OR_UPDATE
operation is created for something that's installed, whether it's a
related ref or something else, the remote used is always the origin. And
ensure that the remote is set correctly before the stage where the op is
resolved to a commit, to avoid the situation described above. This is
essentially a re-implementation of the fix in commit 6793d90b8.

Also, add a unit test for this behavior.

This commit also makes a few changes to documentation to make it clear
that this related-ref-different-origin situation is possible.

Fixes #3128
2021-11-15 11:18:58 +01:00
Patrick Griffis
cda4967a9e Re-enable HTTP compression
The original commit (9865ed8989) disabling
it claimed it fixed OCI downloads. This no longer seems to be a problem.

This has also exposed new bugs as some servers will send
gzip compressed data when the client does not send Accept-Encoding.
If we leave this enabled that issue goes away.
2021-11-15 11:12:01 +01:00
Simon McVittie
19a93a8427 run: Always create .local/state directory
This is placed at the same location that would be used by
the --persist=.local/state option.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-11-15 11:07:57 +01:00
Simon McVittie
2e28fa39e8 run: Mention why we're using .local/state
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-11-15 11:07:57 +01:00
Lionir
0fda062c96 Add XDG_STATE_HOME and HOST_XDG_STATE_HOME env variables
This gives new support for the new XDG_STATE_HOME addition to XDG_BASE_DIRS
which allows applications to use this without breaking because they would
assume $HOME/.local/state which may be unavailable to the flatpak

This adds it as .local/state as to make --persist=.local/state the same behaviour
as in new flatpak. This in turn means that the transition should be seamless between
old and new flatpak.

This also has the benefit of working if the application doesn't follow XDG spec thanks
to --persist=.local/state.

This fixes https://github.com/flatpak/flatpak/issues/4477

[smcv: Don't call nonexistent g_get_user_state_dir(); fix a reference
to XDG_STATE_DIR]
2021-11-15 11:07:57 +01:00
Phaedrus Leeds
20fd994c5c transaction: Fix signal Since annotations 2021-11-15 09:55:27 +01:00
Phaedrus Leeds
f3214c59d2 dir: Fix an issue with fetch_remote_ref_sync()
This commit is a follow-up to "Fix implementation of xa.noenumerate
remote option" since that turned out to break
flatpak_installation_fetch_remote_ref_sync() in some cases. I didn't see
it at the time, but flatpak_decomposed_get_collection_id() explains that
the collection ID shouldn't be set on FlatpakDecomposed objects, even
when the remote has a collection ID set, unless they are being used to
enumerate refs from a file:// URI rather than a configured remote. So
this commit changes list_remote_refs() and list_all_remote_refs() to
keep the xa.noenumerate implementation working and to get
fetch_remote_ref_sync() working again (since the latter uses
flatpak_decomposed_new_from_parts() and thus doesn't set a collection ID
on the FlatpakDecomposed object used for comparison).
2021-11-15 09:48:03 +01:00
Phaedrus Leeds
fd4e9e84cd dir: Fix typos in a warning 2021-11-12 17:42:51 -08:00
Will Thompson
eabbff6fef run: Document shortcomings of PulseAudio server string parsing
These are just based on a cursory reading of the spec.
2021-11-11 16:38:11 +00:00
Will Thompson
bcc114383b run: Add link to PulseAudio server string documentation 2021-11-11 16:38:11 +00:00
Will Thompson
7534a970a5 run: Support PulseAudio socket path without unix: prefix
https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/ServerStrings/
says:

> If the string starts with / or unix: the remaining address string is taken as
> UNIX socket name.

but previously the string was only taken to be a UNIX socket name if it began
with "unix:".

This is an issue in practice with WSLg <https://github.com/microsoft/wslg>
which sets $PULSE_SERVER to "/mnt/wslg/PulseServer", without a "unix:" prefix.
2021-11-11 16:38:11 +00:00
Phaedrus Leeds
998a300b29 dir: Fix a return of FALSE rather than NULL 2021-11-05 14:58:55 -07:00
Philip Withnall
cd2f796ba9 Merge pull request #4487 from flatpak/dont-mask-noenumerate-main-refs
dir: Don't mask the main ref of a noenumerate remote
2021-11-02 11:14:37 +00:00
Philip Withnall
8ff02c0e5b flatpak-utils-http: Ensure to wake up the main context on error
All the other code paths which set `data->done` or `data->error` ensure
to wake up the main context so its loop exit conditions can be checked
again — this code path was missing a wakeup though.

Spotted by code inspection; I haven’t hit this in the wild.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-10-26 23:24:52 +01:00
Phaedrus Leeds
93d3cb4704 Pedantic typo fix 2021-10-21 17:30:01 -07:00
Phaedrus Leeds
6de22f0e62 Include extensions in listing origin remote refs
In a recent commit I changed flatpak_dir_list_remote_refs() to make main
refs (xa.main-ref) visible for noenumerate remotes (xa.noenumerate),
meaning that an origin remote created for a flatpakref file can be used
to get information about the ref from the file even before it is
installed. This commit extends that work to include extensions of the
main ref, and updates the unit test to check for this. The reasoning is
that if GNOME Software wants to show the user information about, say,
VLC from a flatpakref file before installing it, Software would want to
also show the available plugins so the user can decide if they want to
install those as well. I haven't checked if Software actually does that;
I'm only focusing on making libflatpak do the right thing.
2021-10-21 11:32:05 -07:00
Phaedrus Leeds
7f3556d92c Fix implementation of xa.noenumerate remote option
Currently the xa.noenumerate option on a remote is documented as causing
the remote not to be used when presenting available apps/runtimes or
when searching for dependencies. The idea is that the remote is only
used for providing updates for things installed from it, and this
functionality is used when creating an origin remote for something
installed via a flatpakref file.

However, the implementation of this in flatpak_dir_list_remote_refs() is
buggy. It returns an empty set of refs even if something is both locally
installed and available from the remote. This is because it is using
hash table comparisons of FlatpkDecomposed objects (via
flatpak_decomposed_hash()) which take into account both the ref (or
refspec) and the collection ID, and the local refs' FlatpakDecomposed
objects are created from a refspec whereas the remote refs'
FlatpakDecomposed objects are created from a ref alone. We could fix
this by having them both use refspecs, but it is better to use a
collection-ref tuple for the following reasons:
(1) Changing flatpak_dir_list_all_remote_refs() to use a refspec to
create the FlatpakDecomposed objects would be a breaking change for the
other users of that function.
(2) Both the local and remote refs are from the same remote so we don't
need to use the remote name to disambiguate them, even if no collection
ID is configured.
(3) The whole point of collection IDs is to make refs uniquely
identifiable, so we're using them for the intended purpose.

In addition to fixing this bug, this commit adds a unit test in
testlibrary.c so it stays fixed.
2021-10-21 11:32:05 -07:00
Phaedrus Leeds
ef05925700 dir: Don't mask the main ref of a noenumerate remote
When we create origin remotes for apps installed via .flatpakref files,
we set xa.noenumerate=true and
xa.main-ref=app/com.example.App/arch/branch so that the remote is only
used for the app it was intended for. This is implemented in
flatpak_dir_list_remote_refs() by only listing refs in the remote which
are already installed. This works fine after the ref is installed but in
the short timespan between when the origin remote is created and the app
is installed from it, it means that the remote appears as empty.

The use case where I ran into this is in attempting to use
flatpak_installation_fetch_remote_ref_sync() in the gnome-software
flatpak plugin, in the handling of flatpakref files, which is intended
to just display information to the user and let them decide whether to
install the app. But I was not able to create a FlatpakRemoteRef due to
the behavior described above; see #4453 for more details.

So, change the behavior so that the main ref for an origin remote is
visible even before it is installed. This technically could be a
breaking change for some consumer of libflatpak but that seems very
unlikely, and the new behavior makes more sense.

Also add a unit test for this behavior.
2021-10-21 11:32:05 -07:00
Phaedrus Leeds
f6da902b38 common: Improve a few REF_NOT_FOUND error messages
This would have been helpful in my work on #4453
2021-10-21 18:16:13 +01:00
Phaedrus Leeds
4f6c13e751 Merge pull request #4327 from ericcurtin/warn_unused_result
Fix some warn_unused_result warnings
2021-10-12 14:31:43 -07:00
Eric Curtin
c6845ad70b Fix some warn_unused_result warnings
While building on gcc 9.3.0
2021-10-12 13:50:14 -07:00
Simon McVittie
53bde36585 run: Improve error handling/diagnostics for calls into libseccomp
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-10-11 09:42:00 +02:00
Simon McVittie
3fc8c67267 Fix handling of syscalls only allowed by --devel
This was incorrectly looking at errno instead of -r.

Fixes: 0b38b0f0 "run: Handle unknown syscalls as intended"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-10-11 09:39:38 +02:00
Simon McVittie
ae59fb7aca common: Backport g_get_language_names_with_category() more thoroughly
Even though we are going to check all the `LC_*` environment variables,
if one of them is not set, we still need to consider LANGUAGE, LC_ALL
and LANG; there is no guarantee that *every* `LC_*` environment variable
is set (and in particular, during our build-time tests, they will usually
not be).

Resolves: https://github.com/flatpak/flatpak/issues/4471
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-10-11 09:31:58 +02:00
Simon McVittie
d419fa6703 run: Handle unknown syscalls as intended
The error-handling here was

    if (r < 0 && r == -EFAULT)

but Alex says it was almost certainly intended to be

    if (r < 0 && r != -EFAULT)

so that syscalls not known to libseccomp are not a fatal error.

Instead of literally making that change, emit a debug message on -EFAULT
so we can see what is going on.

This temporarily weakens our defence against CVE-2021-41133
(GHSA-67h7-w3jq-vh4q) in order to avoid regressions: if the installed
version of libseccomp does not know about the recently-added syscalls,
but the kernel does, then we will not prevent non-native executables
from using those syscalls.

Resolves: https://github.com/flatpak/flatpak/issues/4458
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-10-08 18:39:25 +02:00
Simon McVittie
462fca2c66 run: Don't allow chroot()
If we don't allow pivot_root() then there seems no reason why we should
allow chroot().

Partially fixes GHSA-67h7-w3jq-vh4q.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-10-08 12:53:20 +02:00
Simon McVittie
1330662f33 run: Don't allow unmounting filesystems
If we don't allow mounting filesystems, we shouldn't allow unmounting
either.

Partially fixes GHSA-67h7-w3jq-vh4q.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-10-08 12:53:20 +02:00
Simon McVittie
4c34815784 run: Block setns()
If we don't allow unshare() or clone() with CLONE_NEWUSER, we also
shouldn't allow joining an existing (but different) namespace.

Partially fixes GHSA-67h7-w3jq-vh4q.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-10-08 12:53:20 +02:00
Simon McVittie
9766ee05b1 run: Disallow recently-added mount-manipulation syscalls
If we don't allow mount() then we shouldn't allow these either.

Partially fixes GHSA-67h7-w3jq-vh4q.

Thanks: an anonymous reporter
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-10-08 12:53:20 +02:00
Simon McVittie
a10f52a756 run: Block clone3() in sandbox
clone3() can be used to implement clone() with CLONE_NEWUSER, allowing
a sandboxed process to get CAP_SYS_ADMIN in a new namespace and
manipulate its root directory. We need to block this so that AF_UNIX-based
socket servers (X11, Wayland, etc.) can rely on
/proc/PID/root/.flatpak-info existing for all Flatpak-sandboxed apps.

Partially fixes GHSA-67h7-w3jq-vh4q.

Thanks: an anonymous reporter
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-10-08 12:53:20 +02:00
Simon McVittie
26b12484eb common: Add a list of recently-added Linux syscalls
Historically, syscalls could take arbitrarily-different values on
different architectures, but new syscalls are added with syscall numbers
that align on each architecture.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-10-08 12:53:20 +02:00
Simon McVittie
89ae9fe74c run: Add cross-references for some other seccomp syscall filters
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-10-08 12:53:20 +02:00
Simon McVittie
e26ac7586c run: Add an errno value to seccomp filters
At the moment, if we block a syscall we always make it fail with EPERM,
but this is risky: user-space libraries can start to use new replacements
for old syscalls at any time, and will often treat EPERM as a fatal error.
For new syscalls, we should make the syscall fail with ENOSYS, which is
indistinguishable from running on an older kernel and will cause fallback
to an older implementation, for example clone3() to clone().

In future we should probably move from EPERM to ENOSYS for some of the
syscalls we already block, but for now keep the status quo.

This is a prerequisite for fixing the vulnerability tracked as
GHSA-67h7-w3jq-vh4q.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-10-08 12:53:20 +02:00
Philip Withnall
8cb27763fc flatpak-dir: Fix parental controls checks for root
These checks were broken in commit d762a2f, as the commit failed to
consider the fact that `flatpak_dir_check_parental_controls()` is run
both in the `flatpak` CLI process run by the user, but also in the
`flatpak-system-helper` process which always runs as root, and which
handles any installations done on the system repository.

As a result, parental controls were not working for the system
repository.

Fix that by limiting the scope of the check to only pass if running
without the system helper. flatpak calls from root never go through the
system helper.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #4418
2021-09-28 13:38:48 +01:00
gasinvein
9962b6bc1a run: Get gai.conf from session helper 2021-09-23 09:58:27 +02:00
Richard Maw
a96e9af37f Handle /var/tmp mounts when it is a symlink
In Yocto systems /var/tmp is a symlink to /var/volatile/tmp
because in its implementation of read-only rootfs /var is read-only
so /var/volatile is mounted as a tmpfs
and a subset of the paths point into it.

This would result in flatpak emitting mount arguments of
`--symlink ../var/volatile/tmp /var/tmp --bind /var/volatile/tmp /var/volatile/tmp`
which fails because flatpak has already added `--dir /var/tmp`
and the call to symlink fails with EEXIST.

This is fixed by blacklisting /var/tmp from symlink exports
in the same way /tmp is, so the bind is emitted as
`--bind /var/tmp /var/tmp`, which results in /var/volatile/tmp
being mounted into /var/tmp.
2021-09-23 09:57:33 +02:00
Ryan Gonzalez
f15f926284 Retrieve user languages for all locale categories
g_get_language_names() only returns the language names for the
LC_MESSAGES category, so mixed locale scenarios would result in missing
languages. Now, the languages are listed for each individual category.

Note that this issue was only present with the user installation. For
the system installation, the locales were queried from localed, and all
categories were checked.

In order to work on GLib versions < 2.58, the code to get language
names for a category has been backported.

Fixes #3712.
2021-09-17 09:23:52 +02:00
Seppo Yli-Olli
a99b748931 Support dynamic export path into scripts
When flatpak-builder is running under flatpak, its
path will be /app/bin/flatpak. This path must not
be in export scripts or desktop file. This change
makes it possible for flatpak-builder flatpak to
tell flatpak what it should write to generated
files
2021-09-10 11:32:51 +02:00
Simon McVittie
6e5b02e2d4 run: Don't let XDG_RUNTIME_DIR from user override the value we set
We use `bwrap --setenv XDG_RUNTIME_DIR` to set it to `/run/user/UID`,
regardless of what it is on the host system, but the changes made
to resolve CVE-2021-21261 unintentionally broke this by overwriting it
with the user's XDG_RUNTIME_DIR.

In practice this worked for most people, who either have
XDG_RUNTIME_DIR set to the same value we use (which is the conventional
setup from systemd-logind and elogind), or entirely unset (if they do not
have systemd-logind or elogind). However, it broke Wayland and other
XDG_RUNTIME_DIR-based protocols for people who intentionally set up an
XDG_RUNTIME_DIR that is different.

Fixes: 6d1773d2 "run: Convert all environment variables into bwrap arguments"
Resolves: https://github.com/flatpak/flatpak/issues/4372
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-20 15:28:58 +02:00
Simon McVittie
7fbb165c81 tests: Exercise failure to export a broken autofs
To achieve this, add a flag to FlatpakExports to make it fake a broken
autofs.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 08:37:25 +02:00
Simon McVittie
a232276191 exports: Make all filesystem accesses relative to the mock root fd
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 08:37:25 +02:00
Simon McVittie
9f6ec548ab utils: Document that flatpak_canonicalize_filename() does not do I/O
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 08:37:25 +02:00
Simon McVittie
bca0e65267 exports: Close mock host fd when destroyed
Previously this was leaked.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 08:37:25 +02:00
Philip Withnall
879b632c58 flatpak-transaction: Fix finding runtime with non-default remote+arch
Fix an “The application foo requires the runtime bla which was not
found” error when using libflatpak (not the CLI) to install an
application whose runtime is provided by a different repo, and which is
for a non-default architecture.

This is a follow-up to commit f2ff664ff.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-06-16 17:59:45 +02:00
Philip Withnall
a7af60f498 flatpak-transaction: Squash error propagation and fix return value
It doesn’t look like this error path is taken very often. Spotted while
reading through the code.

This function is opportunistically looking for dependencies, so a
failure in one remote shouldn’t make the whole operation fail.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-06-16 17:59:45 +02:00
Dennis Schridde
1bdbb80ac5 Reword to make it clearer how (not) to invoke flatpak 2021-06-15 10:06:50 +01:00