Commit Graph

2217 Commits

Author SHA1 Message Date
Phaedrus Leeds
ffff812957 transaction: Fix signal Since annotations
(cherry picked from commit 20fd994c5c)
2022-01-04 11:43:51 +00:00
Phaedrus Leeds
ea322f3df0 dir: Fix typos in a warning
(cherry picked from commit fd4e9e84cd)
2022-01-04 11:43:51 +00:00
Phaedrus Leeds
76d5928707 Pedantic typo fix
(cherry picked from commit 93d3cb4704)
2022-01-04 11:43:51 +00:00
Simon McVittie
72c38fe0bd 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>
(cherry picked from commit ae59fb7aca)
2021-10-11 09:52:48 +02:00
Simon McVittie
bd2c58fc27 run: Improve error handling/diagnostics for calls into libseccomp
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 53bde36585)
2021-10-11 09:52:48 +02:00
Simon McVittie
97e128c2c1 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>
(cherry picked from commit 3fc8c67267)
2021-10-11 09:52:48 +02:00
Simon McVittie
270701f900 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>
(cherry picked from commit d419fa6703)
2021-10-08 18:44:18 +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
Dennis Schridde
11d66b4587 Fix grammar 2021-06-15 10:06:50 +01:00
Dennis Schridde
1fa898202a Improve error message for sudo flatpak run
Closes: https://github.com/flatpak/flatpak/issues/3963
2021-06-15 10:06:50 +01:00
Philip Withnall
c8cbf26316 flatpak-installation: Fix some typos in documentation comments
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-06-14 15:30:59 +01:00
Philip Withnall
ce6fdcf077 transaction: Don’t abort on uninstall if deploy metadata is missing
If the deploy metadata is missing for the locale runtime of an app which
is being uninstalled, flatpak will currently abort on an assertion
failure.

Prevent that abort, at the expense of not uninstalling the locale
runtime. A better fix could be found for this in future.

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

Fixes: #3943
2021-06-01 09:51:59 +02:00
Simon McVittie
10a4cd7e08 context: Factor out functions to parse an environment block
This makes them easier to test, and easier to use in related tests.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-05-25 11:11:03 +02:00
Simon McVittie
d13f489e63 Don't disable -Wformat-nonliteral unnecessarily
These functions were already annotated with G_GNUC_PRINTF, so gcc
can assume that the format string and arguments match up.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-05-25 10:33:18 +02:00
Simon McVittie
17b6c31c7c Add missing G_GNUC_PRINTF attributes
This allows callers to be checked for mismatches between format string
and arguments, and also means gcc can assume that the format string and
the arguments match up correctly when forwarding them to functions
like g_strdup_vprintf, removing the need to suppress -Wformat-nonliteral
warnings.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-05-25 10:33:18 +02:00
Alexander Larsson
0a9d5ac7f2 Include more architectures when listing installed refs.
It turns out that we can't currently uninstall a ref from a
non-standard arch without specifying the arch even if there is no similar
ref installed for the main arch. (#4264)

The fundamental reason for this that `flatpak_dir_find_installed_ref(s)`
currently only returns refs with standard arches unless you explicitly
specify an arch.

This changes flatpak_dir_find_installed_refs() to always return
all the refs for all installed arches. This is generally what
we want anyway, except in the case of "flatpak run org.some.Platform" where
we don't want to prompt if there are multiple arches installed, so that
is manually changed.

This changes find_matching_ref() to look for refs in all arches, but
always prefer (without prompting) the default arch if that is installed.
This also matches what all current callers want.

Fixes #4264
2021-05-19 09:54:52 +02:00
Alexander Larsson
540bcda3bd Transaction: Ensure we download the subsummary for the arch of added refs
By default we only download the main arch subsummary, so if you added
a ref for some other arch it failed to find the ref. This works with the
CLI, because it explicilty loads the subsummary when its trying to expand
the parial ref to the full ref. However apps using libflatpak don't do that
so they failed.
2021-05-19 09:49:30 +02:00
Alexander Larsson
ce9a1c4f6c Add FLATPAK_QUERY_FLAGS_ALL_ARCHES for list_remote_refs()
This allows flatpak_installation_list_remote_refs_sync_full() to list
refs for all arches on remotes that use the new subsummary format.

Fixes #4252
2021-05-19 09:49:25 +02:00
Philip Withnall
a65e97c380 dir: Avoid a crash when looking up summary for a ref without an arch
If looking up the summary for a ref without an arch (for example,
`ostree-metadata`, which the Endless OS version of flatpak uses in some
backwards-compatibility code), avoid passing `NULL` to `strcmp()` and
hence crashing.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-05-11 15:12:15 +01:00
Phaedrus Leeds
404d7c6941 Fix several memory leaks 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
4562627b04 utils: Add missing check for empty string collection id 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
a0188dee79 dir: Fix a GString leak 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
756b9eae14 common: Fix several memory leaks 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
d191c2eb58 context: Fix leak of env var key/value pair 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
1120c7cb24 Fix memory errors w/ use of var_arrayofstring_to_strv() 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
879c9b9008 utils: Fix use-after-free and logic error
Without this change, validate_component() might free the "component"
variable, but then go on to keep using it. This change also makes the
code work as intended, to only have a flatpak-specific "bundle" in the
appstream xml (where here bundle does not mean "flatpak single-file
bundle").
2021-05-04 10:23:13 +02:00
Alexander Larsson
0cd4656ea1 Add (and use) custom, high-perfomance prune implementation
This is an optimized version of ostree_repo_prune() specialized for
archive mode repos. It is faster and uses less memory so that we can
prune larger repos (like flathub) in a realistic timeframe.

The primary reason it is faster is that it creates and uses a
`.commitmeta2` file for each commit, containing information about what
objects are reachable from that commit. This means incremental prunes
need only traverse over newly created commits.

Secondly, it uses the variant parser compiled accessors for the
various GVariants that are involved in the prune which is quite a bit
faster, especially if the repo is very large.

It also merges the scan-for-all-objects and prune-unreachable objects
phases, which means that we don't have to allocate a hashtable for
all the objects in the entire repo saving a lot of memory.

To save memory the hashtable of reachable objects, which can be quite
big on a big repo, points to a custom, very compact format for object
names.

Additionally it does the scanning for reachable objects twice, first
with a shared lock and then again (if anything changed) it with an
exclusive lock. This allows us to avoid using an exclusive lock during
the slowest part of the prune.

Unfortunately there are currently no public APIs for the ostree repo
locks. We really need to take an exclusive lock during the whole prune
or we parallel modifications (say a commit) might get their newly
written objects deleted. To work around this we have a minimal custom
implementation of an exclusive lock. Once the public API is available
we can start using that.

I created a repo with a lot of small commits to test this.  It has 9M,
and pruning with depth=10 deletes 2M of them.

The original performance looks like:

 Finding reachable objects: 287 seconds
 Pruning unreachable: 69 seconds

Just using the pregenerated reachable data:

 Finding reachable objects: 15 seconds
 Pruning unreachable: 69 seconds

The final optimized prune (using pregenerated data):

 Finding reachable objects: 12 seconds
 Pruning unreachable: 51 seconds

The above are with the page caches cleaned, on a second run the performance
increase is even more noticeable.

As a comparison to the above, finding the reachable objects in the
actual flathub repo took 22 hours, but with the pregenerated reachable data
only 39 minutes.
2021-04-26 10:30:14 +02:00
Simon McVittie
2a01318e15 ref-utils: Remove dead store
We always set match_len before using it, discarding the result of this
assignment. Detected by scan-build.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-19 09:09:04 +02:00
Simon McVittie
c26a48a9aa Fix various unused variables detected by scan-build
scan-build has a lot of false positives for this codebase because it
doesn't understand __attribute__((__cleanup__)) or GLib's GError
convention, but it seems to have been right about these.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-19 09:09:04 +02:00
Hubert Figuière
9e7c5fa545 flatpak_dir_find_local_related_for_metadata: Skip invalid branch
Fixes #4234
2021-04-19 09:07:10 +02:00