Patch "scsi: scsi_debug: Fix possible name leak in sdebug_add_host_helper()" has been added to the 5.10-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    scsi: scsi_debug: Fix possible name leak in sdebug_add_host_helper()

to the 5.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     scsi-scsi_debug-fix-possible-name-leak-in-sdebug_add.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit de1168d952c328025234f6ae4ee0f641505cadfb
Author: Yang Yingliang <yangyingliang@xxxxxxxxxx>
Date:   Sat Nov 12 21:10:10 2022 +0800

    scsi: scsi_debug: Fix possible name leak in sdebug_add_host_helper()
    
    [ Upstream commit e6d773f93a49e0eda88a903a2a6542ca83380eb1 ]
    
    Afer commit 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id
    string array"), the name of device is allocated dynamically, it needs be
    freed when device_register() returns error.
    
    As comment of device_register() says, one should use put_device() to give
    up the reference in the error path. Fix this by calling put_device(), then
    the name can be freed in kobject_cleanup(), and sdbg_host is freed in
    sdebug_release_adapter().
    
    When the device release is not set, it means the device is not initialized.
    We can not call put_device() in this case. Use kfree() to free memory.
    
    Fixes: 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")
    Signed-off-by: Yang Yingliang <yangyingliang@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20221112131010.3757845-1-yangyingliang@xxxxxxxxxx
    Signed-off-by: Martin K. Petersen <martin.petersen@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index bd63357f439d..7cfc6db81763 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -7103,7 +7103,10 @@ static int sdebug_add_host_helper(int per_host_idx)
 		kfree(sdbg_devinfo->zstate);
 		kfree(sdbg_devinfo);
 	}
-	kfree(sdbg_host);
+	if (sdbg_host->dev.release)
+		put_device(&sdbg_host->dev);
+	else
+		kfree(sdbg_host);
 	pr_warn("%s: failed, errno=%d\n", __func__, -error);
 	return error;
 }



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux