Skip to content

Commit a58f134

Browse files
giuseppeclaude
andcommitted
linux: move pivot_root before container mounts
Use the new mount API (fsopen/fsconfig/fsmount) to create detached mounts for each non-bind filesystem type before pivot_root. After the pivot, place them via move_mount so the kernel mnt_already_visible check is satisfied. set_mounts then mounts fresh instances on top with the correct OCI flags. This fixes mounting proc/sysfs/cgroup in containers that use a user namespace, where the kernel denies these mounts unless a mount of the same type is already visible. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
1 parent d12f8b7 commit a58f134

5 files changed

Lines changed: 482 additions & 149 deletions

File tree

src/libcrun/container.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,11 +1339,6 @@ container_init_setup (void *args, pid_t own_pid, char *notify_socket,
13391339
if (UNLIKELY (ret < 0))
13401340
return ret;
13411341

1342-
/* sync 2 and 3 are sent as part of libcrun_set_mounts. */
1343-
ret = libcrun_set_mounts (entrypoint_args, container, rootfs, send_sync_cb, &sync_socket, err);
1344-
if (UNLIKELY (ret < 0))
1345-
return ret;
1346-
13471342
if (def->hooks && def->hooks->create_container_len)
13481343
{
13491344
libcrun_error_t tmp_err = NULL;
@@ -1357,6 +1352,15 @@ container_init_setup (void *args, pid_t own_pid, char *notify_socket,
13571352
return ret;
13581353
}
13591354

1355+
ret = libcrun_do_pivot_root (container, entrypoint_args->context->no_pivot, &rootfs, err);
1356+
if (UNLIKELY (ret < 0))
1357+
return ret;
1358+
1359+
/* sync 2 and 3 are sent as part of libcrun_set_mounts. */
1360+
ret = libcrun_set_mounts (entrypoint_args, container, rootfs, send_sync_cb, &sync_socket, err);
1361+
if (UNLIKELY (ret < 0))
1362+
return ret;
1363+
13601364
ret = libcrun_finalize_mounts (entrypoint_args, container, rootfs, err);
13611365
if (UNLIKELY (ret < 0))
13621366
return ret;
@@ -1376,13 +1380,6 @@ container_init_setup (void *args, pid_t own_pid, char *notify_socket,
13761380
if (UNLIKELY (ret < 0))
13771381
crun_error_write_warning_and_release (entrypoint_args->context->output_handler_arg, &err);
13781382

1379-
if (rootfs)
1380-
{
1381-
ret = libcrun_do_pivot_root (container, entrypoint_args->context->no_pivot, rootfs, err);
1382-
if (UNLIKELY (ret < 0))
1383-
return ret;
1384-
}
1385-
13861383
ret = libcrun_reopen_dev_null (err);
13871384
if (UNLIKELY (ret < 0))
13881385
return ret;

0 commit comments

Comments
 (0)