Skip to content

Commit 81a2ef8

Browse files
alexlarssonsmcv
andcommitted
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. [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 <smcv@collabora.com> Signed-off-by: Simon McVittie <smcv@collabora.com>
1 parent 48328ab commit 81a2ef8

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

common/flatpak-run.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3498,6 +3498,38 @@ flatpak_run_setup_base_argv (FlatpakBwrap *bwrap,
34983498
gulong pers;
34993499
gid_t gid = getgid ();
35003500
g_autoptr(GFile) etc = NULL;
3501+
gboolean parent_expose_pids = (flags & FLATPAK_RUN_FLAG_PARENT_EXPOSE_PIDS) != 0;
3502+
gboolean parent_share_pids = (flags & FLATPAK_RUN_FLAG_PARENT_SHARE_PIDS) != 0;
3503+
gboolean bwrap_unprivileged = flatpak_bwrap_is_unprivileged ();
3504+
3505+
/* Disable recursive userns for all flatpak processes, as we need this
3506+
* to guarantee that the sandbox can't restructure the filesystem.
3507+
* Allowing to change e.g. /.flatpak-info would allow sandbox escape
3508+
* via portals.
3509+
*
3510+
* This is also done via seccomp, but here we do it using userns
3511+
* unsharing in combination with max_user_namespaces.
3512+
*
3513+
* If bwrap is setuid, then --disable-userns will not work, which
3514+
* makes the seccomp filter security-critical.
3515+
*/
3516+
if (bwrap_unprivileged)
3517+
{
3518+
if (parent_expose_pids || parent_share_pids)
3519+
{
3520+
/* If we're joining an existing sandbox's user and process
3521+
* namespaces, then it should already have creation of
3522+
* nested user namespaces disabled. */
3523+
flatpak_bwrap_add_arg (bwrap, "--assert-userns-disabled");
3524+
}
3525+
else
3526+
{
3527+
/* This is a new sandbox, so we need to disable creation of
3528+
* nested user namespaces. */
3529+
flatpak_bwrap_add_arg (bwrap, "--unshare-user");
3530+
flatpak_bwrap_add_arg (bwrap, "--disable-userns");
3531+
}
3532+
}
35013533

35023534
run_dir = g_strdup_printf ("/run/user/%d", getuid ());
35033535

0 commit comments

Comments
 (0)