b23496
From 7afe9a8d7dca86a8f35250f21f5f0a62ea2fedf7 Mon Sep 17 00:00:00 2001
6a9155
From: "kernel-team@fedoraproject.org" <kernel-team@fedoraproject.org>
6a9155
Date: Fri, 10 Feb 2012 14:56:13 -0500
6a9155
Subject: [PATCH] scsi: sd_revalidate_disk prevent NULL ptr deref
6a9155
68d0d6
Bugzilla: 754518
68d0d6
Upstream-status: Fedora mustard (might be worth dropping...)
6a9155
---
6a9155
 drivers/scsi/sd.c | 7 ++++++-
6a9155
 1 file changed, 6 insertions(+), 1 deletion(-)
3f7b3a
3f7b3a
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
b23496
index 3d22fc3..07aec76 100644
3f7b3a
--- a/drivers/scsi/sd.c
3f7b3a
+++ b/drivers/scsi/sd.c
b23496
@@ -2825,7 +2825,7 @@ static inline u32 logical_to_sectors(struct scsi_device *sdev, u32 blocks)
Josh Boyer af1af5
 static int sd_revalidate_disk(struct gendisk *disk)
Josh Boyer af1af5
 {
Josh Boyer af1af5
 	struct scsi_disk *sdkp = scsi_disk(disk);
Josh Boyer af1af5
-	struct scsi_device *sdp = sdkp->device;
Josh Boyer af1af5
+	struct scsi_device *sdp;
b23496
 	struct request_queue *q = sdkp->disk->queue;
962ea4
 	sector_t old_capacity = sdkp->capacity;
Josh Boyer af1af5
 	unsigned char *buffer;
b23496
@@ -2833,6 +2833,11 @@ static int sd_revalidate_disk(struct gendisk *disk)
Josh Boyer af1af5
 	SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp,
Josh Boyer af1af5
 				      "sd_revalidate_disk\n"));
Josh Boyer af1af5
 
Josh Boyer 7505ef
+	if (WARN_ONCE((!sdkp), "Invalid scsi_disk from %p\n", disk))
Josh Boyer af1af5
+		goto out;
Josh Boyer af1af5
+
Josh Boyer af1af5
+	sdp = sdkp->device;
Josh Boyer af1af5
+
Josh Boyer af1af5
 	/*
Josh Boyer af1af5
 	 * If the device is offline, don't try and read capacity or any
Josh Boyer af1af5
 	 * of the other niceties.
b23496
-- 
b23496
2.5.0
b23496