Skip to content

Commit 889c733

Browse files
jhovoldgregkh
authored andcommitted
firmware: qemu_fw_cfg: fix NULL-pointer deref on duplicate entries
commit d3e3055 upstream. Commit fe3c606 ("firmware: Fix a reference count leak.") "fixed" a kobject leak in the file registration helper by properly calling kobject_put() for the entry in case registration of the object fails (e.g. due to a name collision). This would however result in a NULL pointer dereference when the release function tries to remove the never added entry from the fw_cfg_entry_cache list. Fix this by moving the list-removal out of the release function. Note that the offending commit was one of the benign looking umn.edu fixes which was reviewed but not reverted. [1][2] [1] https://lore.kernel.org/r/202105051005.49BFABCE@keescook [2] https://lore.kernel.org/all/YIg7ZOZvS3a8LjSv@kroah.com Fixes: fe3c606 ("firmware: Fix a reference count leak.") Cc: stable@vger.kernel.org # 5.8 Cc: Qiushi Wu <wu000273@umn.edu> Cc: Kees Cook <keescook@chromium.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org> Link: https://lore.kernel.org/r/20211201132528.30025-2-johan@kernel.org Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ff9588c commit 889c733

1 file changed

Lines changed: 1 addition & 4 deletions

File tree

drivers/firmware/qemu_fw_cfg.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,7 @@ static void fw_cfg_sysfs_cache_cleanup(void)
388388
struct fw_cfg_sysfs_entry *entry, *next;
389389

390390
list_for_each_entry_safe(entry, next, &fw_cfg_entry_cache, list) {
391-
/* will end up invoking fw_cfg_sysfs_cache_delist()
392-
* via each object's release() method (i.e. destructor)
393-
*/
391+
fw_cfg_sysfs_cache_delist(entry);
394392
kobject_put(&entry->kobj);
395393
}
396394
}
@@ -448,7 +446,6 @@ static void fw_cfg_sysfs_release_entry(struct kobject *kobj)
448446
{
449447
struct fw_cfg_sysfs_entry *entry = to_entry(kobj);
450448

451-
fw_cfg_sysfs_cache_delist(entry);
452449
kfree(entry);
453450
}
454451

0 commit comments

Comments
 (0)