From patchwork Fri Mar 17 23:29:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Martin K. Petersen" X-Patchwork-Id: 9631731 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9E54F602D7 for ; Fri, 17 Mar 2017 23:31:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A80F7284FA for ; Fri, 17 Mar 2017 23:31:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9CA5028616; Fri, 17 Mar 2017 23:31:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24B7828543 for ; Fri, 17 Mar 2017 23:31:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751105AbdCQXbr (ORCPT ); Fri, 17 Mar 2017 19:31:47 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:48053 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751098AbdCQXbq (ORCPT ); Fri, 17 Mar 2017 19:31:46 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v2HNTqiF009298 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Mar 2017 23:29:53 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v2HNTpEZ030166 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Mar 2017 23:29:51 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v2HNTnEk006974; Fri, 17 Mar 2017 23:29:50 GMT Received: from ca-mkp.ca.oracle.com (/10.159.214.123) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 17 Mar 2017 16:29:49 -0700 To: Kefeng Wang Cc: "Martin K. Petersen" , Jens Axboe , "James E.J. Bottomley" , , , Douglas Gilbert Subject: Re: [PATCH] scsi: sr: fix oob access in get_capabilities From: "Martin K. Petersen" Organization: Oracle Corporation References: <1488536272-10509-1-git-send-email-wangkefeng.wang@huawei.com> <3f08ece0-531e-6853-d47d-a860e81e55d6@huawei.com> Date: Fri, 17 Mar 2017 19:29:46 -0400 In-Reply-To: <3f08ece0-531e-6853-d47d-a860e81e55d6@huawei.com> (Kefeng Wang's message of "Thu, 16 Mar 2017 13:21:01 +0800") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Kefeng Wang 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! 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);