提交 5dad1c49 编写于 作者: C Cristian Marussi 提交者: sanglipeng

firmware: arm_scmi: Harden shared memory access in fetch_notification

stable inclusion
from stable-v5.10.166
commit 6813d8ba7dac2de37670e04cbe25dd7071d612fd
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I7TH9O

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=6813d8ba7dac2de37670e04cbe25dd7071d612fd

--------------------------------

[ Upstream commit 9bae076c ]

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

Fixes: d5141f37 ("firmware: arm_scmi: Add notifications support in transport layer")
Signed-off-by: NCristian Marussi <cristian.marussi@arm.com>
Link: https://lore.kernel.org/r/20221222183823.518856-4-cristian.marussi@arm.comSigned-off-by: NSudeep Holla <sudeep.holla@arm.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: Nsanglipeng <sanglipeng1@jd.com>
上级 df0c5a92
...@@ -71,8 +71,10 @@ void shmem_fetch_response(struct scmi_shared_mem __iomem *shmem, ...@@ -71,8 +71,10 @@ void shmem_fetch_response(struct scmi_shared_mem __iomem *shmem,
void shmem_fetch_notification(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 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 */ /* 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.. */ /* Take a copy to the rx buffer.. */
memcpy_fromio(xfer->rx.buf, shmem->msg_payload, xfer->rx.len); memcpy_fromio(xfer->rx.buf, shmem->msg_payload, xfer->rx.len);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册