75d449a
From 7afe9a8d7dca86a8f35250f21f5f0a62ea2fedf7 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
75d449a
index 3d22fc3..07aec76 100644
3f7b3ae
--- a/drivers/scsi/sd.c
3f7b3ae
+++ b/drivers/scsi/sd.c
75d449a
@@ -2825,7 +2825,7 @@ static inline u32 logical_to_sectors(struct scsi_device *sdev, u32 blocks)
af1af57
 static int sd_revalidate_disk(struct gendisk *disk)
af1af57
 {
af1af57
 	struct scsi_disk *sdkp = scsi_disk(disk);
af1af57
-	struct scsi_device *sdp = sdkp->device;
af1af57
+	struct scsi_device *sdp;
75d449a
 	struct request_queue *q = sdkp->disk->queue;
af1af57
 	unsigned char *buffer;
75d449a
 	unsigned int dev_max, rw_max;
75d449a
@@ -2833,6 +2833,11 @@ static int sd_revalidate_disk(struct gendisk *disk)
af1af57
 	SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp,
af1af57
 				      "sd_revalidate_disk\n"));
af1af57
 
7505efc
+	if (WARN_ONCE((!sdkp), "Invalid scsi_disk from %p\n", disk))
af1af57
+		goto out;
af1af57
+
af1af57
+	sdp = sdkp->device;
af1af57
+
af1af57
 	/*
af1af57
 	 * If the device is offline, don't try and read capacity or any
af1af57
 	 * of the other niceties.
75d449a
-- 
75d449a
2.5.0
75d449a