FAILED: patch "[PATCH] firmware: qemu_fw_cfg: fix kobject leak in probe error path" failed to apply to 4.14-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 4.14-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 47a1db8e797da01a1309bf42e0c0d771d4e4d4f3 Mon Sep 17 00:00:00 2001
From: Johan Hovold <[email protected]>
Date: Wed, 1 Dec 2021 14:25:26 +0100
Subject: [PATCH] firmware: qemu_fw_cfg: fix kobject leak in probe error path
An initialised kobject must be freed using kobject_put() to avoid leaking associated resources (e.g. the object name).
Commit fe3c60684377 ("firmware: Fix a reference count leak.") "fixed" the leak in the first error path of the file registration helper but left the second one unchanged. This "fix" would however result in a NULL pointer dereference due to the release function also removing the never added entry from the fw_cfg_entry_cache list. This has now been addressed.
Fix the remaining kobject leak by restoring the common error path and adding the missing kobject_put().
drivers/firmware/qemu_fw_cfg.c +6 -7
@@ -603,15 +603,13 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f)/* register entry under "/sys/firmware/qemu_fw_cfg/by_key/" */ err =kobject_init_and_add (&entry->kobj, &fw_cfg_sysfs_entry_ktype, fw_cfg_sel_ko,"%d" , entry->select); -if (err) { -kobject_put (&entry->kobj); -return err; - } +if (err) + goto err_put_entry;/* add raw binary content access */ err =sysfs_create_bin_file (&entry->kobj, &fw_cfg_sysfs_attr_raw);if (err) - goto err_add_raw; + goto err_del_entry;/* try adding "/sys/firmware/qemu_fw_cfg/by_name/" symlink */ fw_cfg_build_symlink (fw_cfg_fname_kset, &entry->kobj, entry->name);
@@ -620,9 +618,10 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f)fw_cfg_sysfs_cache_enlist (entry);return 0 ; -err_add_raw: +err_del_entry:kobject_del (&entry->kobj); -kfree (entry); +err_put_entry: +kobject_put (&entry->kobj);return err; }
Hi Greg,
Quoted 5 lines · On Tue, Jan 18, 2022 at 09:51:44AM +0100, [email protected] wrote:
The patch below does not apply to the 4.14-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
Here is the backport along with the backport of:fe3c60684377 ("firmware: Fix a reference count leak.") which was needed to make the backport easier. Both will also apply to 4.9-stable.
--
Regards
Sudip
From cee693694f56f4819bc92e406eeb4f44151b3851 Mon Sep 17 00:00:00 2001
From: Qiushi Wu <[email protected]>
Date: Sat, 13 Jun 2020 14:05:33 -0500
Subject: [PATCH 1/2] firmware: Fix a reference count leak.
commit fe3c60684377d5ad9b0569b87ed3e26e12c8173b upstream.
kobject_init_and_add() takes reference even when it fails. If this function returns an error, kobject_put() must be called to properly clean up the memory associated with the object. Callback function fw_cfg_sysfs_release_entry() in kobject_put() can handle the pointer "entry" properly.
--- drivers/firmware/qemu_fw_cfg.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/firmware/qemu_fw_cfg.c +4 -3
@@ -461,8 +461,10 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f)/* register entry under "/sys/firmware/qemu_fw_cfg/by_key/" */ err =kobject_init_and_add (&entry->kobj, &fw_cfg_sysfs_entry_ktype, fw_cfg_sel_ko,"%d" , entry->f.select); -if (err) - goto err_register; +if (err) { +kobject_put (&entry->kobj); +return err; + }/* add raw binary content access */ err =sysfs_create_bin_file (&entry->kobj, &fw_cfg_sysfs_attr_raw);
@@ -478,7 +480,6 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f) err_add_raw:kobject_del (&entry->kobj); -err_register:kfree (entry);return err; }
Signature · 1 line
2.30.2
From a0efe2fb6149f222be297da49d80fd05ec22c915 Mon Sep 17 00:00:00 2001
From: Johan Hovold <[email protected]>
Date: Wed, 1 Dec 2021 14:25:26 +0100
Subject: [PATCH 2/2] firmware: qemu_fw_cfg: fix kobject leak in probe error
path
commit 47a1db8e797da01a1309bf42e0c0d771d4e4d4f3 upstream.
An initialised kobject must be freed using kobject_put() to avoid leaking associated resources (e.g. the object name).
Commit fe3c60684377 ("firmware: Fix a reference count leak.") "fixed" the leak in the first error path of the file registration helper but left the second one unchanged. This "fix" would however result in a NULL pointer dereference due to the release function also removing the never added entry from the fw_cfg_entry_cache list. This has now been addressed.
Fix the remaining kobject leak by restoring the common error path and adding the missing kobject_put().
--- drivers/firmware/qemu_fw_cfg.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/firmware/qemu_fw_cfg.c +6 -7
@@ -461,15 +461,13 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f)/* register entry under "/sys/firmware/qemu_fw_cfg/by_key/" */ err =kobject_init_and_add (&entry->kobj, &fw_cfg_sysfs_entry_ktype, fw_cfg_sel_ko,"%d" , entry->f.select); -if (err) { -kobject_put (&entry->kobj); -return err; - } +if (err) + goto err_put_entry;/* add raw binary content access */ err =sysfs_create_bin_file (&entry->kobj, &fw_cfg_sysfs_attr_raw);if (err) - goto err_add_raw; + goto err_del_entry;/* try adding "/sys/firmware/qemu_fw_cfg/by_name/" symlink */ fw_cfg_build_symlink (fw_cfg_fname_kset, &entry->kobj, entry->f.name);
@@ -478,9 +476,10 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f)fw_cfg_sysfs_cache_enlist (entry);return 0 ; -err_add_raw: +err_del_entry:kobject_del (&entry->kobj); -kfree (entry); +err_put_entry: +kobject_put (&entry->kobj);return err; }
Signature · 1 line
2.30.2
Greg KH
maintainerQuoted 4 lines · Sudip Mukherjee
Hi Greg,
Quoted 1 line · On Tue, Jan 18, 2022 at 09:51:44AM +0100, [email protected] wrote:
Quoted 8 lines
Quoted 4 lines
The patch below does not apply to the 4.14-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.Here is the backport along with the backport of:
fe3c60684377("firmware: Fix a reference count leak.") which was needed to make the backport easier. Both will also apply to 4.9-stable.
Now queued up, thanks!
greg k-h