Commit Graph

117 Commits (2618a19716856d2b107acc0b5b63838e1379ef45)

Author SHA1 Message Date
Colin Walters 2618a19716 Import ostree's compiler warnings, fix up callers
In ostree I maintain what I consider a "baseline" set of compiler
warnings that should *always* be fatal for a modern C project.

I noticed while working on a previous patch that a `-Werror=format`
warning wasn't fatal.

There are a few that are really, really important like
`-Werror=missing-prototypes`. I also take some like `-Werror=misleading-indentation`
which already caught some bugs.  See also https://lwn.net/Articles/678019/
2017-03-27 10:42:36 +02:00
Alexander Larsson 248a603e6a build: Allow dbus proxy access if explicitly given
If you do something like:
 flatpak build --talk-name=org.foo.Bar appdir
Then we now spawn a dbus proxy for the app.
However, we don't do this by default, even if the
runtime or the app metadata allows this, because
we want builds to normally be disconnected from
the build host.
2017-03-14 16:20:33 +01:00
Alexander Larsson 62286cf779 Support runtime-less extra-data
This is going to be needed for the nvidia driver to solve
https://github.com/flatpak/flatpak/issues/595
2017-02-28 18:10:06 +01:00
Alexander Larsson d24c5f1423 run: Handle error when enumerating /etc 2017-02-28 11:00:01 +01:00
Alexander Larsson b2b6dd3af2 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.
2017-02-28 10:44:54 +01:00
Ray Strode a82708cb10 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.
2017-02-22 14:47:14 +01:00
Alexander Larsson 082efe8951 Properly quote all commandlines we print
Fixes https://github.com/flatpak/flatpak/issues/236
2017-02-21 18:56:11 +01:00
Alexander Larsson d27799518d Fix no-systemd-user warning (it doesn't affect sandboxing anymore) 2017-02-21 15:41:43 +01:00
Alexander Larsson 521e7e6a37 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).
2017-02-13 15:03:00 +01:00
Alexander Larsson 763a686d87 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.
2017-02-08 16:43:14 +01:00
Alexander Larsson 160f3a9820 extensions: Handle priorities with merge-dirs 2017-02-03 08:17:22 +01:00
Alexander Larsson c88f1aa835 extensions: Support merge-dirs=list..
This causes the listed directories to become symlink farms
into all the subdirectory extensions.
2017-02-02 13:56:34 +01:00
Alexander Larsson 5e1d456b8b 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.
2017-02-01 19:59:12 +01:00
Alexander Larsson a3da0b3da8 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.
2017-02-01 19:46:25 +01:00
Alexander Larsson 7f8ad5b3a1 extensions: Make extension tmpfs requirement independent on order
If we sort, or subset the extensions we use, then we can't just
set need_tmpfs on the first one, instead do the checking
for the first one when we're applying the extensions.
2017-02-01 19:42:57 +01:00
Mario Sanchez Prada bfd43c1f98 Check if symlink target for /etc/localtime exists in the runtime
On unmonitored systems (if the session helper is not available), we
currently decide whether to create a symlink or a read-only bind mount
for /etc/localtime based on whether that's a symlink in the host or
not, but we don't check whether that symlink would be reachable in
the sandboxed environment, which might lead to bad situations.

This patch adds some extra checks relying on GFile's API to check
whether that symlink would be reachable before making the final
decision: if it's not, then do a bind mount despite of the file
being a symlink in the host.

https://github.com/flatpak/flatpak/issues/409
2017-01-30 14:35:04 +01:00
Alexander Larsson 84aed615da run: Fix e.g. --filesystem=xdg-config/foo without :create
Fixes https://github.com/flatpak/flatpak/issues/463
2017-01-27 10:43:59 +01:00
Alexander Larsson bc5ea57226 Run: Make sure all mounted sources are read-only
It turned out that some sources where bind-mounted read-write
which should have been read-only:

 * Extensions
 * Fonts
 * resolv.conf
 * localtime
 * machine-id

Many of these are not generally writable by the user, but
some are, which is pretty bad. For instance if the an
app is user-installed it will be able to write to its
locale data.

We fix this by using --ro-bind where needed.
2017-01-26 18:19:46 +01:00
Alexander Larsson ab446ebac5 Make /etc writable when building a runtime
We make /etc just a symlink to /usr/etc when we're building a runtime
and /etc is supposed to be writable. Otherwise the bind-mount we
normally have there don't allow use to replace existing files in /etc.
2017-01-25 15:28:42 +01:00
Alexander Larsson 0bea92bd73 dbus-proxy: Make it work if XDG_RUNTIME_DIR not set
The socket directory then ended up in $HOME which was read-only, so
we couldn't create the socket. We solve this by putting the sockets
in a subdirectory and always making this directory writable in the
proxy.
2017-01-23 18:27:00 +01:00
Juan Pablo Ugarte cc0c6354a2 --device=dri added support for Mali drivers 2017-01-20 15:03:56 +01:00
Alexander Larsson c329e60d73 Create the homedir last to avoid symlink issues
If the homedir is on a symlink (say /home -> /var/home) but the homedir
is in /home, then we shouldn't create a directory in /home because
then the symlink creation will fail. Instead we move the homedir
creation to the end, where we will create it in the symlink if needed.

This should fix https://github.com/flatpak/flatpak/issues/493
2017-01-19 15:36:06 +01:00
Alexander Larsson 58a5e146d3 Run: Handle dependencies when exposing symlinks
If you are exposing a symlink, say /link (-> /target) and
also a child of it, say /link/child, then we run into dependency
issues. For instance, the /link symlink is created, pointing to /target,
but then we try to to create /link/child before the /target
bind mount is setup, which will fail.

We work around this by adding a level, and the dependency of a symlink
(/target in the above case) will always be handled first. This isn't
a perfect solution, but is likely to be good enough in practice.
2017-01-19 15:36:06 +01:00
Alexander Larsson b2c7137e73 run: Create symlinks as relative paths to make them work during bwrap setup
During setup the new root is in /newroot, so absolute symlinks don't work.
We make them realtive so that we can resolve the symlinks during setup.
2017-01-19 15:36:06 +01:00
Alexander Larsson 592bea2b2e Don't break if exporting paths or symlinks to files in the runtime
For instance like in https://github.com/flatpak/flatpak/issues/494
if there is a /linuxrc -> /bin/busybox symlink, and /bin/busybox
is not in the runtime then we will fail creating it as a mountpoint
for the bind mount.

Fixes https://github.com/flatpak/flatpak/issues/494
2017-01-19 10:43:17 +01:00
Ikey Doherty 605c7ee87b Fix compiler warnings with uninitialised cleanup pointers
This change fixes GCC compiler warnings where a cleanup function was
specified on an uninitialised pointer, which in the view of GCC could
result in an errornous free of uninitialised memory, if the functions
that initialise them do not return NULL.

Signed-off-by: Ikey Doherty <ikey@solus-project.com>
2017-01-19 10:05:13 +01:00
Alexander Larsson 902fb71399 Use seccomp to filter out TIOCSTI ioctl
This would otherwise let the sandbox add input to the controlling tty.
2017-01-17 16:36:56 +01:00
Alexander Larsson 8152331bd0 Make sure /var/tmp is not on tmpfs
Apps may rely on /var/tmp not being in ram, for instance when
downloading large files. See for instance:

  http://0pointer.net/blog/projects/tmp.html

We make /var/tmp point to ~/.var/app/cache/tmp so that each app get
its own instane, and so that its cleared whe removing xdg-cache-dir
for the app.
2017-01-16 13:04:55 +01:00
Alexander Larsson 1e854ddc11 Fix all clang warnings 2016-12-13 10:20:28 +01:00
Alexander Larsson d3715463f2 Don't export symlinks from the host into /usr and /app
These make no sense, we don't want to modify the runtime, and
we can't create parent directories there anyway which can cause
issues like https://github.com/flatpak/flatpak/pull/433
2016-12-07 19:50:14 +01:00
Alexander Larsson efc8458165 run: Record in the flatpak-info file if dbus is proxied 2016-12-07 11:31:45 +01:00
Alexander Larsson c5856dd4e5 run: Fix xauth support
We need to lseek the fd *after* the fclose has
flushed the output.
2016-12-07 11:18:27 +01:00
Mario Sanchez Prada 8193b9f282 Extra checks mounting /etc/{resolv.conf|localtime} without session helper
When no session helper is available (e.g. running flatpak run from a
socket-activated service unit), we need to be extra careful before
making these two files appear inside the sandbox. Otherwise, if they
are not reachable on the host system (or just symlinks to non-existent
targets), flatpak won't be able to create the sandbox, which will fail
due to a "No such file or directory error".

https://github.com/flatpak/flatpak/issues/409
2016-11-25 08:46:48 +01:00
Alexander Larsson cc36dbcbbf run: Allow --filesystem=foo to expose sockets
We already kind of support this by exposing the parent directory,
so this isn't really less secure, and you should not be able to
access it unless your user is allowed to anyway.
2016-11-22 11:39:58 +01:00
Alexander Larsson 60b8a0eb47 run: Make /var/run symlink relative
This lets it work during early setup phase when the new root is at
/newroot. This allows us to create things in /var/run with
e.g. --filesystem=/var/run/foo.
2016-11-22 11:37:45 +01:00
Alexander Larsson 2acb3f81a5 Special handling of accesible XDG_XYZ_HOME subdirs
If the app is explictitly given access to a subdirectory of
one of the xdg config/cache/data directories, with read-write
(or create) access, then also bind-mount that directory
into the corresponding .var/app/$APPID directory.

This allows apps that want it to keep re-using global directories
for storing per-app information.

For instance, if your app uses "~/.config/foo" to store configuration
data, then you can use --filesystem=xdg-config/foo, which will look
for the directory, and if it exist, let the app access it, as well
as mirror the content in ~/.var/app/$appid/config/foo.

You can also use a ":create" to enforce the directory to be created
and thus always do the mapping.
2016-11-14 18:58:44 +01:00
Alexander Larsson a07a146827 Allow filesystem options for xdg-[config,cache,data] for the regular xdg dirs
This means you can give access to e.g. ~/.config/dconf as --xdg-config/dconf
which then also respects XDG_CONFIG_DIR settings.
2016-11-14 18:58:44 +01:00
Alexander Larsson 2dd9b8627a Add support for --filesystem=XXX:create
This means the same as XXX:rw, but if the location doesn't exist
a directory is created there.
2016-11-14 18:58:44 +01:00
Alexander Larsson b19ea63526 By default, hide the user flatpak directory
This way you can't e.g. modify your or other applications
and runtimes. If you really need to to this, your
app can explicitly request access to this directory.
2016-11-14 18:58:44 +01:00
Alexander Larsson e1d1a29a6f run: Hide ~/.var/app (except your dir)
Unless you specifically set --filesystem=~/.var/app you will not
have any access to files from other apps
2016-11-14 18:58:44 +01:00
Alexander Larsson e32612f1c9 Handle bind-mounts of locations that are symlinks
If we're specifying --filesystem=/some/path, where the final element
in the path is a symlink we need to special case this. We used
to rely on bubblewrap resolving the symlink for the source and
creating a bind mount directly to that, but this does not work
if the parent directory is already visible in the sandbox, because
we can't bind-mount on top of the pre-existing symlink.

Instead we detect this the symlink early, resolve the target and
bind mount in that, then we create a real symlink in its place.
However, that doesn't work if the paren't *doesn't* exist, so
we have to check for this and not create the symlink if it is
already going to be visible in the sandbox.
2016-11-11 22:21:07 +01:00
Alexander Larsson e175774d35 flatpak_run_add_x11_args: Only use tmp_fd inside != -1 check 2016-11-11 10:59:00 +01:00
Alexander Larsson 041d3eeb39 Add generic static permissions to metadata
This allows you do do something like
  flatpak build-finish --add-policy=subsystem.key=v1 --add-policy=subsystem.key=v2

Which maps to this metadata keys:

[Policy subsystem]
key=v1;v2;

You can also --remove-policy to remove values from a key.

The policy values are parsed from the app and runtime metadata, and
are overridable by per-app overrides and on the command line, however
the values are never used by flatpak. They do end up in the flatpak-info
file for the running application though, so external agents can look
at them.

These
2016-10-19 20:39:17 +02:00
Alexander Larsson f9c1cc40bb run: Support running a runtime directly
This means you can do:
  flatpak run org.freedesktop.Sdk
to get a shell in a sandbox with that runtime, but with an
empty /app.

You can also specify a particular runtime branch and command like so:
  flatpak run --command=ls org.gnome.Platform//3.22 /
2016-10-19 17:33:00 +02:00
Alexander Larsson c23316cb5d Add FlatpakKinds flag and use instead of booleans 2016-10-14 11:20:53 +02:00
Alexander Larsson 972442a7b0 Don't assign unused variables 2016-10-06 12:31:54 +02:00
Adrian Perez de Castro 6cbf3b6c01 Support mixed (multilib/multiarch) binaries in Flatpaks
This adds a new "multiarch" feature which allows bundling e.g. 32-bit
binaries to be run in a x86_64 environment. By default, the seccomp
filter is configured to allow only the native architecture. When the
"multiarch" feature is enabled, the filter will be configured to allow
running binaries of additional architectures supported. For x86_64, this
allows x86 32-bit binaries; and for Aarch64, allows 32-bit ARM binaries.

Application bundles can use the feature e.g. in order to ship 32-bit
binaries alongside with a mostly-64-bit application. This is particularly
interesting when for applications that might launch themselves prebuilt
programs for which 64-bit versions do not exist. For example, the Steam
application is available as a 64-bit executable, but some of the games
available are 32-bit only. A Flatpak bundle for the Steam application
with "multiarch" enabled is able launch the 32-bit games -- without the
feature enabled, the seccomp filter would prevent them from running.

Multiple-architecture support is enabled by adding the "multiarch" value
for the "features" key in the metadata file for a Flatpak:

  [Context]
  features=multiarch;

The corresponding "--allow=multiarch" command line option is supported
in "flatpak build-finish" as well.
2016-10-03 09:54:05 +02:00
Alexander Larsson c9c35133c3 Add support for --device=kvm
Solves: https://github.com/flatpak/flatpak/issues/332
2016-09-30 16:46:51 +02:00
Alexander Larsson 636130db49 Merge pull request #299 from matthiasclasen/keyring
flatpak should close up access to kernel keyring
2016-09-21 07:12:30 +02:00
Alexander Larsson acc561c6fc Add versioning info to the appinfo file. 2016-09-19 16:33:48 +02:00