From: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
To: "Martin K . Petersen" <mkp@kernel.org>,
"James E . J . Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, yhlee@isslab.korea.ac.kr
Subject: [PATCH v6 5/5] scsi: mvumi: validate the response frame tag before using it
Date: Thu, 15 Oct 2026 01:24:13 +0900 [thread overview]
Message-ID: <20261014162413.3649841-6-yhlee@isslab.korea.ac.kr> (raw)
In-Reply-To: <20261014162413.3649841-1-yhlee@isslab.korea.ac.kr>
mvumi_handle_clob() indexes mhba->tag_cmd[] with the tag of a response
frame the firmware DMAs into the outbound list. The array holds
tag_pool.size entries, and the only check on that tag runs earlier, in
mvumi_receive_ob_list_entry() and mvumi_check_ob_frame(), against the frame
still sitting in the outbound list. mvumi_receive_ob_list_entry() then
copies the frame into an ob_data buffer and mvumi_handle_clob() reads the
tag out of that copy, so the value that is checked and the value that is
used are two separate fetches of firmware-writable memory. A firmware that
changes the tag after the check reaches tag_cmd[] with any u16, reads a
pointer past the array and dereferences it, writes NULL past the array and
pushes the tag onto the free stack for a later command to pick up. The
check is also off by one: tag_cmd[] and tag_pool.stack[] both hold
tag_pool.size entries, so a tag equal to tag_pool.size passes a > test and
lands one entry past both.
Check the tag that mvumi_handle_clob() actually uses, against the size of
the array it indexes, and check the command it finds for NULL before
dereferencing it: with two fetches the earlier NULL check no longer says
anything about this one. Make the two existing bounds checks >= so a tag
equal to the entry count is rejected there too, and read the tag into a
local in mvumi_receive_ob_list_entry() as well, so the check there and the
accesses beside it see one value instead of three fetches. Use READ_ONCE()
for the tag and request_id both functions take out of the outbound list, so
the single fetch is guaranteed rather than left to the compiler.
Fixes: f0c568a478f0 ("[SCSI] mvumi: Add Marvell UMI driver")
Cc: stable@vger.kernel.org
Signed-off-by: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
---
drivers/scsi/mvumi.c | 38 ++++++++++++++++++++++++++++----------
1 file changed, 28 insertions(+), 10 deletions(-)
diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 2871b4c96f1c8..85624efcc1725 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -466,9 +466,9 @@ static char mvumi_check_ob_frame(struct mvumi_hba *mhba,
udelay(1);
p_outb_frame = mhba->ob_list + cur_obf * mhba->ob_max_size;
- request_id = p_outb_frame->request_id;
- tag = p_outb_frame->tag;
- if (tag > mhba->tag_pool.size) {
+ request_id = READ_ONCE(p_outb_frame->request_id);
+ tag = READ_ONCE(p_outb_frame->tag);
+ if (tag >= mhba->tag_pool.size) {
dev_err(&mhba->pdev->dev, "ob frame data error\n");
return -1;
}
@@ -530,6 +530,7 @@ static void mvumi_receive_ob_list_entry(struct mvumi_hba *mhba)
struct mvumi_ob_data *ob_data;
struct mvumi_rsp_frame *p_outb_frame;
struct mvumi_hw_regs *regs = mhba->regs;
+ unsigned short tag;
if (mhba->instancet->check_ob_list(mhba, &cur_obf, &assign_obf_end))
return;
@@ -546,10 +547,11 @@ static void mvumi_receive_ob_list_entry(struct mvumi_hba *mhba)
/* Copy pointer may point to entry in outbound list
* before entry has valid data
*/
- if (unlikely(p_outb_frame->tag > mhba->tag_pool.size ||
- mhba->tag_cmd[p_outb_frame->tag] == NULL ||
- p_outb_frame->request_id !=
- mhba->tag_cmd[p_outb_frame->tag]->request_id))
+ tag = READ_ONCE(p_outb_frame->tag);
+ if (unlikely(tag >= mhba->tag_pool.size ||
+ !mhba->tag_cmd[tag] ||
+ mhba->tag_cmd[tag]->request_id !=
+ READ_ONCE(p_outb_frame->request_id)))
if (mvumi_check_ob_frame(mhba, cur_obf, p_outb_frame))
continue;
@@ -1878,6 +1880,7 @@ static void mvumi_handle_clob(struct mvumi_hba *mhba)
struct mvumi_rsp_frame *ob_frame;
struct mvumi_cmd *cmd;
struct mvumi_ob_data *pool;
+ unsigned short tag;
while (!list_empty(&mhba->free_ob_list)) {
pool = list_first_entry(&mhba->free_ob_list,
@@ -1886,11 +1889,26 @@ static void mvumi_handle_clob(struct mvumi_hba *mhba)
list_add_tail(&pool->list, &mhba->ob_data_list);
ob_frame = (struct mvumi_rsp_frame *) &pool->data[0];
- cmd = mhba->tag_cmd[ob_frame->tag];
+ /*
+ * The tag was checked against the frame in the outbound list.
+ * This is the copy, so check the value that is used.
+ */
+ tag = ob_frame->tag;
+ if (tag >= mhba->tag_pool.size) {
+ dev_err(&mhba->pdev->dev,
+ "ob frame tag[0x%x] out of range\n", tag);
+ continue;
+ }
+ cmd = mhba->tag_cmd[tag];
+ if (!cmd) {
+ dev_err(&mhba->pdev->dev,
+ "ob frame tag[0x%x] with no command\n", tag);
+ continue;
+ }
atomic_dec(&mhba->fw_outstanding);
- mhba->tag_cmd[ob_frame->tag] = NULL;
- tag_release_one(mhba, &mhba->tag_pool, ob_frame->tag);
+ mhba->tag_cmd[tag] = NULL;
+ tag_release_one(mhba, &mhba->tag_pool, tag);
if (cmd->scmd)
mvumi_complete_cmd(mhba, cmd, ob_frame);
else
--
2.43.0
prev parent reply other threads:[~2026-10-14 16:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 16:24 [PATCH v6 0/5] scsi: mvumi: bound the values the firmware supplies Yehyeong Lee
2026-10-14 16:24 ` [PATCH v6 1/5] scsi: mvumi: bound the per-event parameter and sense dumps Yehyeong Lee
2026-10-14 16:24 ` [PATCH v6 2/5] scsi: mvumi: reject an out-of-range handshake frame length Yehyeong Lee
2026-10-14 16:24 ` [PATCH v6 3/5] scsi: mvumi: bound the hotplug event bitmap Yehyeong Lee
2026-10-14 16:24 ` [PATCH v6 4/5] scsi: mvumi: reject handshake sizes that overflow the list allocations Yehyeong Lee
2026-10-14 16:24 ` Yehyeong Lee [this message]
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=20261014162413.3649841-6-yhlee@isslab.korea.ac.kr \
--to=yhlee@isslab.korea.ac.kr \
--cc=James.Bottomley@HansenPartnership.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--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
all inboxes | Powered by JetHome®