Commit 994dd5b3 authored by Miaoqian Lin's avatar Miaoqian Lin Committed by Xia Fukun
Browse files

firmware: dmi-sysfs: Fix memory leak in dmi_sysfs_register_handle

stable inclusion
from stable-v4.19.247
commit c66cc3c62870a27ea8f060a7e4c1ad8d26dd3f0d
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IBP6BN
CVE: CVE-2022-49370

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=c66cc3c62870a27ea8f060a7e4c1ad8d26dd3f0d



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

[ Upstream commit 660ba678 ]

kobject_init_and_add() takes reference even when it fails.
According to the doc of kobject_init_and_add()

   If this function returns an error, kobject_put() must be called to
   properly clean up the memory associated with the object.

Fix this issue by calling kobject_put().

Fixes: 948af1f0 ("firmware: Basic dmi-sysfs support")
Signed-off-by: default avatarMiaoqian Lin <linmq006@gmail.com>
Link: https://lore.kernel.org/r/20220511071421.9769-1-linmq006@gmail.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarXia Fukun <xiafukun@huawei.com>
parent e876b90a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -602,7 +602,7 @@ static void __init dmi_sysfs_register_handle(const struct dmi_header *dh,
				    "%d-%d", dh->type, entry->instance);

	if (*ret) {
		kfree(entry);
		kobject_put(&entry->kobj);
		return;
	}