Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/libcrun/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,9 @@ create_missing_devs (libcrun_container_t *container, bool binds, libcrun_error_t
dev_fds = get_private_data (container)->dev_fds;
get_private_data (container)->dev_fds = NULL;

if (! def || ! def->linux)
return 0;

devfd = openat (get_private_data (container)->rootfsfd, "dev", O_CLOEXEC | O_PATH | O_DIRECTORY);
if (UNLIKELY (devfd < 0))
return crun_make_error (err, errno, "open `/dev` directory in `%s`", rootfs);
Expand Down Expand Up @@ -1839,6 +1842,9 @@ do_masked_and_readonly_paths (libcrun_container_t *container, libcrun_error_t *e
int ret;
runtime_spec_schema_config_schema *def = container->container_def;

if (! def || ! def->linux)
return 0;

for (i = 0; i < def->linux->masked_paths_len; i++)
{
ret = do_masked_or_readonly_path (container, def->linux->masked_paths[i], false, false, err);
Expand Down Expand Up @@ -2689,7 +2695,7 @@ libcrun_set_mounts (struct container_entrypoint_s *entrypoint_args, libcrun_cont
if (rootfs == NULL || def->mounts == NULL)
return 0;

if (def->linux->rootfs_propagation)
if (def->linux && def->linux->rootfs_propagation)
rootfs_propagation = get_mount_flags (def->linux->rootfs_propagation, 0, NULL, NULL, NULL, NULL);

if ((rootfs_propagation & ALL_PROPAGATIONS_NO_REC) == 0)
Expand Down Expand Up @@ -3130,6 +3136,9 @@ libcrun_set_usernamespace (libcrun_container_t *container, pid_t pid, libcrun_er
if ((get_private_data (container)->unshare_flags & CLONE_NEWUSER) == 0)
return 0;

if (! def || ! def->linux)
return 0;

if (def->linux->uid_mappings_len)
{
ret = format_mount_mappings (&uid_map, def->linux->uid_mappings, def->linux->uid_mappings_len, &uid_map_len, err);
Expand Down Expand Up @@ -4366,16 +4375,22 @@ get_id_in_user_namespace (uid_t id, bool is_uid, runtime_spec_schema_config_sche
size_t len;
size_t i;

if (! def || ! def->linux)
goto exit;

mappings = is_uid ? def->linux->uid_mappings : def->linux->gid_mappings;
len = is_uid ? def->linux->uid_mappings_len : def->linux->gid_mappings_len;

if (! mappings)
goto exit;

for (i = 0; i < len; i++)
{
if (mappings[i]->container_id <= id
&& id < mappings[i]->container_id + mappings[i]->size)
return id - mappings[i]->container_id + mappings[i]->host_id;
}

exit:
return is_uid ? get_overflow_uid () : get_overflow_gid ();
}

Expand Down