Commit Graph

559 Commits

Author SHA1 Message Date
Alexander Larsson
37d809ff9f run: Always create a fontconfig cache dir in the app dir
Otherwise fontconfig falls back to a shared ~/.fontconfig dir
which means caches are not per-app, and is not necessarily accessible.

(cherry picked from commit fef8743f26)

Closes: #1115
Approved by: alexlarsson
2017-10-19 09:04:50 +00:00
Alexander Larsson
25c151fbd9 Expose host icons readonly in sandbox
Icons are really only a bunch of pngs, and the icon theme specification
has been stable since forever and never broke ABI. So, exposing the
host fonts should be pretty safe, comparable to the fonts that we
already expose.

This ends up being kind of important since a lot of things pick up the
icon theme from the host. In particular, it means that libXcursor can pick up
the correct cursor icons for the current cursor theme.

(cherry picked from commit 1ee74fc5ea)
2017-09-13 14:58:51 +02:00
Alexander Larsson
0723efdcc8 Manually copy summary for update and appdata too
Origin: backport, 0.9.6, commit:67ffd9a0b6f2f76de8aa08e6eb00505e48c48cbd
2017-06-28 12:17:43 +02:00
Alexander Larsson
8249593482 install: Manually save summary[.sig] in cache repo
With the latest ostree, pull --mirror does not mirror the
summary for partial pulls, so system-wide installs fail. We
fix it by manually updating the summary.

Origin: backport, 0.9.6, commit:e987d92ad03981895a2a60db4f82420a12cd6cb7
2017-06-28 12:17:43 +02:00
Alexander Larsson
f76f500236 common: Store the summary signature in the cache too
We will need this later

Origin: backport, 0.9.4, commit:b06e38073a17dc2e67a7774768100f6cc9769791
2017-06-28 12:17:43 +02:00
Alexander Larsson
2c8e2417de Ensure we don't install world-writable dirs or setuid files
This is solved in a much nicer way on master, using new ostree
APIs. However, here we take a brute-force approach of scanning
all staged files and ensuring we don't have any files or
directories with invalid modes before committing the transaction.

If any bad permissions were found we delete the entire staging
directory.
2017-06-19 19:47:53 +02:00
Colin Walters
02a299f5c0 dir: Ensure ~/.local/share/flatpak is 0700
This goes into a big old topic about Unix homedir permissions; it's not uncommon
for general purpose OS vendors to have homedirs be 0755. In that case,
applications need to ensure confidentiality for data requiring it (classically
e.g. `~/.ssh`) by making the dirs `0700`.

While most of the data in the flatpak per-user dir probably isn't confidential
(debatably) we have a different issue; if container content includes suid or
world-writable files/dirs, then having that data accessible to other users
is obviously problematic.

We're going to fix flatpak/ostree to not create files with those modes
to begin with, but this simple fix closes off the attack route for
the per-user directory.

A different fix will be necessary for the system-wide repo.

See: https://github.com/flatpak/flatpak/pull/837
(cherry picked from commit daf36ba2af)
2017-06-19 19:25:52 +02:00
Colin Walters
714a70338d dir: Ensure we return on pull error to avoid error-overwrites
Looking at the git history, this code originally retried on
some cases for pull, then stopped doing so, then a later commit
added code after it, which made it incorrect.

Just do an early return again and drop the `res` variable.

(cherry picked from commit 4714f55ebd)
2017-06-19 19:25:52 +02:00
Simon McVittie
d513b03752 flatpak-dir: Check for variant containing string correctly
g_variant_get_type_string() is like g_dbus_message_get_signature(),
not like G_VALUE_HOLDS_STRING(). Use g_variant_is_of_type() to get
the equivalent of G_VALUE_HOLDS_STRING(). This was correct on master,
but went wrong during backporting to 0.8.x.

Signed-off-by: Simon McVittie <smcv@debian.org>
2017-06-04 18:20:09 +02:00
Alexander Larsson
beaa1fc3c9 run: Allow --filesystem=xdg-*/subdir:ro
We previously required the directory to be writable to expose
it in the app-specific directory. However, the file was already
made visible in the regular location, and it was explicitly requested
by the app, so not allowing it to be there read-only makes no sense.

In particular, this allows KDE apps to use
--filesystem=xdg-config/kdeglobals:ro to allow apps to pick up global
configurations such as theme, etc, in a safe way.

(cherry picked from commit 1d9fe6fbf3)
2017-06-01 11:07:12 +02:00
Alexander Larsson
ac357d76b1 run: Allow regular files for --filesystem=xdg-config/path
KDE needs this to put ~/.config/kdeglobals into the sandbox

(cherry picked from commit 75d884046d)
2017-06-01 11:07:11 +02:00
Alexander Larsson
c376cb1af0 Minimal backport of rewrite-url and gpg-keys remote metadata support
This backports the minimal support for migrating a remote to
a new url/gpg-key from master (see commit 21778f1075
and 7a4c82529e).

The support is manual (you must run flatpak remote-modify --update-metadata) and
only supports the client-side consuming parts. You have to use the 0.9.x
series to update the server-side repository.
2017-05-31 10:40:50 +02:00
Jonas Ådahl
304c127348 run: Handle non-default WAYLAND_DISPLAY
WAYLAND_DISPLAY can be other than "wayland-0" for various reasons, such
as using a custom Wayland display server or the session display server
using a custom display name.

Note that for xdg-desktop-portal to support showing portal windows, the
xdg-desktop-portal service MUST use the same WAYLAND_DISPLAY.

(cherry picked from commit a1ff20ca0e)
2017-05-31 09:58:05 +02:00
Alexander Larsson
414d699621 run: Fix race condition in app identification
There is a race condition in how the portals detects the peer app-id.
If we manager to open /proc/$pid/root, and then openat(fd,
".flatpak-info"), but the process dies inbetween the two, then the
.flatpak-info read-only bind mount (and all other mounts in the
namespace except the root one) is unmounted, so we will find
and empty .flatpakinfo file.

We fix this race by storing the contents in a regular file, but
also as a readonly bind mount on top of it.

For typical dbus portals the pid is the dbus proxy though, and in
that case the app can't modify the file, so we make it just
a file there instead of file + bind-mount.

(cherry picked from commit e7ad74c398)
2017-05-31 09:57:23 +02:00
Alexander Larsson
6265200c83 install: Limit the exported file to a whitelist
Instead of exporting any files we add a whilelist
of directories that get exported:

 share/applications
 share/icons
 share/dbus-1/services

This avoids potentially installing some kind of file that the
host system reads and interprets in a risky way.

Applications and dbus services are safe because we rewrite them.
Icons are safe as long as the image loaders are, and if they are
not we have worse problems.

This is based on what we do in master (commit
e8369a69ef), but that also
allows mimetypes and gnome shell provider files. These were made safe
using by rewriting during exports, but that code is not backported.
2017-05-31 09:55:02 +02:00
Matthias Clasen
5e82a7b11a Add a marker to rewritten desktop files
Add X-Flatpak=$app to rewritten desktop files.
Desktop files have multiple consumers, and this
makes it easier for them to know what to do.

(cherry picked from commit 66e91f55e8
 and e75cff6bb5)
2017-05-31 09:51:15 +02:00
Alexander Larsson
d6af6b72c8 Expose host /etc/hosts and /etc/host.conf
These are local network configuration, very much similar to
resolv.conf, so should also be exposed.

Fixes https://github.com/alexlarsson/spotify-app/issues/42
2017-05-31 09:44:48 +02:00
Alexander Larsson
2bdc160d20 run: Handle the case where /tmp on the host is a symlink
If the app explicitly grants access to the host /tmp (for
instance telegram) then when this is being exposed as a symlink
in the sandbox we get an error because /tmp already exists
as a dir, which we create very early on.

It doesn't really make sense to keep /tmp as a symlink in
the sandbox anyway, so we just special case this and mount
the symlink target as /tmp.

(cherry picked from commit f28d318cc9)
2017-05-31 09:43:43 +02:00
Alexander Larsson
25d92d40c8 Unset TMPDIR in the sandbox
Its quite possible that a custom TMPDIR is not mapped
in the sandbox, and /tmp is per-app anyway, so it doesn't
really make sense to use the custom one.

Fixes https://github.com/alexlarsson/spotify-app/issues/41

(cherry picked from commit 6711b56794
 and 7f7387ce5e)
2017-05-31 09:42:44 +02:00
Alexander Larsson
426189ab89 Handle uris better when detecting .flatpak[repo,ref] suffix
We fully parse the argument as (possibly) a uri, which means
we can handle an argument like:
 https://git.gnome.org/browse/gnome-apps-nightly/plain/gnome-builder.flatpakref?h=stable

Which doesn't work with a simple has_suffix call.
This is important because the flatpak.org site now references
these kinds of uris.

Fixes https://github.com/flatpak/flatpak/issues/659

(cherry picked from commit 0dcc7332f7)
2017-04-03 13:46:31 +02:00
Alexander Larsson
b30a731ca4 update: Only allow downgrades if a commit is explicitly specified
If you run "flatpak update" then we will never update to
a commit that is older than the currently installed one. This
protects against a man-in-the-middle attack that would otherwise
let the attacker downgrade to a previously signed version that
may have some vulnerability.

(cherry picked from commit 3ff6d312de)
2017-04-03 13:44:28 +02:00
Alexander Larsson
f34398a4ec system-helper: Fix check for downgrade
We never want the system-helper to downgrade. If you want to run
not-the-latest version you need to be "real root". However, the
check for this was broken, as it compared the new commit with the
new commit, which was always ok. Instead check the timestamp
on the new commit with the current one.

(cherry picked from commit 266b9cb6f0)
2017-04-03 13:44:24 +02:00
Colin Walters
0082bd53e6 utils: Prepare for libostree 2017.4 defining autocleanups
See: https://github.com/ostreedev/ostree/pull/756
2017-04-03 13:44:00 +02:00
Alexander Larsson
ea04835008 Correctly find system unmaintained extensions
We should not terminate the extension search just because
an earlier directory succeeds. Even non-existant directories
succeed, and anyway we should continue searching even if it
wasn't empty, because multiple subdir extensions may match.

Fixes https://github.com/flatpak/flatpak/issues/654

(cherry picked from commit 82aad1ccb1)
2017-04-03 13:30:43 +02:00
Georges Basile Stavracas Neto
a0b3f74587 Split extra-data setup and fetch
By splitting the extra-data setup - where we set the number of
extra-data downloads and auxiliary information - and download -
where we actually fetch the extra-data - we can have more precise
progress reports.

(cherry picked from commit d73090cc96)
2017-03-10 10:20:21 +01:00
Alexander Larsson
efa282f9ea appstream: Don't add runtime to flatpak bundle tag for runtimes
(cherry picked from commit 7d1a8f69f6)
2017-03-10 10:20:18 +01:00
Alexander Larsson
69d32a6331 extensions: Support multiple versions
This means an extension point can include extensions of multiple
(specified) versions. This is useful for e.g. the GL extensions,
where we want a single extension for all the essentially unversioned
GL extensions (like the nvidia one) that is used by all the
runtimes.

(cherry picked from commit 640a02315b)
2017-03-06 14:37:53 +01:00
Alexander Larsson
c68d6a6428 flatpak_list_extensions: Break out code into helper
This is a minor restructure to make the code more readable
and extensible.

(cherry picked from commit 3122d1c014)
2017-03-06 14:37:53 +01:00
Alexander Larsson
8bd07ca2a0 Support runtime-less extra-data
This is going to be needed for the nvidia driver to solve
https://github.com/flatpak/flatpak/issues/595

(cherry picked from commit 62286cf779)
2017-02-28 19:54:37 +01:00
Alexander Larsson
c216d989a8 Fix error check when loading configuration
(cherry picked from commit 78b5c2fbf5)
2017-02-28 19:54:32 +01:00
Alexander Larsson
0869586e47 zero-mtime: Handle error when enumerating directory
(cherry picked from commit 9d9bd184c7)
2017-02-28 19:54:27 +01:00
Alexander Larsson
91f91b5994 run: Handle error when enumerating /etc
(cherry picked from commit d24c5f1423)
2017-02-28 19:54:23 +01:00
Alexander Larsson
4adb1c21ad utils: Fix flatpak_bundle_load typo
If we failed to look up the app metadata we would
clear out a different out argument instead.

(cherry picked from commit 4db1e74090)
2017-02-28 19:53:50 +01:00
Alexander Larsson
20b872d2ce Avoid possible null dereference
If the link fails to resolve the return value will be NULL, so we shouldn't use
it before checking for NULL.

(cherry picked from commit b2b6dd3af2)
2017-02-28 19:53:45 +01:00
Alexander Larsson
d0e927a538 utils: Fix list_unmtainained_refs
There was a stray goto out that caused it to only look at the first
element in the system dirs list.

(cherry picked from commit e1e27559d1)
2017-02-28 19:53:36 +01:00
Mario Sanchez Prada
a44b6191d7 Initialize g_autofree string to NULL, not to crash when early returning
Otherwise, anytime we fail in ostree_repo_write_metadata() will cause
an invalid free to happen, and flatpak to crash.

(cherry picked from commit d0b5b51076)
2017-02-27 11:44:36 +01:00
Alexander Larsson
37a19ce172 Don't remove origin remotes if some other ref uses it
This fixes https://github.com/flatpak/flatpak/issues/586

(cherry picked from commit cc03a2b94b)
2017-02-27 11:43:53 +01:00
Ray Strode
24632dab0b run: propagate wildcard xauth entries to app bundle
At the moment, flatpak applications are only given FamilyLocal family
xauth cookies from the Xauthority file.  This is so, the sandboxed
application doesn't inadvertently get access to displays on other
computers.

But FamilyLocal isn't the only xauth family that's local.  FamilyWild
entries can be local as well.

Furthermore, FamilyWild entries are preferable to FamilyLocal entries
when found, because they don't break if the system hostname is changed.

This commit makes FamilyWild xauth entries get propagated in the same
way as their FamilyLocal counterparts.

(cherry picked from commit a82708cb10)
2017-02-27 11:43:16 +01:00
Alexander Larsson
fad0ab1ca1 Fix no-systemd-user warning (it doesn't affect sandboxing anymore)
(cherry picked from commit d27799518d)
2017-02-27 11:41:10 +01:00
Mario Sanchez Prada
f8c74167fd Allow cancelling the downloading process for extra data
So far, the installation of external apps can only be cancelled
before flatpak starts downloading the extra data, as there's no
cancellable being passed to g_input_stream_read_async().

This fixes that problem, making it possible to cancel installs
from GNOME Software regardless of the installation stage.

(cherry picked from commit 86bf88d89f)
2017-02-14 11:14:41 +01:00
Mario Sanchez Prada
01c5727cfa Report progress for extra data downloads, as we do for OSTree pulls
Otherwise, clients such as GNOME Software won't be able to report
any progress once the flatpak application has been downloaded and
we enter the stage to download the extra data.

(cherry picked from commit 2e1740297c)
2017-02-14 11:14:38 +01:00
Mario Sanchez Prada
da3f059485 Use the thread's default context to download extra data, not a new one
Otherwise, all the progress reporting for the extra data being downloaded
won't work, as the main context used by OstreeAsyncProgress will not be
the same than the one from the nested main loop used to download this.

(cherry picked from commit ca952b0f21)
2017-02-14 11:14:34 +01:00
Alexander Larsson
0e8d2884d6 Don't user user namespaces when bubblewrap is setuid
It turns out that it is impossible for to get ptrace capabilities
for child user namespaces in the current kernel if the user
namespace is created as root, which is what happens when bwrap
is setuid root (see https://github.com/flatpak/flatpak/issues/557
for details).

This is very problematic, as ptrace rights controls access to
/proc/$pid/root which is what we base the detection of peer
app id and rights on for portals.

For now, we disable user namespaces (except for the case of
unprivileged user namespaces, where it is necessary and works).

(cherry picked from commit 521e7e6a37)
2017-02-13 15:12:44 +01:00
Alexander Larsson
860ef3a798 dri: Fix nvidia driver with shared network
If we have network access, then nvidia talks to the xserver
and for some reason it then also needs /dev/nvidia-modeset.
So, lets add that to the dri device list.

(cherry picked from commit 763a686d87)
2017-02-08 16:44:31 +01:00
Alexander Larsson
3c8288f0e9 extensions: Support enable/install-if=active-gl-driver
Only use/download this extension if it matches an active gl driver.

(cherry picked from commit 2e453048e0)
2017-02-06 15:10:19 +01:00
Alexander Larsson
2ae9d9aaba Initial flatpak_get_gl_drivers() implementation
This is supposed to list all the currently loaded "non-standard" gl drivers.
If FLATPAK_GL_DRIVERS is set, then that is used, otherwise it looks
for an nvidia driver and if so, uses that, and always adding "default"
at the end which is meant to resolve to a stable mesa fallback build, as
well as "host" which can be used if you have a host-side driver
as an unmaintained extension.

(cherry picked from commit d4d15c7211)
2017-02-06 15:10:15 +01:00
Alexander Larsson
caa41bbb7f extensions: Handle priorities with merge-dirs
(cherry picked from commit 160f3a9820)
2017-02-06 15:10:12 +01:00
Alexander Larsson
bd9ff4de31 extensions: Support merge-dirs=list..
This causes the listed directories to become symlink farms
into all the subdirectory extensions.

(cherry picked from commit c88f1aa835)
2017-02-06 15:10:07 +01:00
Alexander Larsson
444f36c4cc extensions: Support subdirectory-suffix=foo
If directory is "foo" and the extension id ends with ".ext" and
subdirectory-suffix is "sub" then the extension point will
be "/usr/foo/ext/sub" rather than just "/usr/foo/ext".

This is very useful when the extension point naming scheme is
"reversed". For instance, this happens for the /usr/share/themes directory.
An extension point for a gtk3 theme would be in /usr/share/themes/$NAME/gtk-3.0,
which could be achived by using subdirectory-suffix=gtk-3.0.

(cherry picked from commit 5e1d456b8b)
2017-02-06 15:09:31 +01:00
Alexander Larsson
5c9b12a630 extensions: Add add_ld_path property
If your extension points set this, then each extension will have
the corresponding subdirectory added to LD_LIBRARY_PATH.

We also support a priority property in the ExtensionOf group
in the extensions themselves to set the search order.

(cherry picked from commit a3da0b3da8)
2017-02-06 15:01:41 +01:00