diff options
author | Cristian Marussi <cristian.marussi@arm.com> | 2022-12-22 21:38:21 +0300 |
---|---|---|
committer | Sudeep Holla <sudeep.holla@arm.com> | 2023-01-03 19:50:30 +0300 |
commit | 9bae076cd4e3e3c3dc185cae829d80b2dddec86e (patch) | |
tree | 633bd55153a6ce693c11d69d7dcb93b9518103cf | |
parent | ad78b81a1077f7d956952cd8bdfe1e61504e3eb8 (diff) | |
download | linux-9bae076cd4e3e3c3dc185cae829d80b2dddec86e.tar.xz |
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>
-rw-r--r-- | drivers/firmware/arm_scmi/shmem.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/firmware/arm_scmi/shmem.c b/drivers/firmware/arm_scmi/shmem.c index 135f8718000f..87b4f4d35f06 100644 --- a/drivers/firmware/arm_scmi/shmem.c +++ b/drivers/firmware/arm_scmi/shmem.c @@ -94,8 +94,10 @@ void shmem_fetch_response(struct scmi_shared_mem __iomem *shmem, void shmem_fetch_notification(struct scmi_shared_mem __iomem *shmem, size_t max_len, struct scmi_xfer *xfer) { + size_t len = ioread32(&shmem->length); + /* Skip only the length of header in shmem area i.e 4 bytes */ - xfer->rx.len = min_t(size_t, max_len, ioread32(&shmem->length) - 4); + xfer->rx.len = min_t(size_t, max_len, len > 4 ? len - 4 : 0); /* Take a copy to the rx buffer.. */ memcpy_fromio(xfer->rx.buf, shmem->msg_payload, xfer->rx.len); |