* [PATCH] firmware: qemu_fw_cfg: fix possible memory leak in fw_cfg_build_symlink()
@ 2022-10-17 13:35 Yang Yingliang via
0 siblings, 0 replies; only message in thread
From: Yang Yingliang via @ 2022-10-17 13:35 UTC (permalink / raw)
To: qemu-devel; +Cc: somlo, mst, gregkh, yangyingliang
Inject fault while probing module, kset_register() may fail, if
it fails, but the refcount of kobject is not decreased to 0, the
name allocated in kobject_set_name() is leaked. To fix this by
calling kset_put(), so that name can be freed in callback function
kobject_cleanup() and 'subdir' is freed in kset_release().
unreferenced object 0xffff88810ad69050 (size 8):
comm "swapper/0", pid 1, jiffies 4294677178 (age 38.812s)
hex dump (first 8 bytes):
65 74 63 00 81 88 ff ff etc.....
backtrace:
[<00000000a80c7bf1>] __kmalloc_node_track_caller+0x44/0x1b0
[<000000003f0167c7>] kstrdup+0x3a/0x70
[<0000000049336709>] kstrdup_const+0x41/0x60
[<00000000175616e4>] kvasprintf_const+0xf5/0x180
[<000000004bcc30f7>] kobject_set_name_vargs+0x56/0x150
[<000000004b0251bd>] kobject_set_name+0xab/0xe0
[<00000000700151fb>] fw_cfg_sysfs_probe+0xa5b/0x1320
Fixes: 246c46ebaeae ("firmware: create directory hierarchy for sysfs fw_cfg entries")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/firmware/qemu_fw_cfg.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c
index a69399a6b7c0..d036e69cabbb 100644
--- a/drivers/firmware/qemu_fw_cfg.c
+++ b/drivers/firmware/qemu_fw_cfg.c
@@ -544,7 +544,7 @@ static int fw_cfg_build_symlink(struct kset *dir,
}
ret = kset_register(subdir);
if (ret) {
- kfree(subdir);
+ kset_put(subdir);
break;
}
--
2.25.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-10-17 14:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-17 13:35 [PATCH] firmware: qemu_fw_cfg: fix possible memory leak in fw_cfg_build_symlink() Yang Yingliang via
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.