lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240816100258.2159447-1-ruanjinjie@huawei.com>
Date: Fri, 16 Aug 2024 18:02:58 +0800
From: Jinjie Ruan <ruanjinjie@...wei.com>
To: <sudeep.holla@....com>, <linux-arm-kernel@...ts.infradead.org>,
	<linux-kernel@...r.kernel.org>
CC: <ruanjinjie@...wei.com>
Subject: [PATCH -next] firmware: arm_ffa: Fix beyond size of field warning

An allmodconfig build of arm64 resulted in following warning:

	In function ‘fortify_memcpy_chk’,
	    inlined from ‘export_uuid’ at ./include/linux/uuid.h:88:2,
	    inlined from ‘ffa_msg_send_direct_req2’ at ./drivers/firmware/arm_ffa/driver.c:488:2:
	./include/linux/fortify-string.h:571:25: error: call to ‘__write_overflow_field’ declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
	  571 |                         __write_overflow_field(p_size_field, size);
	      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	In function ‘fortify_memcpy_chk’,
	    inlined from ‘ffa_msg_send_direct_req2’ at ./drivers/firmware/arm_ffa/driver.c:489:2:
	./linux-next/include/linux/fortify-string.h:571:25: error: call to ‘__write_overflow_field’ declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
	  571 |                         __write_overflow_field(p_size_field, size);
	      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Because ffa_msg_send_direct_req2() memcpy uuid_t and struct
ffa_send_direct_data2 data to unsigned long dst, the copy size is 2 or
or 14 unsigned long which beyond size of dst size, fix it by using a temp
array for memcpy.

Signed-off-by: Jinjie Ruan <ruanjinjie@...wei.com>
---
 drivers/firmware/arm_ffa/driver.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c
index 1e3764852118..674fbe008ea6 100644
--- a/drivers/firmware/arm_ffa/driver.c
+++ b/drivers/firmware/arm_ffa/driver.c
@@ -480,13 +480,23 @@ static int ffa_msg_send2(u16 src_id, u16 dst_id, void *buf, size_t sz)
 static int ffa_msg_send_direct_req2(u16 src_id, u16 dst_id, const uuid_t *uuid,
 				    struct ffa_send_direct_data2 *data)
 {
+	unsigned long args_data[14];
+	unsigned long args_uuid[2];
+	unsigned long *data_ptr;
+
 	u32 src_dst_ids = PACK_TARGET_INFO(src_id, dst_id);
 	ffa_value_t ret, args = {
 		.a0 = FFA_MSG_SEND_DIRECT_REQ2, .a1 = src_dst_ids,
 	};
 
-	export_uuid((u8 *)&args.a2, uuid);
-	memcpy(&args.a4, data, sizeof(*data));
+	memcpy(args_uuid, uuid, sizeof(uuid_t));
+	args.a2 = args_uuid[0];
+	args.a3 = args_uuid[1];
+
+	memcpy(args_data, data, sizeof(*data));
+	data_ptr = &args.a4;
+	for (int i = 0; i < 14; i++)
+		*data_ptr++ = args_data[i];
 
 	invoke_ffa_fn(args, &ret);
 
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ