diff options
author | Junichi Nomura <j-nomura@ce.jp.nec.com> | 2015-10-06 00:32:57 -0400 |
---|---|---|
committer | James Bottomley <JBottomley@Odin.com> | 2015-10-26 22:22:37 -0400 |
commit | 23695e41a1cac017edad2b38607f33678a31b877 (patch) | |
tree | 2cadb3d6276f29f8a3555b8601d91c4aaa15d50e | |
parent | 2280521719e81919283b82902ac24058f87dfc1b (diff) |
scsi_dh: fix use-after-free when removing scsi device
The commit 1bab0de0274f ("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: 1bab0de0274f ("dm-mpath, scsi_dh: don't let dm detach device handlers")
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: James Bottomley <JBottomley@Odin.com>
-rw-r--r-- | drivers/scsi/scsi_dh.c | 6 | ||||
-rw-r--r-- | drivers/scsi/scsi_priv.h | 2 | ||||
-rw-r--r-- | drivers/scsi/scsi_sysfs.c | 2 |
3 files changed, 9 insertions, 1 deletions
diff --git a/drivers/scsi/scsi_dh.c b/drivers/scsi/scsi_dh.c index 0a2168e69bbc..cb78388de3fc 100644 --- a/drivers/scsi/scsi_dh.c +++ b/drivers/scsi/scsi_dh.c | |||
@@ -232,10 +232,14 @@ int scsi_dh_add_device(struct scsi_device *sdev) | |||
232 | return err; | 232 | return err; |
233 | } | 233 | } |
234 | 234 | ||
235 | void scsi_dh_remove_device(struct scsi_device *sdev) | 235 | void scsi_dh_release_device(struct scsi_device *sdev) |
236 | { | 236 | { |
237 | if (sdev->handler) | 237 | if (sdev->handler) |
238 | scsi_dh_handler_detach(sdev); | 238 | scsi_dh_handler_detach(sdev); |
239 | } | ||
240 | |||
241 | void scsi_dh_remove_device(struct scsi_device *sdev) | ||
242 | { | ||
239 | device_remove_file(&sdev->sdev_gendev, &scsi_dh_state_attr); | 243 | device_remove_file(&sdev->sdev_gendev, &scsi_dh_state_attr); |
240 | } | 244 | } |
241 | 245 | ||
diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h index 644bb7339b55..4d01cdb1b348 100644 --- a/drivers/scsi/scsi_priv.h +++ b/drivers/scsi/scsi_priv.h | |||
@@ -173,9 +173,11 @@ extern struct async_domain scsi_sd_probe_domain; | |||
173 | /* scsi_dh.c */ | 173 | /* scsi_dh.c */ |
174 | #ifdef CONFIG_SCSI_DH | 174 | #ifdef CONFIG_SCSI_DH |
175 | int scsi_dh_add_device(struct scsi_device *sdev); | 175 | int scsi_dh_add_device(struct scsi_device *sdev); |
176 | void scsi_dh_release_device(struct scsi_device *sdev); | ||
176 | void scsi_dh_remove_device(struct scsi_device *sdev); | 177 | void scsi_dh_remove_device(struct scsi_device *sdev); |
177 | #else | 178 | #else |
178 | static inline int scsi_dh_add_device(struct scsi_device *sdev) { return 0; } | 179 | static inline int scsi_dh_add_device(struct scsi_device *sdev) { return 0; } |
180 | static inline void scsi_dh_release_device(struct scsi_device *sdev) { } | ||
179 | static inline void scsi_dh_remove_device(struct scsi_device *sdev) { } | 181 | static inline void scsi_dh_remove_device(struct scsi_device *sdev) { } |
180 | #endif | 182 | #endif |
181 | 183 | ||
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index b333389f248f..dff8fafb741c 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c | |||
@@ -399,6 +399,8 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work) | |||
399 | 399 | ||
400 | sdev = container_of(work, struct scsi_device, ew.work); | 400 | sdev = container_of(work, struct scsi_device, ew.work); |
401 | 401 | ||
402 | scsi_dh_release_device(sdev); | ||
403 | |||
402 | parent = sdev->sdev_gendev.parent; | 404 | parent = sdev->sdev_gendev.parent; |
403 | 405 | ||
404 | spin_lock_irqsave(sdev->host->host_lock, flags); | 406 | spin_lock_irqsave(sdev->host->host_lock, flags); |