From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FD08C77B73 for ; Mon, 24 Apr 2023 13:20:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231969AbjDXNUw (ORCPT ); Mon, 24 Apr 2023 09:20:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231956AbjDXNUh (ORCPT ); Mon, 24 Apr 2023 09:20:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C61C4C2B for ; Mon, 24 Apr 2023 06:20:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5AF40621FD for ; Mon, 24 Apr 2023 13:20:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69AC5C433EF; Mon, 24 Apr 2023 13:20:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1682342412; bh=BhX8aFZNlLmTRTF+l3UNPof0eFjwX7T9kgq0qsBfOqo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JUk5nKvF2qrPupiujfbDXH5TNS+0IW0o2gy9pKjRQWQmtdH+5Q7FS+VJsjlzgbVBX e28Xa1GjQ8f5H8acP5Ahyhh38DNLNADFSbQ1w4wTrMVniqzVKNdSnUkD7Uej02BM7x gKyRc3CP2lg2yOcB6VYu9kuYZwpYq/NiauydEh4k= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Damien Le Moal , Benjamin Block , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.15 30/73] scsi: core: Improve scsi_vpd_inquiry() checks Date: Mon, 24 Apr 2023 15:16:44 +0200 Message-Id: <20230424131130.121375183@linuxfoundation.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230424131129.040707961@linuxfoundation.org> References: <20230424131129.040707961@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Damien Le Moal [ Upstream commit f0aa59a33d2ac2267d260fe21eaf92500df8e7b4 ] Some USB-SATA adapters have broken behavior when an unsupported VPD page is probed: Depending on the VPD page number, a 4-byte header with a valid VPD page number but with a 0 length is returned. Currently, scsi_vpd_inquiry() only checks that the page number is valid to determine if the page is valid, which results in receiving only the 4-byte header for the non-existent page. This error manifests itself very often with page 0xb9 for the Concurrent Positioning Ranges detection done by sd_read_cpr(), resulting in the following error message: sd 0:0:0:0: [sda] Invalid Concurrent Positioning Ranges VPD page Prevent such misleading error message by adding a check in scsi_vpd_inquiry() to verify that the page length is not 0. Signed-off-by: Damien Le Moal Link: https://lore.kernel.org/r/20230322022211.116327-1-damien.lemoal@opensource.wdc.com Reviewed-by: Benjamin Block Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/scsi.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 4fc9466d820a7..a499a57150720 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -323,11 +323,18 @@ static int scsi_vpd_inquiry(struct scsi_device *sdev, unsigned char *buffer, if (result) return -EIO; - /* Sanity check that we got the page back that we asked for */ + /* + * Sanity check that we got the page back that we asked for and that + * the page size is not 0. + */ if (buffer[1] != page) return -EIO; - return get_unaligned_be16(&buffer[2]) + 4; + result = get_unaligned_be16(&buffer[2]); + if (!result) + return -EIO; + + return result + 4; } /** -- 2.39.2