Commit e8c50a20 authored by Tejun Heo's avatar Tejun Heo Committed by Tim Gardner

UBUNTU: SAUCE: (noup) cgroup: fix and restructure error handling in copy_cgroup_ns()

copy_cgroup_ns()'s error handling was broken and the attempt to fix it
d2202557 ("cgroup: fix alloc_cgroup_ns() error handling in
copy_cgroup_ns()") was broken too in that it ended up trying an
ERR_PTR() value.

There's only one place where copy_cgroup_ns() needs to perform cleanup
after failure.  Simplify and fix the error handling by removing the
goto's.

(Ported from upstream patch for linux-next - Serge)
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarSerge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: default avatarTim Gardner <tim.gardner@canonical.com>
parent b9c6f006
......@@ -5951,9 +5951,8 @@ struct cgroup_namespace *
copy_cgroup_ns(unsigned long flags, struct user_namespace *user_ns,
struct cgroup_namespace *old_ns)
{
struct cgroup_namespace *new_ns = NULL;
struct css_set *cset = NULL;
int err;
struct cgroup_namespace *new_ns;
struct css_set *cset;
BUG_ON(!old_ns);
......@@ -5963,9 +5962,8 @@ copy_cgroup_ns(unsigned long flags, struct user_namespace *user_ns,
}
/* Allow only sysadmin to create cgroup namespace. */
err = -EPERM;
if (!ns_capable(user_ns, CAP_SYS_ADMIN))
goto err_out;
return ERR_PTR(-EPERM);
mutex_lock(&cgroup_mutex);
spin_lock_bh(&css_set_lock);
......@@ -5976,21 +5974,16 @@ copy_cgroup_ns(unsigned long flags, struct user_namespace *user_ns,
spin_unlock_bh(&css_set_lock);
mutex_unlock(&cgroup_mutex);
err = -ENOMEM;
new_ns = alloc_cgroup_ns();
if (!new_ns)
goto err_out;
if (IS_ERR(new_ns)) {
put_css_set(cset);
return new_ns;
}
new_ns->user_ns = get_user_ns(user_ns);
new_ns->root_cset = cset;
return new_ns;
err_out:
if (cset)
put_css_set(cset);
kfree(new_ns);
return ERR_PTR(err);
}
static inline struct cgroup_namespace *to_cg_ns(struct ns_common *ns)
......
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