mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] slimbus: messaging: fix out-of-bounds write in slim_msg_response()
@ 2026-11-20  8:50 zhangjiao2
  2026-11-24 21:43 ` Srinivas Kandagatla
  0 siblings, 1 reply; 2+ messages in thread
From: zhangjiao2 @ 2026-11-20  8:50 UTC (permalink / raw)
  To: gregkh; +Cc: srini, zhouzongmin, linux-kernel, trivial, zhang jiao

From: zhang jiao <zhangjiao2@cmss.chinamobile.com>

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@cmss.chinamobile.com>
---
 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




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] slimbus: messaging: fix out-of-bounds write in slim_msg_response()
  2026-11-20  8:50 [PATCH] slimbus: messaging: fix out-of-bounds write in slim_msg_response() zhangjiao2
@ 2026-11-24 21:43 ` Srinivas Kandagatla
  0 siblings, 0 replies; 2+ messages in thread
From: Srinivas Kandagatla @ 2026-11-24 21:43 UTC (permalink / raw)
  To: zhangjiao2, gregkh; +Cc: srini, zhouzongmin, linux-kernel, trivial



On 11/20/26 8:50 AM, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> 
> 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
Do you have a hardware that does show this behavior? or is this
hypothetical?

> 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.
> 
You said its a fix but I dont see any fixes tag or Stable.

--srini
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> ---
>  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)


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-24 21:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20  8:50 [PATCH] slimbus: messaging: fix out-of-bounds write in slim_msg_response() zhangjiao2
2026-11-24 21:43 ` Srinivas Kandagatla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®