]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
mm/hugetlb: fix potential double free in hugetlb_register_node() error path
authorMiaohe Lin <linmiaohe@huawei.com>
Wed, 24 Feb 2021 20:06:50 +0000 (12:06 -0800)
committerAndrea Righi <andrea.righi@canonical.com>
Mon, 15 Mar 2021 14:09:34 +0000 (15:09 +0100)
[ Upstream commit cc2205a67dec5a700227a693fc113441e73e4641 ]

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: a3437870160c ("hugetlb: new sysfs interface")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
Reviewed-by: Muchun Song <smuchun@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
mm/hugetlb.c

index 4bdb58ab14cbbd659a1f9ca2e531a995fed03077..bc61eea60e07eee97c172301d837988d5959c269 100644 (file)
@@ -2988,8 +2988,10 @@ static int hugetlb_sysfs_add_hstate(struct hstate *h, struct kobject *parent,
                return -ENOMEM;
 
        retval = sysfs_create_group(hstate_kobjs[hi], hstate_attr_group);
-       if (retval)
+       if (retval) {
                kobject_put(hstate_kobjs[hi]);
+               hstate_kobjs[hi] = NULL;
+       }
 
        return retval;
 }