From: Christian Brauner Date: Fri, 27 Mar 2020 10:05:11 +0000 (+0100) Subject: cgroups: move pointer dereference after check X-Git-Tag: lxc-5.0.0~490^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c2c435c523d5895ec6d668d55fa906a598d606c;p=thirdparty%2Flxc.git cgroups: move pointer dereference after check Signed-off-by: Christian Brauner --- diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index ad37291e9..387350b43 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -2124,8 +2124,8 @@ struct userns_exec_unified_attach_data { static int cgroup_unified_attach_wrapper(void *data) { struct userns_exec_unified_attach_data *args = data; - uid_t nsuid = (args->conf->root_nsuid_map != NULL) ? 0 : args->conf->init_uid; - gid_t nsgid = (args->conf->root_nsgid_map != NULL) ? 0 : args->conf->init_gid; + uid_t nsuid; + gid_t nsgid; int ret; if (!args->conf || args->unified_fd < 0 || args->pid <= 0) @@ -2134,6 +2134,9 @@ static int cgroup_unified_attach_wrapper(void *data) if (!lxc_setgroups(0, NULL) && errno != EPERM) return log_error_errno(-1, errno, "Failed to setgroups(0, NULL)"); + nsuid = (args->conf->root_nsuid_map != NULL) ? 0 : args->conf->init_uid; + nsgid = (args->conf->root_nsgid_map != NULL) ? 0 : args->conf->init_gid; + ret = setresgid(nsgid, nsgid, nsgid); if (ret < 0) return log_error_errno(-1, errno, "Failed to setresgid(%d, %d, %d)",