linuxtorvalds / rpms / kernel

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