aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorKen Xue <ken.xue@amd.com>2015-12-01 01:45:46 -0500
committerJens Axboe <axboe@fb.com>2015-12-03 22:35:02 -0500
commit4fd41a8552afc01054d9d9fc7f1a63c324867d27 (patch)
tree6e2f5b3206f75c732b307402d2f726317499f712 /block
parent071f5d105a0ae93aeb02197c4ee3557e8cc57a21 (diff)
SCSI: Fix NULL pointer dereference in runtime PM
The routines in scsi_pm.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 checking q->dev in block layer before handle runtime PM. Since ses doesn't define any PM callbacks and call blk_pm_runtime_init(), the crash won't occur. This fixes Bugzilla #101371. https://bugzilla.kernel.org/show_bug.cgi?id=101371 More discussion can be found from below link. http://marc.info/?l=linux-scsi&m=144163730531875&w=2 Signed-off-by: Ken Xue <Ken.Xue@amd.com> Acked-by: Alan Stern <stern@rowland.harvard.edu> Cc: Xiangliang Yu <Xiangliang.Yu@amd.com> Cc: James E.J. Bottomley <JBottomley@odin.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Michael Terry <Michael.terry@canonical.com> Cc: stable@vger.kernel.org Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block')
-rw-r--r--block/blk-core.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/block/blk-core.c b/block/blk-core.c
index a0af4043dda2..3636be469fa2 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -3405,6 +3405,9 @@ int blk_pre_runtime_suspend(struct request_queue *q)
3405{ 3405{
3406 int ret = 0; 3406 int ret = 0;
3407 3407
3408 if (!q->dev)
3409 return ret;
3410
3408 spin_lock_irq(q->queue_lock); 3411 spin_lock_irq(q->queue_lock);
3409 if (q->nr_pending) { 3412 if (q->nr_pending) {
3410 ret = -EBUSY; 3413 ret = -EBUSY;
@@ -3432,6 +3435,9 @@ EXPORT_SYMBOL(blk_pre_runtime_suspend);
3432 */ 3435 */
3433void blk_post_runtime_suspend(struct request_queue *q, int err) 3436void blk_post_runtime_suspend(struct request_queue *q, int err)
3434{ 3437{
3438 if (!q->dev)
3439 return;
3440
3435 spin_lock_irq(q->queue_lock); 3441 spin_lock_irq(q->queue_lock);
3436 if (!err) { 3442 if (!err) {
3437 q->rpm_status = RPM_SUSPENDED; 3443 q->rpm_status = RPM_SUSPENDED;
@@ -3456,6 +3462,9 @@ EXPORT_SYMBOL(blk_post_runtime_suspend);
3456 */ 3462 */
3457void blk_pre_runtime_resume(struct request_queue *q) 3463void blk_pre_runtime_resume(struct request_queue *q)
3458{ 3464{
3465 if (!q->dev)
3466 return;
3467
3459 spin_lock_irq(q->queue_lock); 3468 spin_lock_irq(q->queue_lock);
3460 q->rpm_status = RPM_RESUMING; 3469 q->rpm_status = RPM_RESUMING;
3461 spin_unlock_irq(q->queue_lock); 3470 spin_unlock_irq(q->queue_lock);
@@ -3478,6 +3487,9 @@ EXPORT_SYMBOL(blk_pre_runtime_resume);
3478 */ 3487 */
3479void blk_post_runtime_resume(struct request_queue *q, int err) 3488void blk_post_runtime_resume(struct request_queue *q, int err)
3480{ 3489{
3490 if (!q->dev)
3491 return;
3492
3481 spin_lock_irq(q->queue_lock); 3493 spin_lock_irq(q->queue_lock);
3482 if (!err) { 3494 if (!err) {
3483 q->rpm_status = RPM_ACTIVE; 3495 q->rpm_status = RPM_ACTIVE;