Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils: fix creating default userns #1073

Merged
merged 1 commit into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/libcrun/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -2796,7 +2796,7 @@ libcrun_set_usernamespace (libcrun_container_t *container, pid_t pid, libcrun_er
uid_map = format_mount_mappings (def->linux->uid_mappings, def->linux->uid_mappings_len, &uid_map_len, true);
else
{
uid_map_len = format_default_id_mapping (&uid_map, container->container_uid, container->host_uid, 1);
uid_map_len = format_default_id_mapping (&uid_map, container->container_uid, container->host_uid, container->host_uid, 1);
if (uid_map == NULL)
uid_map = format_mount_mapping (0, container->host_uid, container->host_uid + 1, &uid_map_len, true);
}
Expand All @@ -2805,7 +2805,7 @@ libcrun_set_usernamespace (libcrun_container_t *container, pid_t pid, libcrun_er
gid_map = format_mount_mappings (def->linux->gid_mappings, def->linux->gid_mappings_len, &gid_map_len, true);
else
{
gid_map_len = format_default_id_mapping (&gid_map, container->container_gid, container->host_uid, 0);
gid_map_len = format_default_id_mapping (&gid_map, container->container_gid, container->host_uid, container->host_gid, 0);
if (gid_map == NULL)
gid_map = format_mount_mapping (0, container->host_gid, container->host_gid + 1, &gid_map_len, true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcrun/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1403,15 +1403,15 @@ getsubidrange (uid_t id, int is_uid, uint32_t *from, uint32_t *len)
#define MIN(x, y) ((x) < (y) ? (x) : (y))

size_t
format_default_id_mapping (char **ret, uid_t container_id, uid_t host_id, int is_uid)
format_default_id_mapping (char **ret, uid_t container_id, uid_t host_uid, uid_t host_id, int is_uid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be (..., uid_t host_uid, uid_t host_gid,...)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhatdan is this resolved I think this has same explanation as the above one.

{
uint32_t from, available;
cleanup_free char *buffer = NULL;
size_t written = 0;

*ret = NULL;

if (getsubidrange (host_id, is_uid, &from, &available) < 0)
if (getsubidrange (host_uid, is_uid, &from, &available) < 0)
return 0;

/* More than enough space for all the mappings. */
Expand Down
2 changes: 1 addition & 1 deletion src/libcrun/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ int copy_from_fd_to_fd (int src, int dst, int consume, libcrun_error_t *err);

int run_process (char **args, libcrun_error_t *err);

size_t format_default_id_mapping (char **ret, uid_t container_id, uid_t host_id, int is_uid);
size_t format_default_id_mapping (char **ret, uid_t container_id, uid_t host_uid, uid_t host_id, int is_uid);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be (..., uid_t host_uid, uid_t host_gid,...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

host_id is either UID or GID, depending on the value of is_uid. We need to differentiate since we use different files for the lookup (/etc/subuid or /etc/subgid)


int run_process_with_stdin_timeout_envp (char *path, char **args, const char *cwd, int timeout, char **envp,
char *stdin, size_t stdin_len, int out_fd, int err_fd, libcrun_error_t *err);
Expand Down