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 5.4 5/9] scsi: core: Improve scsi_vpd_inquiry() checks
Date: Thu, 6 Apr 2023 07:33:33 -0400 [thread overview]
Message-ID: <20230406113337.648916-5-sashal@kernel.org> (raw)
In-Reply-To: <20230406113337.648916-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 1ce3f90f782fd..2921256b59a0e 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -331,11 +331,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
next prev parent reply other threads:[~2023-04-06 11:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-06 11:33 [PATCH AUTOSEL 5.4 1/9] f2fs: Fix f2fs_truncate_partial_nodes ftrace event Sasha Levin
2023-04-06 11:33 ` [PATCH AUTOSEL 5.4 2/9] Input: i8042 - add quirk for Fujitsu Lifebook A574/H Sasha Levin
2023-04-06 11:33 ` [PATCH AUTOSEL 5.4 3/9] selftests: sigaltstack: fix -Wuninitialized Sasha Levin
2023-04-06 11:33 ` [PATCH AUTOSEL 5.4 4/9] scsi: megaraid_sas: Fix fw_crash_buffer_show() Sasha Levin
2023-04-06 11:33 ` Sasha Levin [this message]
2023-04-06 11:33 ` [PATCH AUTOSEL 5.4 6/9] net: dsa: b53: mmap: add phy ops Sasha Levin
2023-04-06 11:33 ` [PATCH AUTOSEL 5.4 7/9] s390/ptrace: fix PTRACE_GET_LAST_BREAK error handling Sasha Levin
2023-04-06 11:33 ` [PATCH AUTOSEL 5.4 8/9] nvme-tcp: fix a possible UAF when failing to allocate an io queue Sasha Levin
2023-04-06 11:33 ` [PATCH AUTOSEL 5.4 9/9] xen/netback: use same error messages for same errors 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=20230406113337.648916-5-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