From b346f6645ea1f605dd40ada931009e177df9780e Mon Sep 17 00:00:00 2001 From: Sneh Mankad Date: Wed, 18 Nov 2026 16:23:07 +0530 Subject: [PATCH] FROMLIST: soc: qcom: smd-rpm: Avoid out-of-bounds write on empty error message 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") Link: https://lore.kernel.org/all/20261118-smd_rpm_oob_fix-v1-1-e233c4262caf@oss.qualcomm.com/ Signed-off-by: Sneh Mankad --- 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 f2b3e02abdf13..efbb9558b2733 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;