Skip to content

Commit 6b8c3a1

Browse files
jhovoldgregkh
authored andcommitted
firmware: qemu_fw_cfg: fix kobject leak in probe error path
commit 47a1db8 upstream. An initialised kobject must be freed using kobject_put() to avoid leaking associated resources (e.g. the object name). Commit fe3c606 ("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(). Fixes: 75f3e8e ("firmware: introduce sysfs driver for QEMU's fw_cfg device") Cc: stable@vger.kernel.org # 4.6 Cc: Gabriel Somlo <somlo@cmu.edu> Signed-off-by: Johan Hovold <johan@kernel.org> Link: https://lore.kernel.org/r/20211201132528.30025-3-johan@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 889c733 commit 6b8c3a1

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

drivers/firmware/qemu_fw_cfg.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -603,15 +603,13 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f)
603603
/* register entry under "/sys/firmware/qemu_fw_cfg/by_key/" */
604604
err = kobject_init_and_add(&entry->kobj, &fw_cfg_sysfs_entry_ktype,
605605
fw_cfg_sel_ko, "%d", entry->select);
606-
if (err) {
607-
kobject_put(&entry->kobj);
608-
return err;
609-
}
606+
if (err)
607+
goto err_put_entry;
610608

611609
/* add raw binary content access */
612610
err = sysfs_create_bin_file(&entry->kobj, &fw_cfg_sysfs_attr_raw);
613611
if (err)
614-
goto err_add_raw;
612+
goto err_del_entry;
615613

616614
/* try adding "/sys/firmware/qemu_fw_cfg/by_name/" symlink */
617615
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)
620618
fw_cfg_sysfs_cache_enlist(entry);
621619
return 0;
622620

623-
err_add_raw:
621+
err_del_entry:
624622
kobject_del(&entry->kobj);
625-
kfree(entry);
623+
err_put_entry:
624+
kobject_put(&entry->kobj);
626625
return err;
627626
}
628627

0 commit comments

Comments
 (0)