Re: [PATCH v2] scsi: sg: Avoid sg device teardown race

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

 



On 3/20/24 04:08, Alexander Wetzel wrote:
sg_remove_sfp_usercontext() must not use sg_device_destroy() after
calling scsi_device_put().

sg_device_destroy() is accessing the parent scsi device request_queue.
Which will already be set to NULL when the preceding call to
scsi_device_put() removed the last reference to the parent scsi device.

The resulting NULL pointer exception will then crash the kernel.

Link: https://lore.kernel.org/r/20240305150509.23896-1-Alexander@xxxxxxxxxxxxxx
Cc: <stable@xxxxxxxxxxxxxxx>
Signed-off-by: Alexander Wetzel <Alexander@xxxxxxxxxxxxxx>
---
Changes compared to V1:
Reworked the commit message

Alexander
---
  drivers/scsi/sg.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 86210e4dd0d3..80e0d1981191 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -2232,8 +2232,8 @@ sg_remove_sfp_usercontext(struct work_struct *work)
  			"sg_remove_sfp: sfp=0x%p\n", sfp));
  	kfree(sfp);
- scsi_device_put(sdp->device);
  	kref_put(&sdp->d_ref, sg_device_destroy);
+	scsi_device_put(sdp->device);
  	module_put(THIS_MODULE);
  }

Is it guaranteed that the above kref_put() call is the last kref_put()
call on sdp->d_ref? If not, how about inserting code between the
kref_put() call and the scsi_device_put() call that waits until
sg_device_destroy() has finished?

Thanks,

Bart.




[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux