[PATCH] slimbus: messaging: fix out-of-bounds write in slim_msg_response()

From: zhangjiao2

Date: Fri Nov 20 2026 - 03:50:27 EST


From: zhang jiao <zhangjiao2@xxxxxxxxxxxxxxxxxxxx>

slim_msg_response() copies the reply payload into the client receive
buffer using the length reported by the controller, without checking it
against the msg->num_bytes for which the buffer was sized.

The reply length originates from the message received on the bus (the
RL field of the message header) and is therefore controlled by the
remote SLIM device. A buggy or malicious remote, e.g. the firmware
driving the Qualcomm NGD controller, can send a reply longer than the
requested number of bytes and slim_msg_response() then writes past the
end of the client buffer. Client buffers are typically small, for
example the single stack byte used by slim_readb(), so this can corrupt
adjacent stack or heap memory.

Clamp the reply length to msg->num_bytes and report the protocol error
so that the transaction still completes normally (freeing the TID and
dropping the runtime PM vote) without overflowing the receive buffer.

Signed-off-by: zhang jiao <zhangjiao2@xxxxxxxxxxxxxxxxxxxx>
---
drivers/slimbus/messaging.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/slimbus/messaging.c b/drivers/slimbus/messaging.c
index ee127ef42046..b20864b59606 100644
--- a/drivers/slimbus/messaging.c
+++ b/drivers/slimbus/messaging.c
@@ -41,6 +41,13 @@ void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 len)
return;
}

+ if (len > msg->num_bytes) {
+ dev_err(ctrl->dev,
+ "Got response with invalid length:%d for TID:%d, expected:%d\n",
+ len, tid, msg->num_bytes);
+ len = msg->num_bytes;
+ }
+
slim_free_txn_tid(ctrl, txn);
memcpy(msg->rbuf, reply, len);
if (txn->comp)
--
2.33.0