summaryrefslogtreecommitdiffstats
path: root/scsi-sd_revalidate_disk-prevent-NULL-ptr-deref.patch
blob: 350705249548c17d3a237d1508dfd1f2b3df1657 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Bugzilla: 754518
Upstream-status: Fedora mustard (might be worth dropping...)


diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 2c2041ca4b70..e10812d985af 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2749,13 +2749,18 @@ static int sd_try_extended_inquiry(struct scsi_device *sdp)
 static int sd_revalidate_disk(struct gendisk *disk)
 {
 	struct scsi_disk *sdkp = scsi_disk(disk);
-	struct scsi_device *sdp = sdkp->device;
+	struct scsi_device *sdp;
 	unsigned char *buffer;
 	unsigned int max_xfer;
 
 	SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp,
 				      "sd_revalidate_disk\n"));
 
+	if (WARN_ONCE((!sdkp), "Invalid scsi_disk from %p\n", disk))
+		goto out;
+
+	sdp = sdkp->device;
+
 	/*
 	 * If the device is offline, don't try and read capacity or any
 	 * of the other niceties.