提交 6b710995 编写于 作者: M Miaohe Lin 提交者: Zheng Zengkai

mm/hugetlb: fix potential double free in hugetlb_register_node() error path

stable inclusion
from stable-5.10.20
commit 89b2dbd807b12c2ccd6e6705672eeaf41170c733
bugzilla: 50608

--------------------------------

[ Upstream commit cc2205a6 ]

In hugetlb_sysfs_add_hstate(), we would do kobject_put() on hstate_kobjs
when failed to create sysfs group but forget to set hstate_kobjs to NULL.
Then in hugetlb_register_node() error path, we may free it again via
hugetlb_unregister_node().

Link: https://lkml.kernel.org/r/20210107123249.36964-1-linmiaohe@huawei.com
Fixes: a3437870 ("hugetlb: new sysfs interface")
Signed-off-by: NMiaohe Lin <linmiaohe@huawei.com>
Reviewed-by: NMike Kravetz <mike.kravetz@oracle.com>
Reviewed-by: NMuchun Song <smuchun@gmail.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 8bf54d76
...@@ -2984,8 +2984,10 @@ static int hugetlb_sysfs_add_hstate(struct hstate *h, struct kobject *parent, ...@@ -2984,8 +2984,10 @@ static int hugetlb_sysfs_add_hstate(struct hstate *h, struct kobject *parent,
return -ENOMEM; return -ENOMEM;
retval = sysfs_create_group(hstate_kobjs[hi], hstate_attr_group); retval = sysfs_create_group(hstate_kobjs[hi], hstate_attr_group);
if (retval) if (retval) {
kobject_put(hstate_kobjs[hi]); kobject_put(hstate_kobjs[hi]);
hstate_kobjs[hi] = NULL;
}
return retval; return retval;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册