Commit 23695e41 authored by Junichi Nomura's avatar Junichi Nomura Committed by James Bottomley

scsi_dh: fix use-after-free when removing scsi device

The commit 1bab0de0 ("dm-mpath, scsi_dh: don't let dm detach device
handlers") removed reference counting of attached scsi device handler.
As a result, handler data is freed immediately via scsi_dh->detach()
in the context of scsi_remove_device() where activation request can be
still in flight.

This patch moves scsi_dh_handler_detach() to sdev releasing function,
scsi_device_dev_release_usercontext(), at that point the device
is already in quiesced state.

Fixes: 1bab0de0 ("dm-mpath, scsi_dh: don't let dm detach device handlers")
Signed-off-by: default avatarJun'ichi Nomura <j-nomura@ce.jp.nec.com>
Acked-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJames Bottomley <JBottomley@Odin.com>
parent 22805217
...@@ -232,10 +232,14 @@ int scsi_dh_add_device(struct scsi_device *sdev) ...@@ -232,10 +232,14 @@ int scsi_dh_add_device(struct scsi_device *sdev)
return err; return err;
} }
void scsi_dh_remove_device(struct scsi_device *sdev) void scsi_dh_release_device(struct scsi_device *sdev)
{ {
if (sdev->handler) if (sdev->handler)
scsi_dh_handler_detach(sdev); scsi_dh_handler_detach(sdev);
}
void scsi_dh_remove_device(struct scsi_device *sdev)
{
device_remove_file(&sdev->sdev_gendev, &scsi_dh_state_attr); device_remove_file(&sdev->sdev_gendev, &scsi_dh_state_attr);
} }
......
...@@ -173,9 +173,11 @@ extern struct async_domain scsi_sd_probe_domain; ...@@ -173,9 +173,11 @@ extern struct async_domain scsi_sd_probe_domain;
/* scsi_dh.c */ /* scsi_dh.c */
#ifdef CONFIG_SCSI_DH #ifdef CONFIG_SCSI_DH
int scsi_dh_add_device(struct scsi_device *sdev); int scsi_dh_add_device(struct scsi_device *sdev);
void scsi_dh_release_device(struct scsi_device *sdev);
void scsi_dh_remove_device(struct scsi_device *sdev); void scsi_dh_remove_device(struct scsi_device *sdev);
#else #else
static inline int scsi_dh_add_device(struct scsi_device *sdev) { return 0; } static inline int scsi_dh_add_device(struct scsi_device *sdev) { return 0; }
static inline void scsi_dh_release_device(struct scsi_device *sdev) { }
static inline void scsi_dh_remove_device(struct scsi_device *sdev) { } static inline void scsi_dh_remove_device(struct scsi_device *sdev) { }
#endif #endif
......
...@@ -399,6 +399,8 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work) ...@@ -399,6 +399,8 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
sdev = container_of(work, struct scsi_device, ew.work); sdev = container_of(work, struct scsi_device, ew.work);
scsi_dh_release_device(sdev);
parent = sdev->sdev_gendev.parent; parent = sdev->sdev_gendev.parent;
spin_lock_irqsave(sdev->host->host_lock, flags); spin_lock_irqsave(sdev->host->host_lock, flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment