[PATCH 04/10] mailbox: riscv-sbi-mpxy: Validate shmem bounds in message send helpers

From: Lee Jones

Date: Thu Dec 03 2026 - 03:28:30 EST


Neither mpxy_send_message_with_resp() nor
mpxy_send_message_without_resp() verifies that tx_len fits within
mpxy_shmem_size before copying into mpxy->shmem. In addition,
mpxy_send_message_with_resp() checks rx_bytes against max_rx_len but
never verifies that firmware's returned sret.value is non-negative and
within mpxy_shmem_size before copying out of mpxy->shmem.

Reject tx_len > mpxy_shmem_size with -EINVAL in both send helpers, and
reject negative or out-of-bounds sret.value with -EOVERFLOW in
mpxy_send_message_with_resp().

Fixes: bf3022a4eb11 ("mailbox: Add RISC-V SBI message proxy (MPXY) based mailbox driver")
Closes: https://sashiko.dev/#/bug/linux-3c3c0397-a448-41ba-bb19-e7f98ccf265a
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---

Cc: Albert Ou <aou@xxxxxxxxxxxxxxxxx>
Cc: Alexandre Ghiti <alex@xxxxxxxx>
Cc: Anup Patel <apatel@xxxxxxxxxxxxxxxx>
Cc: Jassi Brar <jassisinghbrar@xxxxxxxxx>
Cc: linux-riscv@xxxxxxxxxxxxxxxxxxx
Cc: Palmer Dabbelt <palmer@xxxxxxxxxxx>
Cc: Paul Walmsley <pjw@xxxxxxxxxx>
Cc: Rahul Pathak <rahul@xxxxxxxxxxxxxx>

drivers/mailbox/riscv-sbi-mpxy-mbox.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/mailbox/riscv-sbi-mpxy-mbox.c b/drivers/mailbox/riscv-sbi-mpxy-mbox.c
index 90b1972a42ea..8f0af2e3eb94 100644
--- a/drivers/mailbox/riscv-sbi-mpxy-mbox.c
+++ b/drivers/mailbox/riscv-sbi-mpxy-mbox.c
@@ -249,7 +249,7 @@ static int mpxy_send_message_with_resp(u32 channel_id, u32 msg_id,
unsigned long rx_bytes;
struct sbiret sret;

- if (!tx && tx_len)
+ if ((!tx && tx_len) || tx_len > mpxy_shmem_size)
return -EINVAL;

guard(irqsave)();
@@ -265,6 +265,9 @@ static int mpxy_send_message_with_resp(u32 channel_id, u32 msg_id,
sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_SEND_MSG_WITH_RESP,
channel_id, msg_id, tx_len, 0, 0, 0);
if (rx && !sret.error) {
+ if (sret.value < 0 || (unsigned long)sret.value > mpxy_shmem_size)
+ return -EOVERFLOW;
+
rx_bytes = sret.value;
if (rx_bytes > max_rx_len)
return -ENOSPC;
@@ -283,7 +286,7 @@ static int mpxy_send_message_without_resp(u32 channel_id, u32 msg_id,
struct mpxy_local *mpxy;
struct sbiret sret;

- if (!tx && tx_len)
+ if ((!tx && tx_len) || tx_len > mpxy_shmem_size)
return -EINVAL;

guard(irqsave)();
--
2.56.1.911.g883d8bcb20-goog