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
35eff4
index 3b2fcb4fada0..f0f9e8574303 100644
3f7b3a
--- a/drivers/scsi/sd.c
3f7b3a
+++ b/drivers/scsi/sd.c
264ac3
@@ -2717,13 +2717,18 @@ static int sd_try_extended_inquiry(struct scsi_device *sdp)
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;
Josh Boyer af1af5
 	unsigned char *buffer;
3f7b3a
 	unsigned int max_xfer;
Josh Boyer af1af5
 
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.