* [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* Re: [PATCH] scsi: leapraid: fix off-by-one in reply frame address validation
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
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-20 8:38 UTC (permalink / raw)
To: zhangchujun; +Cc: linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] scsi: leapraid: bad reply bounds in
leapraid_request_descript_handler()
--
commit b7ba75a759881f8671081c0b0994098d97d3921e
Author: zhangchujun <zhangchujun@cmss.chinamobile.com>
scsi: leapraid: fix off-by-one in reply frame address validation
This commit changes the upper bound check on the firmware reply frame
DMA address in leapraid_request_descript_handler() from > to >=.
> diff --git a/drivers/scsi/leapraid/leapraid_func.c b/drivers/scsi/leapraid/leapraid_func.c
> index 573bccf1a4cea..c54797e22e744 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)
[Severity: Medium]
Can rep still cause an out-of-bounds read and DMA write past
adapter->mem_desc.rep_msg if the firmware returns an address within the
last LEAPRAID_REPLY_SIZE - 1 bytes of the buffer or at an unaligned
offset?
Each reply frame is LEAPRAID_REPLY_SIZE (128) bytes, and
leapraid_init_rep_msg_addr() populates rep_msg_addr[] with addresses at
multiples of LEAPRAID_REPLY_SIZE up to rep_msg_dma + (rep_msg_qd - 1) *
LEAPRAID_REPLY_SIZE. An address in the trailing 127 bytes still passes
this check, causing completion handlers such as
leapraid_driver_cmds_done() to read up to LEAPRAID_REPLY_SIZE bytes past
the end of rep_msg and reposting rep to rep_msg_addr[] for firmware DMA.
Should this also verify that (rep - (u32)adapter->mem_desc.rep_msg_dma)
is a multiple of LEAPRAID_REPLY_SIZE?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120083000.1961-1-zhangchujun@cmss.chinamobile.com?part=1
^ permalink raw reply [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.