]> Git Repo - linux.git/commitdiff
firmware_loader: Fix use-after-free during unregister
authorRuss Weight <[email protected]>
Mon, 29 Aug 2022 17:45:57 +0000 (10:45 -0700)
committerGreg Kroah-Hartman <[email protected]>
Thu, 1 Sep 2022 15:46:54 +0000 (17:46 +0200)
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: 97730bbb242c ("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]>
drivers/base/firmware_loader/sysfs_upload.c

index 87044d52322aa2ff9fd8d5654185585b9a1d9d3c..63e15bddd80ca553c6180c600ab2416725f993f5 100644 (file)
@@ -377,6 +377,7 @@ void firmware_upload_unregister(struct fw_upload *fw_upload)
 {
        struct fw_sysfs *fw_sysfs = fw_upload->priv;
        struct fw_upload_priv *fw_upload_priv = fw_sysfs->fw_upload_priv;
+       struct module *module = fw_upload_priv->module;
 
        mutex_lock(&fw_upload_priv->lock);
        if (fw_upload_priv->progress == FW_UPLOAD_PROG_IDLE) {
@@ -392,6 +393,6 @@ void firmware_upload_unregister(struct fw_upload *fw_upload)
 
 unregister:
        device_unregister(&fw_sysfs->dev);
-       module_put(fw_upload_priv->module);
+       module_put(module);
 }
 EXPORT_SYMBOL_GPL(firmware_upload_unregister);
This page took 0.056891 seconds and 4 git commands to generate.