39c21e4
From f40cfb38e00a2bd69aaeb1634b548997b8ba4a05 Mon Sep 17 00:00:00 2001
6a91557
From: "kernel-team@fedoraproject.org" <kernel-team@fedoraproject.org>
6a91557
Date: Fri, 10 Feb 2012 14:56:13 -0500
6a91557
Subject: [PATCH] scsi: sd_revalidate_disk prevent NULL ptr deref
6a91557
68d0d67
Bugzilla: 754518
68d0d67
Upstream-status: Fedora mustard (might be worth dropping...)
6a91557
---
6a91557
 drivers/scsi/sd.c | 7 ++++++-
6a91557
 1 file changed, 6 insertions(+), 1 deletion(-)
3f7b3ae
3f7b3ae
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
3f7b3ae
index 2c2041ca4b70..e10812d985af 100644
3f7b3ae
--- a/drivers/scsi/sd.c
3f7b3ae
+++ b/drivers/scsi/sd.c
3f7b3ae
@@ -2749,13 +2749,18 @@ static int sd_try_extended_inquiry(struct scsi_device *sdp)
Josh Boyer af1af57
 static int sd_revalidate_disk(struct gendisk *disk)
Josh Boyer af1af57
 {
Josh Boyer af1af57
 	struct scsi_disk *sdkp = scsi_disk(disk);
Josh Boyer af1af57
-	struct scsi_device *sdp = sdkp->device;
Josh Boyer af1af57
+	struct scsi_device *sdp;
Josh Boyer af1af57
 	unsigned char *buffer;
3f7b3ae
 	unsigned int max_xfer;
Josh Boyer af1af57
 
Josh Boyer af1af57
 	SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp,
Josh Boyer af1af57
 				      "sd_revalidate_disk\n"));
Josh Boyer af1af57
 
Josh Boyer 7505efc
+	if (WARN_ONCE((!sdkp), "Invalid scsi_disk from %p\n", disk))
Josh Boyer af1af57
+		goto out;
Josh Boyer af1af57
+
Josh Boyer af1af57
+	sdp = sdkp->device;
Josh Boyer af1af57
+
Josh Boyer af1af57
 	/*
Josh Boyer af1af57
 	 * If the device is offline, don't try and read capacity or any
Josh Boyer af1af57
 	 * of the other niceties.
6a91557
-- 
6a91557
1.9.3
6a91557