Linux SCSI subsystem development
 help / color / mirror / Atom feed
* scsi: vmw_pvscsi: add boundary check for cmd_map access.
@ 2026-09-29 23:14 Matt Wang
  2026-11-04  3:33 ` Martin K. Petersen
  0 siblings, 1 reply; 2+ messages in thread
From: Matt Wang @ 2026-09-29 23:14 UTC (permalink / raw)
  To: vishal.bhakta, bcm-kernel-feedback-list, linux-scsi; +Cc: Matt Wang

The context value provided by the device in a completion is used to
index into cmd_map to find the command that was completed. To prevent
out of bounds access or completion of an inactive context, check that
the context value is in-bounds and that it maps to an active context.

Signed-off-by: Matt Wang <matt.wang@broadcom.com>
---
 drivers/scsi/vmw_pvscsi.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index 151cac9f9..49d1950a7 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -201,6 +201,9 @@ static u64 pvscsi_map_context(const struct pvscsi_adapter *adapter,
 static struct pvscsi_ctx *
 pvscsi_get_context(const struct pvscsi_adapter *adapter, u64 context)
 {
+	if (unlikely(context == 0 || context > adapter->req_depth)) {
+		return NULL;
+	}
 	return &adapter->cmd_map[context - 1];
 }
 
@@ -550,6 +553,11 @@ static void pvscsi_complete_request(struct pvscsi_adapter *adapter,
 	u32 sdstat = e->scsiStatus;
 
 	ctx = pvscsi_get_context(adapter, e->context);
+	if (ctx == NULL || ctx->cmd == NULL) {
+		dev_err_ratelimited(&adapter->dev->dev,
+				    "Can not find mapping for context %llu", e->context);
+		return;
+	}
 	cmd = ctx->cmd;
 	abort_cmp = ctx->abort_cmp;
 	pvscsi_unmap_buffers(adapter, ctx);
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: scsi: vmw_pvscsi: add boundary check for cmd_map access.
  2026-09-29 23:14 scsi: vmw_pvscsi: add boundary check for cmd_map access Matt Wang
@ 2026-11-04  3:33 ` Martin K. Petersen
  0 siblings, 0 replies; 2+ messages in thread
From: Martin K. Petersen @ 2026-11-04  3:33 UTC (permalink / raw)
  To: Matt Wang; +Cc: vishal.bhakta, bcm-kernel-feedback-list, linux-scsi


Matt,

> The context value provided by the device in a completion is used to
> index into cmd_map to find the command that was completed. To prevent
> out of bounds access or completion of an inactive context, check that
> the context value is in-bounds and that it maps to an active context.

Applied to 7.5/scsi-staging, thanks!

-- 
Martin K. Petersen

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-04  3:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-29 23:14 scsi: vmw_pvscsi: add boundary check for cmd_map access Matt Wang
2026-11-04  3:33 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox