All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: leapraid: fix off-by-one in reply frame address validation
@ 2026-11-20  8:30 zhangchujun
  2026-11-20  8:38 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: zhangchujun @ 2026-11-20  8:30 UTC (permalink / raw)
  To: Dongdong Hao, Martin K . Petersen
  Cc: linux-scsi, Kees Cook, James E . J . Bottomley

The reply message buffer spans [rep_msg_dma, rep_msg_dma +
rep_msg_qd * LEAPRAID_REPLY_SIZE).  The sanity check on the reply
frame address returned by the firmware uses a strict "rep > end"
comparison, so a reply address equal to the end of the buffer is
still accepted.  leapraid_get_reply_vaddr() then computes
rep_msg + rep_msg_qd * LEAPRAID_REPLY_SIZE, a pointer one past the
end of the buffer, and the completion path dereferences it, reading
outside the DMA allocation.  The out-of-range address is also
written back to rep_msg_addr[] for firmware reuse, which would
make firmware DMA into memory beyond the reply buffer.

This check is the only guard against an out-of-range reply address
from a misbehaving adapter, so make the upper bound check
inclusive-correct by using >=.

Fixes: 5597088c9e79 ("scsi: leapraid: Add new SCSI driver")
Signed-off-by: zhangchujun <zhangchujun@cmss.chinamobile.com>

diff --git a/drivers/scsi/leapraid/leapraid_func.c b/drivers/scsi/leapraid/leapraid_func.c
index 573bccf1a4ce..c54797e22e74 100644
--- a/drivers/scsi/leapraid/leapraid_func.c
+++ b/drivers/scsi/leapraid/leapraid_func.c
@@ -5667,7 +5667,7 @@ static void leapraid_request_descript_handler(
 		break;
 	case LEAPRAID_RPY_DESC_FLG_ADDRESS_REPLY:
 		rep = le32_to_cpu(rpf->addr_rep.rep_frame_addr);
-		if (rep > (u32)adapter->mem_desc.rep_msg_dma +
+		if (rep >= (u32)adapter->mem_desc.rep_msg_dma +
 			   adapter->adapter_attr.rep_msg_qd *
 			   LEAPRAID_REPLY_SIZE ||
 		    rep < (u32)adapter->mem_desc.rep_msg_dma)
-- 
2.50.1.windows.1




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

end of thread, other threads:[~2026-11-20  8:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20  8:30 [PATCH] scsi: leapraid: fix off-by-one in reply frame address validation zhangchujun
2026-11-20  8:38 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.