Skip to contentSkip to conversation

firmware: arm_ffa: Pass buffer size to partition info get

PATCH New 潘业成 1 participant 1 message Dec 3 Firmware framework for ARMV8-a

lore
Share & tools
lore

潘业成

author
#0 lore raw

PATCH 1/1 firmware: arm_ffa: Pass buffer size to partition info get

From: panyecheng <[email protected]>

ffa_info_ops.partition_info_get() copies the partition descriptors returned by FFA_PARTITION_INFO_GET into a buffer provided by the caller, but the interface gives it no way to know how many descriptors that buffer can hold. Since FF-A v1.1 the call may return more than one descriptor for a UUID shared by several partitions, so a caller supplying a one-element buffer can have two or more descriptors memcpy()'d past the end of its object.

Add a num_partitions argument carrying the number of descriptors the caller's buffer can hold and return -ENOSPC, rather than overflowing the buffer, when the firmware reports more partitions than fit.

There are no in-tree users of partition_info_get() today, so no call sites need updating; the flaw is latent in the exported interface.

---
Resend: the initial copy was rejected by the list server; it may have reached the addressee directly.

 drivers/firmware/arm_ffa/driver.c | 7 ++++++-
 include/linux/arm_ffa.h           | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/firmware/arm_ffa/driver.c +6 -1
index ae8cc3a2b..b1c559618 100644
@@ -1145,7 +1145,7 @@ static u32 ffa_api_version_get(void)
 }
 
 static int ffa_partition_info_get(const char *uuid_str,
-  struct ffa_partition_info *buffer)
+  struct ffa_partition_info *buffer, size_t num_partitions)
 {
 int count;
 uuid_t uuid;
@@ -1160,6 +1160,11 @@ static int ffa_partition_info_get(const char *uuid_str,
 if (count <= 0)
 return -ENOENT;
 
+if (count > num_partitions) {
+kfree(pbuf);
+return -ENOSPC;
+}
+
 memcpy(buffer, pbuf, sizeof(*pbuf) * count);
 kfree(pbuf);
 return 0;
include/linux/arm_ffa.h +1 -1
index e71d83ee0..ba06d3663 100644
@@ -470,7 +470,7 @@ struct ffa_mem_ops_args {
 struct ffa_info_ops {
 u32 (*api_version_get)(void);
 int (*partition_info_get)(const char *uuid_str,
-  struct ffa_partition_info *buffer);
+  struct ffa_partition_info *buffer, size_t num_partitions);
 };
 
 struct ffa_msg_ops {

--
2.34.1

#/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#