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 <[email protected]> --- 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
