Skip to content

Commit 9bae076

Browse files
cris-masudeep-holla
authored andcommitted
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: d5141f3 ("firmware: arm_scmi: Add notifications support in transport layer") Signed-off-by: Cristian Marussi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sudeep Holla <[email protected]>
1 parent ad78b81 commit 9bae076

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/firmware/arm_scmi/shmem.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ void shmem_fetch_response(struct scmi_shared_mem __iomem *shmem,
9494
void shmem_fetch_notification(struct scmi_shared_mem __iomem *shmem,
9595
size_t max_len, struct scmi_xfer *xfer)
9696
{
97+
size_t len = ioread32(&shmem->length);
98+
9799
/* 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);
99101

100102
/* Take a copy to the rx buffer.. */
101103
memcpy_fromio(xfer->rx.buf, shmem->msg_payload, xfer->rx.len);

0 commit comments

Comments
 (0)