Skip to content

Commit d087ed2

Browse files
committed
Use new --disable-userns bubblewrap feature when possible
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. This doesn't work with a setuid bubblewrap, so if you're using that you now have to build flatpak with --with-priv-mode=setuid, even when using the system bubblewrap.
1 parent 8b39921 commit d087ed2

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

common/flatpak-run.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4640,6 +4640,29 @@ flatpak_run_app (FlatpakDecomposed *app_ref,
46404640
if (pidns_fd != -1)
46414641
flatpak_bwrap_add_args_data_fd (bwrap, "--pidns", pidns_fd, NULL);
46424642
}
4643+
else
4644+
{
4645+
/* Disable recursive userns for all flatpak processes, as we need this to guarantee
4646+
* that the sandbox can't restructure the filesystem. Allowing to change e.g. /.flatpak-info
4647+
* would allow sandbox escape via portals. This is also done via seccomp, but here we
4648+
* do it using userns unsharing in combination with max_user_namespaces.
4649+
*
4650+
* Unfortunately that is incompatible with --userns as used in the pid sharing code
4651+
* above. However, that will switch into a userns that has the right limit anyway.
4652+
*
4653+
* If bwrap is setuid, then --disable-userns will not work. We don't want to enable
4654+
* --disable-userns with a runtime check though, as then you might be able to disable it.
4655+
* So, for setuid based system you need to build flatpak with --with-priv-mode=setuid
4656+
* to disable this check.
4657+
*/
4658+
#ifndef BWRAP_IS_SETUID
4659+
if (0)
4660+
{
4661+
flatpak_bwrap_add_arg (bwrap, "--unshare-user");
4662+
flatpak_bwrap_add_arg (bwrap, "--disable-userns");
4663+
}
4664+
#endif
4665+
}
46434666

46444667
flatpak_bwrap_populate_runtime_dir (bwrap, shared_xdg_runtime_dir);
46454668

configure.ac

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ AC_ARG_WITH(priv-mode,
381381

382382
AM_CONDITIONAL(PRIV_MODE_SETUID, test "x$with_priv_mode" = "xsetuid")
383383

384+
if test "x$with_priv_mode" = "xsetuid"; then
385+
AC_DEFINE([BWRAP_IS_SETUID], [1], [Define if using setuid bwrap])
386+
fi
387+
384388
AC_ARG_ENABLE(sudo,
385389
AS_HELP_STRING([--enable-sudo],[Use sudo to set setuid flags on binaries during install (only needed if userns disabled)]),
386390
[SUDO_BIN="sudo"], [SUDO_BIN=""])

0 commit comments

Comments
 (0)