From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Damien Le Moal <damien.lemoal@opensource.wdc.com>,
Benjamin Block <bblock@linux.ibm.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
Sasha Levin <sashal@kernel.org>,
jejb@linux.ibm.com, linux-scsi@vger.kernel.org
Subject: [PATCH AUTOSEL 6.1 06/17] scsi: core: Improve scsi_vpd_inquiry() checks
Date: Thu, 6 Apr 2023 07:32:00 -0400 [thread overview]
Message-ID: <20230406113211.648424-6-sashal@kernel.org> (raw)
In-Reply-To: <20230406113211.648424-1-sashal@kernel.org>
From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
[ 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 <damien.lemoal@opensource.wdc.com>
Link: https://lore.kernel.org/r/20230322022211.116327-1-damien.lemoal@opensource.wdc.com
Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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 24c4c92543599..3cda5d26b66ca 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -314,11 +314,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;
}
static int scsi_get_vpd_size(struct scsi_device *sdev, u8 page)
--
2.39.2
next prev parent reply other threads:[~2023-04-06 11:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-06 11:31 [PATCH AUTOSEL 6.1 01/17] f2fs: Fix f2fs_truncate_partial_nodes ftrace event Sasha Levin
2023-04-06 11:31 ` [PATCH AUTOSEL 6.1 02/17] platform/x86/intel: vsec: Fix a memory leak in intel_vsec_add_aux Sasha Levin
2023-04-06 11:31 ` [PATCH AUTOSEL 6.1 03/17] platform/x86 (gigabyte-wmi): Add support for A320M-S2H V2 Sasha Levin
2023-04-06 11:31 ` [PATCH AUTOSEL 6.1 04/17] selftests: sigaltstack: fix -Wuninitialized Sasha Levin
2023-04-06 11:31 ` [PATCH AUTOSEL 6.1 05/17] scsi: megaraid_sas: Fix fw_crash_buffer_show() Sasha Levin
2023-04-06 11:32 ` Sasha Levin [this message]
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 07/17] net: dsa: b53: mmap: add phy ops Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 08/17] platform/x86: gigabyte-wmi: add support for B650 AORUS ELITE AX Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 09/17] s390/ptrace: fix PTRACE_GET_LAST_BREAK error handling Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 10/17] nvme-pci: mark Lexar NM760 as IGNORE_DEV_SUBNQN Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 11/17] drm: buddy_allocator: Fix buddy allocator init on 32-bit systems Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 12/17] drm: test: Fix 32-bit issue in drm_buddy_test Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 13/17] nvme-tcp: fix a possible UAF when failing to allocate an io queue Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 14/17] xen/netback: use same error messages for same errors Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 15/17] platform/x86: gigabyte-wmi: add support for X570S AORUS ELITE Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 16/17] platform/x86: asus-nb-wmi: Add quirk_asus_tablet_mode to other ROG Flow X13 models Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 17/17] mtd: spi-nor: fix memory leak when using debugfs_lookup() Sasha Levin
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=20230406113211.648424-6-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=bblock@linux.ibm.com \
--cc=damien.lemoal@opensource.wdc.com \
--cc=jejb@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=stable@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox