Skip to content

Commit a3fcba9

Browse files
authored
Merge pull request #1568 from michalsieron/no-user-namespaces
Fix running on kernel without user namespaces
2 parents 7c194cb + 27b5a2f commit a3fcba9

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/libcrun/linux.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2942,7 +2942,15 @@ can_setgroups (libcrun_container_t *container, libcrun_error_t *err)
29422942

29432943
ret = read_all_file ("/proc/self/setgroups", &content, NULL, err);
29442944
if (ret < 0)
2945-
return ret;
2945+
{
2946+
/* If the file does not exist, then the kernel does not support /proc/self/setgroups and setgroups can always be used. */
2947+
if (crun_error_get_errno (err) == ENOENT)
2948+
{
2949+
crun_error_release (err);
2950+
return 1;
2951+
}
2952+
return ret;
2953+
}
29462954

29472955
return strncmp (content, "deny", 4) == 0 ? 0 : 1;
29482956
}

src/libcrun/utils.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,16 @@ check_running_in_user_namespace (libcrun_error_t *err)
714714

715715
ret = read_all_file ("/proc/self/uid_map", &buffer, &len, err);
716716
if (UNLIKELY (ret < 0))
717-
return ret;
717+
{
718+
/* If the file does not exist, then the kernel does not support user namespaces and we for sure aren't in one. */
719+
if (crun_error_get_errno (err) == ENOENT)
720+
{
721+
crun_error_release (err);
722+
run_in_userns = 0;
723+
return run_in_userns;
724+
}
725+
return ret;
726+
}
718727

719728
ret = strstr (buffer, "4294967295") ? 0 : 1;
720729
run_in_userns = ret;

0 commit comments

Comments
 (0)