From: Matt Wang <matt.wang@broadcom.com>
To: vishal.bhakta@broadcom.com,
James.Bottomley@HansenPartnership.com,
martin.petersen@oracle.com, linux-kernel@vger.kernel.org,
linux-scsi@vger.kernel.org,
bcm-kernel-feedback-list@broadcom.com
Cc: Matt Wang <matt.wang@broadcom.com>
Subject: [PATCH] scsi: vmw_pvscsi: clamp on e->dataLen in pvscsi_complete_request
Date: Thu, 22 Oct 2026 15:18:58 +0800 [thread overview]
Message-ID: <20261022071858.8674-1-matt.wang@broadcom.com> (raw)
When calculating the residual bytes, clamp dataLen to the buffer length
before the subtraction. This prevents an overflow if the device sends a
larger value than expected.
Signed-off-by: Matt Wang <matt.wang@broadcom.com>
---
drivers/scsi/vmw_pvscsi.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index 151cac9f9..8e2c1b20f 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -548,6 +548,8 @@ static void pvscsi_complete_request(struct pvscsi_adapter *adapter,
struct completion *abort_cmp;
u32 btstat = e->hostStatus;
u32 sdstat = e->scsiStatus;
+ u64 data_len = e->dataLen;
+ u32 data_trans = 0;
ctx = pvscsi_get_context(adapter, e->context);
cmd = ctx->cmd;
@@ -590,15 +592,16 @@ static void pvscsi_complete_request(struct pvscsi_adapter *adapter,
* returns zero dataLen with non zero data - do not set
* residual count in that case.
*/
- if (e->dataLen && (e->dataLen < scsi_bufflen(cmd)))
- scsi_set_resid(cmd, scsi_bufflen(cmd) - e->dataLen);
+ if (data_len && (data_len < scsi_bufflen(cmd)))
+ scsi_set_resid(cmd, scsi_bufflen(cmd) - data_len);
cmd->result = (DID_OK << 16);
break;
case BTSTAT_DATARUN:
case BTSTAT_DATA_UNDERRUN:
/* Report residual data in underruns */
- scsi_set_resid(cmd, scsi_bufflen(cmd) - e->dataLen);
+ data_trans = min_t(u64, data_len, scsi_bufflen(cmd));
+ scsi_set_resid(cmd, scsi_bufflen(cmd) - data_trans);
cmd->result = (DID_ERROR << 16);
break;
--
2.52.0
reply other threads:[~2026-10-22 7:19 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261022071858.8674-1-matt.wang@broadcom.com \
--to=matt.wang@broadcom.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=vishal.bhakta@broadcom.com \
/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®