Skip to content

[Bug]: Some --filesystem options such as --filesystem=/run make Flatpak apps fail to start #5205

Closed

Description

@CommandMC

Checklist

Flatpak version

1.15.1

What Linux distribution are you using?

Arch Linux

Linux distribution version

N/A

What architecture are you using?

x86_64

How to reproduce

  1. Grant all applications full access to a core runtime folder, e.g. with flatpak override --user --filesystem /run/
  2. Try to launch any app (flatpak run foo.bar.baz)

Expected Behavior

Instead of allowing the override, Flatpak should check for permission issues (just like it does when --user is not specified)

Actual Behavior

Permissions are not checked, allowing this override to break all apps

Additional Information

I've noticed this in a situation where an end user wanted to give one specific application access to a subfolder in /run/ (flatpak override --filesystem /run/someFolder foo.bar.baz), but they've accidentally cut the command short, running flatpak override --user --filesystem /run/ instead.

From an experienced user's standpoint, it's somewhat clear what has happened: /run/ in its entirety is no longer sandboxed, but Flatpak tries to mirror some files from the actual system to /run/host/. Since we doesn't have write access to /run/, trying to create /run/host/ fails.
Solving this is as simple as, for example, resetting all overrides (flatpak override --user --reset), but it's not easy for a non-technical user to come to this conclusion

Activity

  1. CommandMC commented on Dec 7, 2022

    @CommandMC
    Author

    Simply not trying to mirror over files into /run/host/ if /run/ is not sandboxed is of course also an option, although I'd say that this wouldn't address the core issue

  2. changed the title [-][Bug]: Permissions are not checked when `override`ing `--filesystem` access on the `--user` installation[/-] [+][Bug]: Some --filesystem options such as --filesystem=/run make Flatpak apps fail to start[/+] on Dec 9, 2022
  3. smcv commented on Dec 9, 2022

    @smcv
    Collaborator

    Flatpak should check for permission issues (just like it does when --user is not specified)

    Does it really? I think you might be misunderstanding the difference between sudo flatpak override and flatpak override --user.

    When you use flatpak override, all you are doing is setting up a list of permissions that will be overridden when running an app later on. To use flatpak override without --user (which is equivalent to flatpak override --system), you have to be root, but only because you are doing something that will affect every user. Nothing is written to /run at this stage.

    Later, when you use flatpak run, Flatpak combines all the permissions from several sources:

    • defaults specified by the app maintainer (lowest precedence)
    • system-wide all-apps overrides (flatpak override --show --system)
    • system-wide per-app overrides (flatpak override --show --system org.gnome.Recipes)
    • per-user all-apps overrides (flatpak override --show --user)
    • per-user per-app overrides (flatpak override --show --user org.gnome.Recipes)
    • flatpak run command-line options (highest precedence)

    Specifying --filesystem=/run at any of those levels has exactly the same effect, unless it is overridden by something like --nofilesystem=/run at a higher-precedence level.

    The effect of --filesystem=/run is that instead of /run being a tmpfs like it is by default, you are asking Flatpak to share the host system's /run with the app's sandbox. That can't work[1], because Flatpak needs to set up directories inside /run for its own purposes (mainly /run/host and /run/flatpak), and ordinary users don't have the ability to create mount points for those directories.

    The only way a permission check affects this is that you are allowed to change configuration (and maybe break Flatpak) for yourself only, whereas root is allowed to change configuration (and maybe break Flatpak) for everyone.

    Probably Flatpak should just reject --filesystem=/run, ideally with a warning, similar to the way it already ignores some specific directories like --filesystem=/usr and --filesystem=/app.

    [1] Technically it can work if root runs flatpak run, but don't do that. flatpak run is not designed to be run as root.

  4. CommandMC commented on Dec 9, 2022

    @CommandMC
    Author

    I think you might be misunderstanding the difference between sudo flatpak override and flatpak override --user.

    I was indeed, thanks for clarifying! It was probably obvious from my post, but I don't use Flatpak myself. An end user of a program I work on encountered this issue, we managed to narrow it down to this, and I though I'd at least let you guys know

    Probably Flatpak should just reject --filesystem=/run, ideally with a warning, similar to the way it already ignores some specific directories like --filesystem=/usr and --filesystem=/app.

    I wonder if there's a "list" somewhere in the codebase with all (normally non-writable/non-existent?) sandboxed directories. Going through that list & checking if the specified path would share this sandbox directory (and if it does, don't allow the override) seems more robust than adding directories one by one

  5. smcv commented on Dec 12, 2022

    @smcv
    Collaborator

    I wonder if there's a "list" somewhere in the codebase with all (normally non-writable/non-existent?) sandboxed directories.

    Yes and no. The directories that are conceptually "owned" by the sandboxing framework are set up imperatively rather than declaratively (they really have to be, since each one has a different purpose and is set up in a different way), but there are also declarative and semi-declarative lists of paths that are different levels of special (dont_export_in and never_export_as_symlink() in flatpak-exports.c, and dont_mount_in_root in flatpak-context.c). /run is already in dont_mount_in_root, which excludes it from --filesystem=host.

    Putting /run in dont_export_in (with /usr and /app) would be too strong: the purpose of dont_export_in is to not allow anything below that point either, like --filesystem=/usr/share/blahblah (which can't work even if we wanted to allow it, because /usr is read-only, so we would be unable to create the mount point). However, we do want you to be able to use something like --filesystem=/run/blahblah/one-specific-socket. What we should not be allowing is --filesystem=/run specifically, or anything below --filesystem=/run/flatpak or --filesystem=/run/host, or possibly others.

    Maybe the ideal thing would be to expand the semantics of dont_export_in so that in addition to not allowing paths below those directories to be exported, we also don't allow paths above those directories to be exported? So that dont_export_in[] = { ..., "/run/host", ... } would imply not allowing /run/host/foo (already true) or /run (new), but would still allow /run/foo, where foo can be anything?

  6. smcv commented on Dec 12, 2022

    @smcv
    Collaborator

    #5213 avoids this by refusing to share all of /run with the app, with a warning message.

    Maybe the ideal thing would be to expand the semantics of dont_export_in so that in addition to not allowing paths below those directories to be exported, we also don't allow paths above those directories to be exported?

    That's (a large part of) what I did in #5213.

  7. 54 remaining items

  8. byteshiva commented on Jan 3, 2024

    @byteshiva

    I'm sharing my insights and solutions.
    Issue with File Overrides: Impact on Visual Studio Code Startup

    Issue:
    Encountering challenges with file overrides while attempting to provide access to Docker from the host for Visual Studio Code via Flatpak.

    1. flatpak override --user --filesystem=/run/docker.sock com.visualstudio.code
    2. sudo flatpak override --nofilesystem=/var/run/docker.sock com.visualstudio.code

    Description:
    Based on a Google search, I discovered that providing access to Docker from the host requires overriding the filesystem of com.visualstudio.code with /var/run/docker.sock. However, this approach has led to complications, impacting the normal startup of Visual Studio Code.

    Guide Link:
    Resolving Flatpak File Override Issues: A Step-by-Step Guide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions