提交 dc4def77 编写于 作者: A Al Viro 提交者: Xie XiuQi

fix cgroup_do_mount() handling of failure exits

mainline inclusion
from mainline-5.1-rc1
commit 399504e21a10be16dd1408ba0147367d9d82a10c
category: bugfix
bugzilla: 11147
CVE: NA

-------------------------------------------------
same story as with last May fixes in sysfs (7b745a4e
"unfuck sysfs_mount()"); new_sb is left uninitialized
in case of early errors in kernfs_mount_ns() and papering
over it by treating any error from kernfs_mount_ns() as
equivalent to !new_ns ends up conflating the cases when
objects had never been transferred to a superblock with
ones when that has happened and resulting new superblock
had been dropped.  Easily fixed (same way as in sysfs
case).  Additionally, there's a superblock leak on
kernfs_node_dentry() failure *and* a dentry leak inside
kernfs_node_dentry() itself - the latter on probably
impossible errors, but the former not impossible to trigger
(as the matter of fact, injecting allocation failures
at that point *does* trigger it).

Cc: stable@kernel.org
Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
(cherry picked from commit 399504e21a10be16dd1408ba0147367d9d82a10c)
Signed-off-by: NZhen Lei <thunder.leizhen@huawei.com>
Reviewed-by: NYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 e880d8dd
...@@ -196,8 +196,10 @@ struct dentry *kernfs_node_dentry(struct kernfs_node *kn, ...@@ -196,8 +196,10 @@ struct dentry *kernfs_node_dentry(struct kernfs_node *kn,
return dentry; return dentry;
knparent = find_next_ancestor(kn, NULL); knparent = find_next_ancestor(kn, NULL);
if (WARN_ON(!knparent)) if (WARN_ON(!knparent)) {
dput(dentry);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
}
do { do {
struct dentry *dtmp; struct dentry *dtmp;
...@@ -206,8 +208,10 @@ struct dentry *kernfs_node_dentry(struct kernfs_node *kn, ...@@ -206,8 +208,10 @@ struct dentry *kernfs_node_dentry(struct kernfs_node *kn,
if (kn == knparent) if (kn == knparent)
return dentry; return dentry;
kntmp = find_next_ancestor(kn, knparent); kntmp = find_next_ancestor(kn, knparent);
if (WARN_ON(!kntmp)) if (WARN_ON(!kntmp)) {
dput(dentry);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
}
dtmp = lookup_one_len_unlocked(kntmp->name, dentry, dtmp = lookup_one_len_unlocked(kntmp->name, dentry,
strlen(kntmp->name)); strlen(kntmp->name));
dput(dentry); dput(dentry);
......
...@@ -1998,7 +1998,7 @@ struct dentry *cgroup_do_mount(struct file_system_type *fs_type, int flags, ...@@ -1998,7 +1998,7 @@ struct dentry *cgroup_do_mount(struct file_system_type *fs_type, int flags,
struct cgroup_namespace *ns) struct cgroup_namespace *ns)
{ {
struct dentry *dentry; struct dentry *dentry;
bool new_sb; bool new_sb = false;
dentry = kernfs_mount(fs_type, flags, root->kf_root, magic, &new_sb); dentry = kernfs_mount(fs_type, flags, root->kf_root, magic, &new_sb);
...@@ -2008,6 +2008,7 @@ struct dentry *cgroup_do_mount(struct file_system_type *fs_type, int flags, ...@@ -2008,6 +2008,7 @@ struct dentry *cgroup_do_mount(struct file_system_type *fs_type, int flags,
*/ */
if (!IS_ERR(dentry) && ns != &init_cgroup_ns) { if (!IS_ERR(dentry) && ns != &init_cgroup_ns) {
struct dentry *nsdentry; struct dentry *nsdentry;
struct super_block *sb = dentry->d_sb;
struct cgroup *cgrp; struct cgroup *cgrp;
mutex_lock(&cgroup_mutex); mutex_lock(&cgroup_mutex);
...@@ -2018,12 +2019,14 @@ struct dentry *cgroup_do_mount(struct file_system_type *fs_type, int flags, ...@@ -2018,12 +2019,14 @@ struct dentry *cgroup_do_mount(struct file_system_type *fs_type, int flags,
spin_unlock_irq(&css_set_lock); spin_unlock_irq(&css_set_lock);
mutex_unlock(&cgroup_mutex); mutex_unlock(&cgroup_mutex);
nsdentry = kernfs_node_dentry(cgrp->kn, dentry->d_sb); nsdentry = kernfs_node_dentry(cgrp->kn, sb);
dput(dentry); dput(dentry);
if (IS_ERR(nsdentry))
deactivate_locked_super(sb);
dentry = nsdentry; dentry = nsdentry;
} }
if (IS_ERR(dentry) || !new_sb) if (!new_sb)
cgroup_put(&root->cgrp); cgroup_put(&root->cgrp);
return dentry; return dentry;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册