Skip to content

Commit 8b40c38

Browse files
Russ Weightgregkh
authored andcommitted
firmware_loader: Fix use-after-free during unregister
In the following code within firmware_upload_unregister(), the call to device_unregister() could result in the dev_release function freeing the fw_upload_priv structure before it is dereferenced for the call to module_put(). This bug was found by the kernel test robot using CONFIG_KASAN while running the firmware selftests. device_unregister(&fw_sysfs->dev); module_put(fw_upload_priv->module); The problem is fixed by copying fw_upload_priv->module to a local variable for use when calling device_unregister(). Fixes: 97730bb ("firmware_loader: Add firmware-upload support") Cc: stable <[email protected]> Reported-by: kernel test robot <[email protected]> Reviewed-by: Matthew Gerlach <[email protected]> Signed-off-by: Russ Weight <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9b03e79 commit 8b40c38

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/base/firmware_loader/sysfs_upload.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ void firmware_upload_unregister(struct fw_upload *fw_upload)
377377
{
378378
struct fw_sysfs *fw_sysfs = fw_upload->priv;
379379
struct fw_upload_priv *fw_upload_priv = fw_sysfs->fw_upload_priv;
380+
struct module *module = fw_upload_priv->module;
380381

381382
mutex_lock(&fw_upload_priv->lock);
382383
if (fw_upload_priv->progress == FW_UPLOAD_PROG_IDLE) {
@@ -392,6 +393,6 @@ void firmware_upload_unregister(struct fw_upload *fw_upload)
392393

393394
unregister:
394395
device_unregister(&fw_sysfs->dev);
395-
module_put(fw_upload_priv->module);
396+
module_put(module);
396397
}
397398
EXPORT_SYMBOL_GPL(firmware_upload_unregister);

0 commit comments

Comments
 (0)