Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

firmware: arm_scmi: Harden shared memory access in fetch_notification

A misbheaving SCMI platform firmware could reply with out-of-spec
notifications, shorter than the mimimum size comprising a header.

Fixes: d5141f37c42e ("firmware: arm_scmi: Add notifications support in transport layer")
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Link: https://lore.kernel.org/r/20221222183823.518856-4-cristian.marussi@arm.com
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>

authored by

Cristian Marussi and committed by
Sudeep Holla
9bae076c ad78b81a

+3 -1
+3 -1
drivers/firmware/arm_scmi/shmem.c
··· 94 94 void shmem_fetch_notification(struct scmi_shared_mem __iomem *shmem, 95 95 size_t max_len, struct scmi_xfer *xfer) 96 96 { 97 + size_t len = ioread32(&shmem->length); 98 + 97 99 /* Skip only the length of header in shmem area i.e 4 bytes */ 98 - xfer->rx.len = min_t(size_t, max_len, ioread32(&shmem->length) - 4); 100 + xfer->rx.len = min_t(size_t, max_len, len > 4 ? len - 4 : 0); 99 101 100 102 /* Take a copy to the rx buffer.. */ 101 103 memcpy_fromio(xfer->rx.buf, shmem->msg_payload, xfer->rx.len);