Skip to contentSkip to conversation

firmware: arm_ffa: fix memory corruption in ffa_msg_send2()

PATCH Applied Dan Carpenter 2 participants 2 messages Apr 24, 2024 – Apr 25, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firmware: arm_ffa: fix memory corruption in ffa_msg_send2()

The "msg" pointer is a struct and msg->offset is the sizeof(*msg). The pointer here math means the memcpy() will write outside the bounds. Cast "msg" to a u8 pointer to fix this.

Fixes 02c19d84c7c5 ("firmware: arm_ffa: Add support for FFA_MSG_SEND2")
---
 drivers/firmware/arm_ffa/driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/arm_ffa/driver.c +1 -1
index 9f89ee0aaa6b..363e86936461 100644
@@ -363,7 +363,7 @@ static int ffa_msg_send2(u16 src_id, u16 dst_id, void *buf, size_t sz)
 	msg->offset = sizeof(*msg);
 	msg->send_recv_id = src_dst_ids;
 	msg->size = sz;
-	memcpy(msg + msg->offset, buf, sz);
+	memcpy((u8 *)msg + msg->offset, buf, sz);
 
 	/* flags = 0, sender VMID = 0 works for both physical/virtual NS */
 	invoke_ffa_fn((ffa_value_t){
Signature · 1 line
2.43.0
Applied
#1 lore raw
Quoted 4 lines · Dan Carpenter

The "msg" pointer is a struct and msg->offset is the sizeof(*msg). The pointer here math means the memcpy() will write outside the bounds. Cast "msg" to a u8 pointer to fix this.

Applied to sudeep.holla/linux (for-next/ffa/updates), thanks!

[1/1] firmware: arm_ffa: fix memory corruption in ffa_msg_send2()

      https://git.kernel.org/sudeep.holla/c/ddfade88f49d

--
Regards,
Sudeep