Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] firmware: arm_ffa: Pass buffer size to partition info get
@ 2026-12-03  3:43 潘业成
  0 siblings, 0 replies; only message in thread
From: 潘业成 @ 2026-12-03  3:43 UTC (permalink / raw)
  To: sudeep.holla@kernel.org; +Cc: linux-arm-kernel@lists.infradead.org


From: panyecheng <panyecheng@xiaomi.com>


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.


Signed-off-by: panyecheng <panyecheng@xiaomi.com>
---
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(-)


diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c
index ae8cc3a2b..b1c559618 100644
--- a/drivers/firmware/arm_ffa/driver.c
+++ b/drivers/firmware/arm_ffa/driver.c
@@ -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;
diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h
index e71d83ee0..ba06d3663 100644
--- a/include/linux/arm_ffa.h
+++ b/include/linux/arm_ffa.h
@@ -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!******/#

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-03  3:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03  3:43 [PATCH] firmware: arm_ffa: Pass buffer size to partition info get 潘业成

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox