Skip to content

Use new --disable-userns bubblewrap feature when possible#5084

Merged
smcv merged 2 commits intoflatpak:mainfrom
alexlarsson:use-bubblewrap-disable-userns
Mar 24, 2023
Merged

Use new --disable-userns bubblewrap feature when possible#5084
smcv merged 2 commits intoflatpak:mainfrom
alexlarsson:use-bubblewrap-disable-userns

Conversation

@alexlarsson
Copy link
Member

@alexlarsson alexlarsson commented Sep 6, 2022

[This now depends on #5325. —smcv]


  • build: Require bubblewrap 0.8.0

    From: smcv

    This lets us use its new features unconditionally.

  • Use new --disable-userns bubblewrap feature when possible

    From: alexlarsson

    This feature (added in Add an option to disable nested user namespaces by setting limit to 1 containers/bubblewrap#488)
    allows us to improve the guarantees of disallowing the sandbox to use
    recursive user namespaces (which is a security risk) compared to the
    existing limits that use seccomp.

    [smcv: Move this to flatpak_run_setup_base_argv() so it will apply
    equally in apply_extra_data() and flatpak build; make the compile-time
    check for a setuid bwrap into a runtime check]

    Co-authored-by: smcv

@smcv smcv force-pushed the use-bubblewrap-disable-userns branch from d087ed2 to b2d3cd6 Compare December 16, 2022 17:43
@smcv smcv requested a review from mwleeds December 16, 2022 17:48
@smcv smcv force-pushed the use-bubblewrap-disable-userns branch 3 times, most recently from 531c843 to e5c7e25 Compare December 16, 2022 18:47
@smcv
Copy link
Collaborator

smcv commented Dec 16, 2022

Note to self for testing uninstalled:

$ meson setup _build -Dsystem_dbus_proxy=/usr/bin/xdg-dbus-proxy -Dsystem_bubblewrap= -Dlocalstatedir=/var -Dsysconfdir=/etc -Dprefix=/usr
$ export G_MESSAGES_DEBUG=all FLATPAK=$builddir/app/flatpak FLATPAK_BWRAP=$builddir/subprojects/bubblewrap/flatpak-bwrap
$ $builddir/portal/flatpak-portal -vvr
$ $builddir/app/flatpak run -vv ...

@smcv smcv added enhancement sandbox issue related to sandbox setup ready-for-review labels Dec 16, 2022
@smcv smcv marked this pull request as draft December 16, 2022 18:58
smcv added a commit to smcv/flatpak that referenced this pull request Dec 16, 2022
Our seccomp filtering necessarily adds overhead to each system call,
which is undesirable for syscall-heavy workloads like graphically
intensive games.

This is currently incomplete. It depends on flatpak#5084, but also needs
solutions to:

- preventing ioctl TIOCSTI (CVE-2017-5226): at the moment this is done
  in a relatively crude way via bwrap --new-session

- preventing access to the kernel keyring (see also flatpak#4281): at the moment
  this is unsolved

Resolves: flatpak#4187
Signed-off-by: Simon McVittie <[email protected]>
@alexlarsson
Copy link
Member Author

I merged the bwrap code now, so we should try to get this in.

@alexlarsson
Copy link
Member Author

Other than the rebase to a released bwrap this PR looks good to me now

@smcv
Copy link
Collaborator

smcv commented Jan 3, 2023

Other than the rebase to a released bwrap this PR looks good to me now

Great, please could you review containers/bubblewrap#545 if you have a chance? I think that one is a bwrap release blocker.

@alexlarsson
Copy link
Member Author

merged that too

smcv added a commit to smcv/flatpak that referenced this pull request Feb 27, 2023
* Improve error message if seccomp is disabled in kernel config
* Add --disable-userns option (needed for flatpak#5084)
* Add --assert-userns-disabled option (needed for flatpak#5084)

Signed-off-by: Simon McVittie <[email protected]>
@smcv smcv marked this pull request as ready for review February 27, 2023 14:13
@smcv smcv force-pushed the use-bubblewrap-disable-userns branch from e5c7e25 to 676f49b Compare February 27, 2023 14:13
@smcv smcv self-requested a review February 27, 2023 14:13
@smcv smcv force-pushed the use-bubblewrap-disable-userns branch from 676f49b to 8da10e9 Compare February 27, 2023 14:15
Copy link
Collaborator

@smcv smcv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with this if other maintainers are. (@alexlarsson? @mwleeds?)

@smcv smcv changed the title WIP: Use new --disable-userns bubblewrap feature when possible Use new --disable-userns bubblewrap feature when possible Feb 27, 2023
@smcv smcv force-pushed the use-bubblewrap-disable-userns branch from 8da10e9 to dbfbad9 Compare February 27, 2023 14:18
smcv added a commit to smcv/flatpak that referenced this pull request Feb 27, 2023
Our seccomp filtering necessarily adds overhead to each system call,
which is undesirable for syscall-heavy workloads like graphically
intensive games.

This is currently incomplete. It depends on flatpak#5084, but also needs
solutions to:

- preventing ioctl TIOCSTI (CVE-2017-5226): at the moment this is done
  in a relatively crude way via bwrap --new-session

- preventing access to the kernel keyring (see also flatpak#4281): at the moment
  this is unsolved

Resolves: flatpak#4187
Signed-off-by: Simon McVittie <[email protected]>
smcv added a commit to smcv/flatpak that referenced this pull request Mar 20, 2023
* Improve error message if seccomp is disabled in kernel config
* Add --disable-userns option (needed for flatpak#5084)
* Add --assert-userns-disabled option (needed for flatpak#5084)

Signed-off-by: Simon McVittie <[email protected]>
smcv added a commit that referenced this pull request Mar 20, 2023
* Improve error message if seccomp is disabled in kernel config
* Add --disable-userns option (needed for #5084)
* Add --assert-userns-disabled option (needed for #5084)

Signed-off-by: Simon McVittie <[email protected]>
@smcv smcv force-pushed the use-bubblewrap-disable-userns branch from dbfbad9 to 94005b1 Compare March 20, 2023 12:11
smcv and others added 2 commits March 23, 2023 11:28
This lets us use its new features unconditionally.

Signed-off-by: Simon McVittie <[email protected]>
This feature (added in containers/bubblewrap#488)
allows us to improve the guarantees of disallowing the sandbox to use
recursive user namespaces (which is a security risk) compared to the
existing limits that use seccomp.

[smcv: Move this to flatpak_run_setup_base_argv() so it will apply
equally in apply_extra_data() and `flatpak build`; make the compile-time
check for a setuid bwrap into a runtime check]

Co-authored-by: Simon McVittie <[email protected]>
Signed-off-by: Simon McVittie <[email protected]>
@smcv smcv force-pushed the use-bubblewrap-disable-userns branch from 94005b1 to 81a2ef8 Compare March 23, 2023 11:28
@smcv
Copy link
Collaborator

smcv commented Mar 23, 2023

Last chance for anyone to object to this, otherwise I'll merge after CI finishes.

@smcv smcv merged commit 23ec4ed into flatpak:main Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement ready-for-review sandbox issue related to sandbox setup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants