[PATCH] mailbox: riscv-sbi-mpxy: validate RPMI event records

Pengpeng Hou pengpeng at iscas.ac.cn
Mon Jul 6 02:21:08 PDT 2026


mpxy_mbox_peek_rpmi_data() walks notification event records
embedded in the RPMI notification buffer.

Iterate only while a full event header remains, and stop if the declared
payload length extends past the notification buffer.

Signed-off-by: Pengpeng Hou <pengpeng at iscas.ac.cn>
---
 drivers/mailbox/riscv-sbi-mpxy-mbox.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/mailbox/riscv-sbi-mpxy-mbox.c b/drivers/mailbox/riscv-sbi-mpxy-mbox.c
index 7c9c006b7244..db380f26872d 100644
--- a/drivers/mailbox/riscv-sbi-mpxy-mbox.c
+++ b/drivers/mailbox/riscv-sbi-mpxy-mbox.c
@@ -480,11 +480,14 @@ static void mpxy_mbox_peek_rpmi_data(struct mbox_chan *chan,
 	struct rpmi_mbox_message msg;
 	unsigned long pos = 0;
 
-	while (pos < events_data_len && (events_data_len - pos) <= sizeof(*event)) {
+	while (events_data_len - pos >= sizeof(*event)) {
 		event = (struct rpmi_notification_event *)(notif->events_data + pos);
 
 		msg.type = RPMI_MBOX_MSG_TYPE_NOTIFICATION_EVENT;
 		msg.notif.event_datalen = le16_to_cpu(event->event_datalen);
+		if (msg.notif.event_datalen >
+		    events_data_len - pos - sizeof(*event))
+			break;
 		msg.notif.event_id = event->event_id;
 		msg.notif.event_data = event->event_data;
 		msg.error = 0;
-- 
2.43.0




More information about the linux-riscv mailing list