The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/3368
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
From 46bc6f2a55dd483b396bc60b73f4e602abcc9b9f Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Thu, 9 Apr 2020 12:44:25 +0200 Subject: [PATCH 1/3] conf: tweak get_minimal_idmap() Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- src/lxc/conf.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 8d480b049a..4fe64770c5 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -3488,7 +3488,7 @@ static int lxc_free_idmap(struct lxc_list *id_map) { struct lxc_list *it, *next; - lxc_list_for_each_safe (it, id_map, next) { + lxc_list_for_each_safe(it, id_map, next) { lxc_list_del(it); free(it->elem); free(it); @@ -3996,7 +3996,7 @@ static struct lxc_list *get_minimal_idmap(const struct lxc_conf *conf, lxc_list_add_elem(tmplist, container_root_uid); lxc_list_add_tail(idmap, tmplist); - if (host_uid_map && (host_uid_map != container_root_uid)) { + if (host_uid_map != container_root_uid) { /* idmap will now keep track of that memory. */ move_ptr(container_root_uid); @@ -4018,7 +4018,7 @@ static struct lxc_list *get_minimal_idmap(const struct lxc_conf *conf, lxc_list_add_elem(tmplist, container_root_gid); lxc_list_add_tail(idmap, tmplist); - if (host_gid_map && (host_gid_map != container_root_gid)) { + if (host_gid_map != container_root_gid) { /* idmap will now keep track of that memory. */ move_ptr(container_root_gid); @@ -4060,9 +4060,13 @@ int userns_exec_1(const struct lxc_conf *conf, int (*fn)(void *), void *data, call_cleaner(lxc_free_idmap) struct lxc_list *idmap = NULL; int ret = -1, status = -1; char c = '1'; + struct userns_fn_data d = { + .arg = data, + .fn = fn, + .fn_name = fn_name, + }; pid_t pid; int pipe_fds[2]; - struct userns_fn_data d; if (!conf) return -EINVAL; @@ -4075,9 +4079,6 @@ int userns_exec_1(const struct lxc_conf *conf, int (*fn)(void *), void *data, if (ret < 0) return -errno; - d.fn = fn; - d.fn_name = fn_name; - d.arg = data; d.p[0] = pipe_fds[0]; d.p[1] = pipe_fds[1]; From c6ba8981f5a0fc69b84e2b35786f1264b7d5b334 Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Thu, 9 Apr 2020 12:49:16 +0200 Subject: [PATCH 2/3] conf: use macros all around in lxc_map_ids() Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- src/lxc/conf.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 4fe64770c5..193df3327f 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -2679,19 +2679,10 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid) struct id_map *map; struct lxc_list *iterator; enum idtype type; - /* strlen("new@idmap") = 9 - * + - * strlen(" ") = 1 - * + - * INTTYPE_TO_STRLEN(uint32_t) - * + - * strlen(" ") = 1 - * - * We add some additional space to make sure that we really have - * LXC_IDMAPLEN bytes available for our the {g,u]id mapping. - */ int ret = 0, gidmap = 0, uidmap = 0; - char mapbuf[9 + 1 + INTTYPE_TO_STRLEN(uint32_t) + 1 + LXC_IDMAPLEN] = {0}; + char mapbuf[STRLITERALLEN("new@idmap") + STRLITERALLEN(" ") + + INTTYPE_TO_STRLEN(pid_t) + STRLITERALLEN(" ") + + LXC_IDMAPLEN] = {0}; bool had_entry = false, use_shadow = false; int hostuid, hostgid; From 1758c195057c32476e0e42c5fb5cbfad836a060e Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Thu, 9 Apr 2020 14:30:31 +0200 Subject: [PATCH 3/3] conf: move_ptr() in all cases in mapped_hostid_add() Closes #3366. Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- src/lxc/conf.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 193df3327f..45acc71a91 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -3918,18 +3918,19 @@ static struct id_map *mapped_hostid_add(const struct lxc_conf *conf, uid_t id, /* Reuse existing mapping. */ tmp = find_mapped_hostid_entry(conf, id, type); - if (tmp) - return memcpy(entry, tmp, sizeof(*entry)); - - /* Find new mapping. */ - hostid_mapped = find_unmapped_nsid(conf, type); - if (hostid_mapped < 0) - return log_debug(NULL, "Failed to find free mapping for id %d", id); - - entry->idtype = type; - entry->nsid = hostid_mapped; - entry->hostid = (unsigned long)id; - entry->range = 1; + if (tmp) { + memcpy(entry, tmp, sizeof(*entry)); + } else { + /* Find new mapping. */ + hostid_mapped = find_unmapped_nsid(conf, type); + if (hostid_mapped < 0) + return log_debug(NULL, "Failed to find free mapping for id %d", id); + + entry->idtype = type; + entry->nsid = hostid_mapped; + entry->hostid = (unsigned long)id; + entry->range = 1; + } return move_ptr(entry); }
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel