Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1604622

Re: [PATCH] scsi: sr: fix oob access in get_capabilities

From "Martin K. Petersen" <martin.petersen@oracle.com>
Newsgroups linux.kernel
Subject Re: [PATCH] scsi: sr: fix oob access in get_capabilities
Date 2017-03-20 15:30 +0100
Message-ID <tn6tP-5Wi-5@gated-at.bofh.it> (permalink)
References <tgSDg-8hC-11@gated-at.bofh.it> <tlr9o-6R3-9@gated-at.bofh.it> <tlw93-1WG-13@gated-at.bofh.it> <tmaSR-6Db-15@gated-at.bofh.it> <tmYFY-yg-11@gated-at.bofh.it>
Organization Oracle Corporation

Show all headers | View raw


Kefeng Wang <wangkefeng.wang@huawei.com> writes:

Kefeng,

> The issue still exists, the patch return zero in scsi_mode_sense(), but zero means
> SAM_STAT_GOOD in scsi_status_is_good(), so n will be still bigger than 512;

OK, I checked the other users of scsi_mode_sense(). So let's keep this
fix local to sr.c for now.

How about the following?


scsi: sr: Sanity check returned mode data
    
Kefeng Wang discovered that old versions of the QEMU CD driver would
return mangled mode data causing us to walk off the end of the buffer in
an attempt to parse it. Sanity check the returned mode sense data.
    
Cc: <stable@vger.kernel.org>
Reported-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 0b29b9329b1c..a8f630213a1a 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -836,6 +836,7 @@ static void get_capabilities(struct scsi_cd *cd)
 	unsigned char *buffer;
 	struct scsi_mode_data data;
 	struct scsi_sense_hdr sshdr;
+	unsigned int ms_len = 128;
 	int rc, n;
 
 	static const char *loadmech[] =
@@ -862,10 +863,11 @@ static void get_capabilities(struct scsi_cd *cd)
 	scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr);
 
 	/* ask for mode page 0x2a */
-	rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128,
+	rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, ms_len,
 			     SR_TIMEOUT, 3, &data, NULL);
 
-	if (!scsi_status_is_good(rc)) {
+	if (!scsi_status_is_good(rc) || data.length > ms_len ||
+	    data.header_length + data.block_descriptor_length > data.length) {
 		/* failed, drive doesn't have capabilities mode page */
 		cd->cdi.speed = 1;
 		cd->cdi.mask |= (CDC_CD_R | CDC_CD_RW | CDC_DVD_R |

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH] scsi: sr: fix oob access in get_capabilities "Martin K. Petersen" <martin.petersen@oracle.com> - 2017-03-16 01:10 +0100
  Re: [PATCH] scsi: sr: fix oob access in get_capabilities Kefeng Wang <wangkefeng.wang@huawei.com> - 2017-03-16 06:30 +0100
    Re: [PATCH] scsi: sr: fix oob access in get_capabilities "Martin K. Petersen" <martin.petersen@oracle.com> - 2017-03-18 02:00 +0100
      Re: [PATCH] scsi: sr: fix oob access in get_capabilities Kefeng Wang <wangkefeng.wang@huawei.com> - 2017-03-20 07:10 +0100
        Re: [PATCH] scsi: sr: fix oob access in get_capabilities "Martin K. Petersen" <martin.petersen@oracle.com> - 2017-03-20 15:30 +0100
          Re: [PATCH] scsi: sr: fix oob access in get_capabilities Kefeng Wang <wangkefeng.wang@huawei.com> - 2017-03-21 03:40 +0100

csiph-web