Skip to content

Commit ad78b81

Browse files
cris-masudeep-holla
authored andcommitted
firmware: arm_scmi: Harden shared memory access in fetch_response
A misbheaving SCMI platform firmware could reply with out-of-spec messages, shorter than the mimimum size comprising a header and a status field. Harden shmem_fetch_response to properly truncate such a bad messages. Fixes: 5c8a47a ("firmware: arm_scmi: Make scmi core independent of the transport type") Signed-off-by: Cristian Marussi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sudeep Holla <[email protected]>
1 parent f6ca505 commit ad78b81

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/firmware/arm_scmi/shmem.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ u32 shmem_read_header(struct scmi_shared_mem __iomem *shmem)
8181
void shmem_fetch_response(struct scmi_shared_mem __iomem *shmem,
8282
struct scmi_xfer *xfer)
8383
{
84+
size_t len = ioread32(&shmem->length);
85+
8486
xfer->hdr.status = ioread32(shmem->msg_payload);
8587
/* Skip the length of header and status in shmem area i.e 8 bytes */
86-
xfer->rx.len = min_t(size_t, xfer->rx.len,
87-
ioread32(&shmem->length) - 8);
88+
xfer->rx.len = min_t(size_t, xfer->rx.len, len > 8 ? len - 8 : 0);
8889

8990
/* Take a copy to the rx buffer.. */
9091
memcpy_fromio(xfer->rx.buf, shmem->msg_payload + 4, xfer->rx.len);

0 commit comments

Comments
 (0)