[PATCH] soc: qcom: smd-rpm: Avoid out-of-bounds write on empty error message
From: Sneh Mankad
Date: Wed Nov 18 2026 - 07:50:31 EST
For an error response the RPM driver copies the error string from IO
memory into a fixed size stack buffer and NUL terminates it at
msgbuf[len - 1].
The copy length is derived from the message length advertised by the
RPM firmware, so a message that carries no payload leaves len at zero
and the NUL termination writes one byte before the buffer.
Treat such a message as an error without inspecting its payload.
Fixes: 936f14cf4e67 ("soc: qcom: Driver for the Qualcomm RPM over SMD")
Signed-off-by: Sneh Mankad <sneh.mankad@xxxxxxxxxxxxxxxx>
---
drivers/soc/qcom/smd-rpm.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/soc/qcom/smd-rpm.c b/drivers/soc/qcom/smd-rpm.c
index 7037d9845d98a2859c9c368e9737e73622b08277..1ab615080ed4b4a00212faaedfc27a8e54bad018 100644
--- a/drivers/soc/qcom/smd-rpm.c
+++ b/drivers/soc/qcom/smd-rpm.c
@@ -174,6 +174,11 @@ static int qcom_smd_rpm_callback(struct rpmsg_device *rpdev,
break;
case RPM_MSG_TYPE_ERR:
len = min_t(u32, ALIGN(msg_length, 4), sizeof(msgbuf));
+ if (!len) {
+ status = -EINVAL;
+ break;
+ }
+
memcpy_fromio(msgbuf, msg->message, len);
msgbuf[len - 1] = 0;
---
base-commit: 20eef29b7c8465ac98d7dd6d6f2ac07a8d8056ca
change-id: 20261118-smd_rpm_oob_fix-124d19996e86
Best regards,
--
Sneh Mankad <sneh.mankad@xxxxxxxxxxxxxxxx>