Skip to contentSkip to conversation

firmware: arm_scmi: imx: Check syslog reply length against word count

PATCH In review Zijie Zhao 2 participants 2 messages Dec 3 – Dec 4

Subsystems (3)
lore
Share & tools
lore

Zijie Zhao

author
#0 lore raw

PATCH 1/1 firmware: arm_scmi: imx: Check syslog reply length against word count

iter_misc_syslog_update_state() takes the number of returned words from the SYSLOG_GET reply and the iterator then copies that many words from the RX buffer without checking the reply length. A reply announcing more words than it carries copies stale data, or memory past the RX buffer, into the syslog dumped to debugfs. Reject such replies.

Found by a static analysis tool.

Fixes 4fa62e80c7db ("firmware: arm_scmi: imx: Support getting syslog of MISC protocol")

---
The patch is against mainline. In linux-next the file has moved to drivers/firmware/arm/scmi/vendors/imx/ by 49c49ca0c4d0 ("firmware: arm:
Group interface drivers under arm/"); the changed function is identical there.

The fix and the changelog were drafted with AI assistance (Claude Code, with a second review by OpenAI Codex), then reviewed by the submitter.

Testing:
- Compile-tested on x86_64 (allmodconfig, W=1):
drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.o; no new warnings.
- checkpatch.pl --strict: no errors or warnings.

---
 drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.c +4 -0
index ed7499d72f19..ad338fc23f72 100644
@@ -446,6 +446,10 @@ static int iter_misc_syslog_update_state(struct scmi_iterator_state *st,
 
 	st->num_returned = RETURNED(r->numlogflags);
 	st->num_remaining = REMAINING(r->numlogflags);
+
+	if (st->rx_len < sizeof(*r) + sizeof(r->syslog[0]) * st->num_returned)
+		return -EINVAL;
+
 	*p->size = st->desc_index + st->num_returned;
 
 	return 0;

---
base-commit: 007722b8211f7b34fdf21b1e6a9c32497633ea29
change-id: 20261203-kbug-l1808-9567ba03e265

Best regards,

Signature · 1 line
Zijie Zhao <[email protected]>
Reviewed-by Peng Fan on v1 1/1
#1 lore raw
Quoted 33 lines · On Thu, 03 Dec 2026 17:29:25 -0600 Zijie Zhao via B4 Relay…

From: Zijie Zhao <[email protected]>

iter_misc_syslog_update_state() takes the number of returned words from the SYSLOG_GET reply and the iterator then copies that many words from the RX buffer without checking the reply length. A reply announcing more words than it carries copies stale data, or memory past the RX buffer, into the syslog dumped to debugfs. Reject such replies.

Found by a static analysis tool.

Fixes 4fa62e80c7db ("firmware: arm_scmi: imx: Support getting syslog of MISC protocol")

---
The patch is against mainline. In linux-next the file has moved to drivers/firmware/arm/scmi/vendors/imx/ by 49c49ca0c4d0 ("firmware: arm:
Group interface drivers under arm/"); the changed function is identical there.

The fix and the changelog were drafted with AI assistance (Claude Code, with a second review by OpenAI Codex), then reviewed by the submitter.

Testing:
- Compile-tested on x86_64 (allmodconfig, W=1):
drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.o; no new warnings.
- checkpatch.pl --strict: no errors or warnings.

---
 drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.c +0 -0
index ed7499d72f19..ad338fc23f72 100644

drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.c static int iter_misc_syslog_update_state(struct scmi_iterator_state *st, · line 453

Quoted 8 lines
drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.c +4 -0
@@ -446,6 +446,10 @@ static int iter_misc_syslog_update_state(struct scmi_iterator_state *st,
 
 	st->num_returned = RETURNED(r->numlogflags);
 	st->num_remaining = REMAINING(r->numlogflags);
+
+	if (st->rx_len < sizeof(*r) + sizeof(r->syslog[0]) * st->num_returned)
+		return -EINVAL;
+
 	*p->size = st->desc_index + st->num_returned;

Fine as defensive programming logic.