All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Martin K. Petersen" <martin.petersen@oracle.com>
To: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>,
	Jens Axboe <axboe@kernel.dk>,
	"James E.J. Bottomley" <jejb@linux.vnet.ibm.com>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	Douglas Gilbert <dgilbert@interlog.com>
Subject: Re: [PATCH] scsi: sr: fix oob access in get_capabilities
Date: Fri, 17 Mar 2017 19:29:46 -0400	[thread overview]
Message-ID: <yq160j7lbx1.fsf@oracle.com> (raw)
In-Reply-To: <3f08ece0-531e-6853-d47d-a860e81e55d6@huawei.com> (Kefeng Wang's message of "Thu, 16 Mar 2017 13:21:01 +0800")

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

Kefeng,

> root@localhost ~]# sg_modes -p 0x2a /dev/sr0
>     QEMU      QEMU DVD-ROM      0.15   peripheral_type: cd/dvd [0x5]
> Mode parameter header from MODE SENSE(10):
> Invalid block descriptor length=512, ignore
>   Mode data length=36, medium type=0x70, specific param=0x00, longlba=0
>   Block descriptor length=0
>>> MM capabilities and mechanical status (obsolete), page_control: current
>  00     2a 12 00 00 71 60 29 00  02 c2 00 02 02 00 02 c2
>  10     00 00 00 00
> Unexpectedly received extra mode page responses, ignore

That looks pretty broken.

Could you try the following patch?

Thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index f41e6b84a1bd..51a4ce094450 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2485,6 +2485,10 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
 		goto retry;
 	}
 
+	if (data->length > len ||
+	    data->header_length + data->block_descriptor_length > data->length)
+		return 0;
+
 	return result;
 }
 EXPORT_SYMBOL(scsi_mode_sense);

WARNING: multiple messages have this Message-ID (diff)
From: "Martin K. Petersen" <martin.petersen@oracle.com>
To: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>,
	Jens Axboe <axboe@kernel.dk>,
	"James E.J. Bottomley" <jejb@linux.vnet.ibm.com>,
	<linux-scsi@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Douglas Gilbert <dgilbert@interlog.com>
Subject: Re: [PATCH] scsi: sr: fix oob access in get_capabilities
Date: Fri, 17 Mar 2017 19:29:46 -0400	[thread overview]
Message-ID: <yq160j7lbx1.fsf@oracle.com> (raw)
In-Reply-To: <3f08ece0-531e-6853-d47d-a860e81e55d6@huawei.com> (Kefeng Wang's message of "Thu, 16 Mar 2017 13:21:01 +0800")

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

Kefeng,

> root@localhost ~]# sg_modes -p 0x2a /dev/sr0
>     QEMU      QEMU DVD-ROM      0.15   peripheral_type: cd/dvd [0x5]
> Mode parameter header from MODE SENSE(10):
> Invalid block descriptor length=512, ignore
>   Mode data length=36, medium type=0x70, specific param=0x00, longlba=0
>   Block descriptor length=0
>>> MM capabilities and mechanical status (obsolete), page_control: current
>  00     2a 12 00 00 71 60 29 00  02 c2 00 02 02 00 02 c2
>  10     00 00 00 00
> Unexpectedly received extra mode page responses, ignore

That looks pretty broken.

Could you try the following patch?

Thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index f41e6b84a1bd..51a4ce094450 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2485,6 +2485,10 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
 		goto retry;
 	}
 
+	if (data->length > len ||
+	    data->header_length + data->block_descriptor_length > data->length)
+		return 0;
+
 	return result;
 }
 EXPORT_SYMBOL(scsi_mode_sense);

  reply	other threads:[~2017-03-17 23:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-03 10:17 [PATCH] scsi: sr: fix oob access in get_capabilities Kefeng Wang
2017-03-03 10:17 ` Kefeng Wang
2017-03-06  7:26 ` Kefeng Wang
2017-03-06  7:26   ` Kefeng Wang
2017-03-16  0:07 ` Martin K. Petersen
2017-03-16  0:07   ` Martin K. Petersen
2017-03-16  5:21   ` Kefeng Wang
2017-03-16  5:21     ` Kefeng Wang
2017-03-17 23:29     ` Martin K. Petersen [this message]
2017-03-17 23:29       ` Martin K. Petersen
2017-03-20  6:00       ` Kefeng Wang
2017-03-20  6:00         ` Kefeng Wang
2017-03-20 14:29         ` Martin K. Petersen
2017-03-20 14:29           ` Martin K. Petersen
2017-03-21  2:20           ` Kefeng Wang
2017-03-21  2:20             ` Kefeng Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=yq160j7lbx1.fsf@oracle.com \
    --to=martin.petersen@oracle.com \
    --cc=axboe@kernel.dk \
    --cc=dgilbert@interlog.com \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=wangkefeng.wang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.