[PATCH V2 3/5] accel/amdxdna: Check mailbox message overflow

From: David Zhang

Date: Mon Nov 30 2026 - 17:59:22 EST


The message size is the firmware-supplied total_size plus the header
size, computed in a u32. A total_size near U32_MAX wraps the sum to a
small value that passes the ring buffer bounds checks, and the consumer
is then called with the unchecked total_size.

Reject the message when the addition overflows.

Signed-off-by: David Zhang <yidong.zhang@xxxxxxx>
---
drivers/accel/amdxdna/amdxdna_mailbox.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/accel/amdxdna/amdxdna_mailbox.c b/drivers/accel/amdxdna/amdxdna_mailbox.c
index c4701b2703d7..967f6f1eb764 100644
--- a/drivers/accel/amdxdna/amdxdna_mailbox.c
+++ b/drivers/accel/amdxdna/amdxdna_mailbox.c
@@ -381,9 +381,9 @@ static int mailbox_get_msg(struct mailbox_channel *mb_chann)
MB_WARN_ONCE(mb_chann, "Invalid total size 0x%x", header.total_size);
return -EINVAL;
}
- msg_size = sizeof(header) + header.total_size;

- if (msg_size > ringbuf_size - head || msg_size > tail - head) {
+ if (check_add_overflow(sizeof(header), header.total_size, &msg_size) ||
+ msg_size > ringbuf_size - head || msg_size > tail - head) {
MB_WARN_ONCE(mb_chann, "Invalid message size %d, tail %d, head %d",
msg_size, tail, head);
return -EINVAL;
--
2.34.1