Commit 35e0b63d authored by Alan Stern's avatar Alan Stern Committed by Kamal Mostafa

SCSI: Fix NULL pointer dereference in runtime PM

commit 49718f0f upstream.

The routines in scsi_rpm.c assume that if a runtime-PM callback is
invoked for a SCSI device, it can only mean that the device's driver
has asked the block layer to handle the runtime power management (by
calling blk_pm_runtime_init(), which among other things sets q->dev).

However, this assumption turns out to be wrong for things like the ses
driver.  Normally ses devices are not allowed to do runtime PM, but
userspace can override this setting.  If this happens, the kernel gets
a NULL pointer dereference when blk_post_runtime_resume() tries to use
the uninitialized q->dev pointer.

This patch fixes the problem by calling the block layer's runtime-PM
routines only if the device's driver really does have a runtime-PM
callback routine.  Since ses doesn't define any such callbacks, the
crash won't occur.

This fixes Bugzilla #101371.
Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Reported-by: default avatarStanisław Pitucha <viraptor@gmail.com>
Reported-by: default avatarIlan Cohen <ilanco@gmail.com>
Tested-by: default avatarIlan Cohen <ilanco@gmail.com>
Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: default avatarJames Bottomley <JBottomley@Odin.com>
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
parent 55f53a66
...@@ -217,15 +217,15 @@ static int sdev_runtime_suspend(struct device *dev) ...@@ -217,15 +217,15 @@ static int sdev_runtime_suspend(struct device *dev)
{ {
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
struct scsi_device *sdev = to_scsi_device(dev); struct scsi_device *sdev = to_scsi_device(dev);
int err; int err = 0;
err = blk_pre_runtime_suspend(sdev->request_queue); if (pm && pm->runtime_suspend) {
if (err) err = blk_pre_runtime_suspend(sdev->request_queue);
return err; if (err)
if (pm && pm->runtime_suspend) return err;
err = pm->runtime_suspend(dev); err = pm->runtime_suspend(dev);
blk_post_runtime_suspend(sdev->request_queue, err); blk_post_runtime_suspend(sdev->request_queue, err);
}
return err; return err;
} }
...@@ -248,11 +248,11 @@ static int sdev_runtime_resume(struct device *dev) ...@@ -248,11 +248,11 @@ static int sdev_runtime_resume(struct device *dev)
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
int err = 0; int err = 0;
blk_pre_runtime_resume(sdev->request_queue); if (pm && pm->runtime_resume) {
if (pm && pm->runtime_resume) blk_pre_runtime_resume(sdev->request_queue);
err = pm->runtime_resume(dev); err = pm->runtime_resume(dev);
blk_post_runtime_resume(sdev->request_queue, err); blk_post_runtime_resume(sdev->request_queue, err);
}
return err; return err;
} }
......
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