Skip to content

Commit 880b7ee

Browse files
committed
criu: allow mount type to be NULL
In runtime-spec, mount's type property is optional and thus it can be NULL (for bind mounts). This is accounted for in other parts of code but not in c/r. This fix prevents SIGSEGV on crun checkpoint/restore. Found when running runc's integration test named "checkpoint and restore (bind mount, destination is symlink)" Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent a9c1f02 commit 880b7ee

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/libcrun/criu.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ restore_cgroup_v1_mount (runtime_spec_schema_config_schema *def, libcrun_error_t
283283
/* First check if there is actually a cgroup mount in the container. */
284284
for (i = 0; i < def->mounts_len; i++)
285285
{
286-
if (strcmp (def->mounts[i]->type, "cgroup") == 0)
286+
char *type = def->mounts[i]->type;
287+
if (type && strcmp (type, "cgroup") == 0)
287288
{
288289
has_cgroup_mount = true;
289290
break;
@@ -353,7 +354,8 @@ checkpoint_cgroup_v1_mount (runtime_spec_schema_config_schema *def, libcrun_erro
353354
/* First check if there is actually a cgroup mount in the container. */
354355
for (i = 0; i < def->mounts_len; i++)
355356
{
356-
if (strcmp (def->mounts[i]->type, "cgroup") == 0)
357+
char *type = def->mounts[i]->type;
358+
if (type && strcmp (type, "cgroup") == 0)
357359
{
358360
has_cgroup_mount = true;
359361
break;
@@ -714,7 +716,7 @@ prepare_restore_mounts (runtime_spec_schema_config_schema *def, char *root, libc
714716
size_t j;
715717

716718
/* cgroup restore should be handled by CRIU itself */
717-
if (strcmp (type, "cgroup") == 0 || strcmp (type, "cgroup2") == 0)
719+
if (type && (strcmp (type, "cgroup") == 0 || strcmp (type, "cgroup2") == 0))
718720
continue;
719721

720722
/* Check if the mountpoint is on a tmpfs. CRIU restores
@@ -723,8 +725,11 @@ prepare_restore_mounts (runtime_spec_schema_config_schema *def, char *root, libc
723725
{
724726
cleanup_free char *dest_loop = NULL;
725727

728+
if (def->mounts[j]->type == NULL || strcmp (def->mounts[j]->type, "tmpfs") != 0)
729+
continue;
730+
726731
xasprintf (&dest_loop, "%s/", def->mounts[j]->destination);
727-
if (strncmp (dest, dest_loop, strlen (dest_loop)) == 0 && strcmp (def->mounts[j]->type, "tmpfs") == 0)
732+
if (strncmp (dest, dest_loop, strlen (dest_loop)) == 0)
728733
{
729734
/* This is a mountpoint which is on a tmpfs.*/
730735
on_tmpfs = true;

0 commit comments

Comments
 (0)