Unverified Commit b7b02642 by Stéphane Graber Committed by GitHub

Merge pull request #3368 from brauner/2020-04-09/fixes

fixes
parents 1c13783e 1758c195
...@@ -2679,19 +2679,10 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid) ...@@ -2679,19 +2679,10 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid)
struct id_map *map; struct id_map *map;
struct lxc_list *iterator; struct lxc_list *iterator;
enum idtype type; 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; 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; bool had_entry = false, use_shadow = false;
int hostuid, hostgid; int hostuid, hostgid;
...@@ -3488,7 +3479,7 @@ static int lxc_free_idmap(struct lxc_list *id_map) ...@@ -3488,7 +3479,7 @@ static int lxc_free_idmap(struct lxc_list *id_map)
{ {
struct lxc_list *it, *next; 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); lxc_list_del(it);
free(it->elem); free(it->elem);
free(it); free(it);
...@@ -3927,18 +3918,19 @@ static struct id_map *mapped_hostid_add(const struct lxc_conf *conf, uid_t id, ...@@ -3927,18 +3918,19 @@ static struct id_map *mapped_hostid_add(const struct lxc_conf *conf, uid_t id,
/* Reuse existing mapping. */ /* Reuse existing mapping. */
tmp = find_mapped_hostid_entry(conf, id, type); tmp = find_mapped_hostid_entry(conf, id, type);
if (tmp) if (tmp) {
return memcpy(entry, tmp, sizeof(*entry)); memcpy(entry, tmp, sizeof(*entry));
} else {
/* Find new mapping. */ /* Find new mapping. */
hostid_mapped = find_unmapped_nsid(conf, type); hostid_mapped = find_unmapped_nsid(conf, type);
if (hostid_mapped < 0) if (hostid_mapped < 0)
return log_debug(NULL, "Failed to find free mapping for id %d", id); return log_debug(NULL, "Failed to find free mapping for id %d", id);
entry->idtype = type; entry->idtype = type;
entry->nsid = hostid_mapped; entry->nsid = hostid_mapped;
entry->hostid = (unsigned long)id; entry->hostid = (unsigned long)id;
entry->range = 1; entry->range = 1;
}
return move_ptr(entry); return move_ptr(entry);
} }
...@@ -3996,7 +3988,7 @@ static struct lxc_list *get_minimal_idmap(const struct lxc_conf *conf, ...@@ -3996,7 +3988,7 @@ static struct lxc_list *get_minimal_idmap(const struct lxc_conf *conf,
lxc_list_add_elem(tmplist, container_root_uid); lxc_list_add_elem(tmplist, container_root_uid);
lxc_list_add_tail(idmap, tmplist); 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. */ /* idmap will now keep track of that memory. */
move_ptr(container_root_uid); move_ptr(container_root_uid);
...@@ -4018,7 +4010,7 @@ static struct lxc_list *get_minimal_idmap(const struct lxc_conf *conf, ...@@ -4018,7 +4010,7 @@ static struct lxc_list *get_minimal_idmap(const struct lxc_conf *conf,
lxc_list_add_elem(tmplist, container_root_gid); lxc_list_add_elem(tmplist, container_root_gid);
lxc_list_add_tail(idmap, tmplist); 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. */ /* idmap will now keep track of that memory. */
move_ptr(container_root_gid); move_ptr(container_root_gid);
...@@ -4060,9 +4052,13 @@ int userns_exec_1(const struct lxc_conf *conf, int (*fn)(void *), void *data, ...@@ -4060,9 +4052,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; call_cleaner(lxc_free_idmap) struct lxc_list *idmap = NULL;
int ret = -1, status = -1; int ret = -1, status = -1;
char c = '1'; char c = '1';
struct userns_fn_data d = {
.arg = data,
.fn = fn,
.fn_name = fn_name,
};
pid_t pid; pid_t pid;
int pipe_fds[2]; int pipe_fds[2];
struct userns_fn_data d;
if (!conf) if (!conf)
return -EINVAL; return -EINVAL;
...@@ -4075,9 +4071,6 @@ int userns_exec_1(const struct lxc_conf *conf, int (*fn)(void *), void *data, ...@@ -4075,9 +4071,6 @@ int userns_exec_1(const struct lxc_conf *conf, int (*fn)(void *), void *data,
if (ret < 0) if (ret < 0)
return -errno; return -errno;
d.fn = fn;
d.fn_name = fn_name;
d.arg = data;
d.p[0] = pipe_fds[0]; d.p[0] = pipe_fds[0];
d.p[1] = pipe_fds[1]; d.p[1] = pipe_fds[1];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment