Skip to content

Commit

Permalink
linux: copy map_file before tokenizing in uidgidmap_helper
Browse files Browse the repository at this point in the history
libcrun_set_usernamespace passes uid_map/gid_map to uidgidmap_helper
which tokenizes it to pass as process args. But if the helper isn't available,
the fallback (when host_uid != 0) reuses this tokenized string and tries
writing it to /proc/pid/gid_map which fails with EINVAL

Signed-off-by: Andrew Consroe <[email protected]>
  • Loading branch information
aconz2 committed Oct 24, 2024
1 parent 2381713 commit 75aa509
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/libcrun/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -2873,17 +2873,17 @@ libcrun_reopen_dev_null (libcrun_error_t *err)
}

static int
uidgidmap_helper (char *helper, pid_t pid, char *map_file, libcrun_error_t *err)
uidgidmap_helper (char *helper, pid_t pid, const char *map_file, libcrun_error_t *err)
{
#define MAX_ARGS 20
char pid_fmt[16];
char *args[MAX_ARGS + 1];
char *next;
cleanup_free char *next = NULL;
size_t nargs = 0;
args[nargs++] = helper;
sprintf (pid_fmt, "%d", pid);
args[nargs++] = pid_fmt;
next = map_file;
next = xstrdup (map_file);
while (nargs < MAX_ARGS)
{
char *p = strsep (&next, " \n");
Expand All @@ -2897,13 +2897,13 @@ uidgidmap_helper (char *helper, pid_t pid, char *map_file, libcrun_error_t *err)
}

static int
newgidmap (pid_t pid, char *map_file, libcrun_error_t *err)
newgidmap (pid_t pid, const char *map_file, libcrun_error_t *err)
{
return uidgidmap_helper ("newgidmap", pid, map_file, err);
}

static int
newuidmap (pid_t pid, char *map_file, libcrun_error_t *err)
newuidmap (pid_t pid, const char *map_file, libcrun_error_t *err)
{
return uidgidmap_helper ("newuidmap", pid, map_file, err);
}
Expand Down

0 comments on commit 75aa509

Please sign in to comment.