[PATCH] firmware: arm_ffa: Bound the buffer in partition_info_get()

panyecheng 2287015934 at qq.com
Thu Dec 3 07:59:17 PST 2026


Give the ffa_info_ops.partition_info_get() callback an explicit buffer
capacity and refuse the copy with -ENOSPC when it is too small.

DEN0077A 6.2.2 has the callee return one partition information
descriptor per partition matching the queried UUID, so a single query
can yield several descriptors. The callback copies them into a caller
supplied buffer:

	memcpy(buffer, pbuf, sizeof(*pbuf) * count);

and until now had no way to know how large that buffer is. A caller
that sizes its buffer for one descriptor is silently corrupted when
more than one partition matches.

There is no in-tree user of this callback yet, but the exported API
cannot be used safely without the bound.

Signed-off-by: panyecheng <2287015934 at qq.com>
---
 drivers/firmware/arm_ffa/driver.c | 8 +++++++-
 include/linux/arm_ffa.h           | 3 ++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c
index ae8cc3a2ba2e..e5a5c056547a 100644
--- a/drivers/firmware/arm_ffa/driver.c
+++ b/drivers/firmware/arm_ffa/driver.c
@@ -1145,7 +1145,8 @@ 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,
+				  int num_partitions)
 {
 	int count;
 	uuid_t uuid;
@@ -1160,6 +1161,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 e71d83ee0aef..57c168d55bfc 100644
--- a/include/linux/arm_ffa.h
+++ b/include/linux/arm_ffa.h
@@ -470,7 +470,8 @@ 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,
+				  int num_partitions);
 };
 
 struct ffa_msg_ops {
-- 
2.43.0




More information about the linux-arm-kernel mailing list