public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 0/8] firmware: arm_ffa: Fix cleanup, notification, and discovery paths
@ 2026-04-23 17:22 Sudeep Holla
  2026-04-23 17:22 ` [PATCH 1/8] firmware: arm_ffa: Check for NULL FF-A ID table while driver registration Sudeep Holla
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Sudeep Holla @ 2026-04-23 17:22 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel
  Cc: Jens Wiklander, Sudeep Holla, Sebastian Ene

Hi all,

This series fixes a set of issues in the FF-A driver around init
cleanup, framework notification handling, v1.0 notifier lifetime, and
partition discovery.

The fixes are all small and localized, but together they tighten a few
important paths:

- fix the early init unwind path when RX buffer allocation fails
- align the stored RX/TX buffer size with the size actually mapped to
  firmware
- ensure the framework notification handler always releases the RX
  buffer correctly
- validate framework notification payload bounds before copying data out
  of the shared RX buffer
- fix the partition lookup used for sched-recv callback registration
- unregister the FF-A v1.0 bus notifier during teardown
- bound the register-based partition discovery copies against the caller
  buffer
- reject FF-A driver registration without an ID table

This is the outcome of the self-initiated review of the entire driver
following the oversight of Sashiko’s review on one of the patches that
was merged.

https://sashiko.dev/#/patchset/20260402113939.930221-1-sebastianene@google.com

Signed-off-by: Sudeep Holla <sudeep.holla@kernel.org>
---
Sudeep Holla (8):
      firmware: arm_ffa: Check for NULL FF-A ID table while driver registration
      firmware: arm_ffa: Skip free_pages on RX buffer alloc failure
      firmware: arm_ffa: Align RxTx buffer size before mapping
      firmware: arm_ffa: Fix Rx buffer release in fwk notification handler
      firmware: arm_ffa: Validate framework notification payload bounds
      firmware: arm_ffa: Unregister v1.0 bus notifier on teardown
      firmware: arm_ffa: Fix sched-recv callback partition lookup
      firmware: arm_ffa: Bound PARTITION_INFO_GET_REGS copies

 drivers/firmware/arm_ffa/bus.c    |  4 +-
 drivers/firmware/arm_ffa/driver.c | 79 ++++++++++++++++++++++++++++-----------
 2 files changed, 60 insertions(+), 23 deletions(-)
---
base-commit: 2e68039281932e6dc37718a1ea7cbb8e2cda42e6
change-id: 20260423-ffa_fixes-4ad33f0ee250


-- 
Regards,
Sudeep



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/8] firmware: arm_ffa: Check for NULL FF-A ID table while driver registration
  2026-04-23 17:22 [PATCH 0/8] firmware: arm_ffa: Fix cleanup, notification, and discovery paths Sudeep Holla
@ 2026-04-23 17:22 ` Sudeep Holla
  2026-04-23 17:22 ` [PATCH 2/8] firmware: arm_ffa: Skip free_pages on RX buffer alloc failure Sudeep Holla
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Sudeep Holla @ 2026-04-23 17:22 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel; +Cc: Jens Wiklander, Sudeep Holla

The bus match callback assumes that every FF-A driver provides an
id_table and dereferences it unconditionally. Enforce that contract at
registration time so a buggy client driver cannot crash the bus during
match.

Fixes: e781858488b9 ("firmware: arm_ffa: Add initial FFA bus support for device enumeration")
Signed-off-by: Sudeep Holla <sudeep.holla@kernel.org>
---
 drivers/firmware/arm_ffa/bus.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/arm_ffa/bus.c b/drivers/firmware/arm_ffa/bus.c
index 9576862d89c4..601c3418e0d9 100644
--- a/drivers/firmware/arm_ffa/bus.c
+++ b/drivers/firmware/arm_ffa/bus.c
@@ -26,6 +26,8 @@ static int ffa_device_match(struct device *dev, const struct device_driver *drv)
 
 	id_table = to_ffa_driver(drv)->id_table;
 	ffa_dev = to_ffa_dev(dev);
+	if (!id_table)
+		return 0;
 
 	while (!uuid_is_null(&id_table->uuid)) {
 		/*
@@ -123,7 +125,7 @@ int ffa_driver_register(struct ffa_driver *driver, struct module *owner,
 {
 	int ret;
 
-	if (!driver->probe)
+	if (!driver->probe || !driver->id_table)
 		return -EINVAL;
 
 	driver->driver.bus = &ffa_bus_type;

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/8] firmware: arm_ffa: Skip free_pages on RX buffer alloc failure
  2026-04-23 17:22 [PATCH 0/8] firmware: arm_ffa: Fix cleanup, notification, and discovery paths Sudeep Holla
  2026-04-23 17:22 ` [PATCH 1/8] firmware: arm_ffa: Check for NULL FF-A ID table while driver registration Sudeep Holla
@ 2026-04-23 17:22 ` Sudeep Holla
  2026-04-23 17:22 ` [PATCH 3/8] firmware: arm_ffa: Align RxTx buffer size before mapping Sudeep Holla
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Sudeep Holla @ 2026-04-23 17:22 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel; +Cc: Jens Wiklander, Sudeep Holla

If the RX buffer allocation fails in ffa_init(), the error path jumps to
free_pages even though no buffer has been allocated yet. Route that case
directly to free_drv_info so the cleanup path is only used after at
least one RX/TX buffer allocation has succeeded.

Fixes: 3bbfe9871005 ("firmware: arm_ffa: Add initial Arm FFA driver support")
Signed-off-by: Sudeep Holla <sudeep.holla@kernel.org>
---
 drivers/firmware/arm_ffa/driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c
index eb2782848283..e6a051b20cb7 100644
--- a/drivers/firmware/arm_ffa/driver.c
+++ b/drivers/firmware/arm_ffa/driver.c
@@ -2067,7 +2067,7 @@ static int __init ffa_init(void)
 	drv_info->rx_buffer = alloc_pages_exact(rxtx_bufsz, GFP_KERNEL);
 	if (!drv_info->rx_buffer) {
 		ret = -ENOMEM;
-		goto free_pages;
+		goto free_drv_info;
 	}
 
 	drv_info->tx_buffer = alloc_pages_exact(rxtx_bufsz, GFP_KERNEL);

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/8] firmware: arm_ffa: Align RxTx buffer size before mapping
  2026-04-23 17:22 [PATCH 0/8] firmware: arm_ffa: Fix cleanup, notification, and discovery paths Sudeep Holla
  2026-04-23 17:22 ` [PATCH 1/8] firmware: arm_ffa: Check for NULL FF-A ID table while driver registration Sudeep Holla
  2026-04-23 17:22 ` [PATCH 2/8] firmware: arm_ffa: Skip free_pages on RX buffer alloc failure Sudeep Holla
@ 2026-04-23 17:22 ` Sudeep Holla
  2026-04-23 17:22 ` [PATCH 4/8] firmware: arm_ffa: Fix Rx buffer release in fwk notification handler Sudeep Holla
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Sudeep Holla @ 2026-04-23 17:22 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel
  Cc: Jens Wiklander, Sudeep Holla, Sebastian Ene

Commit 83210251fd70 ("firmware: arm_ffa: Use the correct buffer size during
RXTX_MAP") advertises PAGE_ALIGN(rxtx_bufsz) to firmware when mapping the
buffers but the driver continues to stores the minimum FF-A buffer size
in drv_info->rxtx_bufsz which is used elsewhere in the driver.

Align the size before storing it so that the allocation, validation and
FFA_RXTX_MAP all use the same buffer size.

Fixes: 83210251fd70 ("firmware: arm_ffa: Use the correct buffer size during RXTX_MAP")
Cc: Sebastian Ene <sebastianene@google.com>
Link: https://sashiko.dev/#/patchset/20260402113939.930221-1-sebastianene@google.com
Signed-off-by: Sudeep Holla <sudeep.holla@kernel.org>
---
 drivers/firmware/arm_ffa/driver.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c
index e6a051b20cb7..4dec7ca52f8c 100644
--- a/drivers/firmware/arm_ffa/driver.c
+++ b/drivers/firmware/arm_ffa/driver.c
@@ -2063,6 +2063,7 @@ static int __init ffa_init(void)
 			rxtx_bufsz = SZ_4K;
 	}
 
+	rxtx_bufsz = PAGE_ALIGN(rxtx_bufsz);
 	drv_info->rxtx_bufsz = rxtx_bufsz;
 	drv_info->rx_buffer = alloc_pages_exact(rxtx_bufsz, GFP_KERNEL);
 	if (!drv_info->rx_buffer) {
@@ -2078,7 +2079,7 @@ static int __init ffa_init(void)
 
 	ret = ffa_rxtx_map(virt_to_phys(drv_info->tx_buffer),
 			   virt_to_phys(drv_info->rx_buffer),
-			   PAGE_ALIGN(rxtx_bufsz) / FFA_PAGE_SIZE);
+			   rxtx_bufsz / FFA_PAGE_SIZE);
 	if (ret) {
 		pr_err("failed to register FFA RxTx buffers\n");
 		goto free_pages;

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/8] firmware: arm_ffa: Fix Rx buffer release in fwk notification handler
  2026-04-23 17:22 [PATCH 0/8] firmware: arm_ffa: Fix cleanup, notification, and discovery paths Sudeep Holla
                   ` (2 preceding siblings ...)
  2026-04-23 17:22 ` [PATCH 3/8] firmware: arm_ffa: Align RxTx buffer size before mapping Sudeep Holla
@ 2026-04-23 17:22 ` Sudeep Holla
  2026-04-23 17:22 ` [PATCH 5/8] firmware: arm_ffa: Validate framework notification payload bounds Sudeep Holla
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Sudeep Holla @ 2026-04-23 17:22 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel; +Cc: Jens Wiklander, Sudeep Holla

Refactor handle_fwk_notif_callbacks() so that all exit paths funnel
through a single FFA_RX_RELEASE call. While doing that, use scoped_guard()
for the Rx buffer lock and keep the message parsing under the lock scope.

This makes the Rx buffer release explicit for the kmemdup() failure path
and for the early exit when the framework notification bit is not set.

This will ensure the Rx buffer is always release in the framework
notification handler.

Fixes: 285a5ea0f542 ("firmware: arm_ffa: Add support for handling framework notifications")
Signed-off-by: Sudeep Holla <sudeep.holla@kernel.org>
---
 drivers/firmware/arm_ffa/driver.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c
index 4dec7ca52f8c..764cb1226182 100644
--- a/drivers/firmware/arm_ffa/driver.c
+++ b/drivers/firmware/arm_ffa/driver.c
@@ -1472,25 +1472,21 @@ static void handle_fwk_notif_callbacks(u32 bitmap)
 
 	/* Only one framework notification defined and supported for now */
 	if (!(bitmap & FRAMEWORK_NOTIFY_RX_BUFFER_FULL))
-		return;
+		goto release_rx;
 
-	mutex_lock(&drv_info->rx_lock);
+	scoped_guard(mutex, &drv_info->rx_lock) {
+		msg = drv_info->rx_buffer;
+		buf = kmemdup((void *)msg + msg->offset, msg->size, GFP_KERNEL);
+		if (!buf)
+			goto release_rx;
 
-	msg = drv_info->rx_buffer;
-	buf = kmemdup((void *)msg + msg->offset, msg->size, GFP_KERNEL);
-	if (!buf) {
-		mutex_unlock(&drv_info->rx_lock);
-		return;
+		target = SENDER_ID(msg->send_recv_id);
+		if (msg->offset >= sizeof(*msg))
+			uuid_copy(&uuid, &msg->uuid);
+		else
+			uuid_copy(&uuid, &uuid_null);
 	}
 
-	target = SENDER_ID(msg->send_recv_id);
-	if (msg->offset >= sizeof(*msg))
-		uuid_copy(&uuid, &msg->uuid);
-	else
-		uuid_copy(&uuid, &uuid_null);
-
-	mutex_unlock(&drv_info->rx_lock);
-
 	ffa_rx_release();
 
 	read_lock(&drv_info->notify_lock);
@@ -1500,6 +1496,11 @@ static void handle_fwk_notif_callbacks(u32 bitmap)
 	if (cb_info && cb_info->fwk_cb)
 		cb_info->fwk_cb(notify_id, cb_info->cb_data, buf);
 	kfree(buf);
+
+	return;
+
+release_rx:
+	ffa_rx_release();
 }
 
 static void notif_get_and_handle(void *cb_data)

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/8] firmware: arm_ffa: Validate framework notification payload bounds
  2026-04-23 17:22 [PATCH 0/8] firmware: arm_ffa: Fix cleanup, notification, and discovery paths Sudeep Holla
                   ` (3 preceding siblings ...)
  2026-04-23 17:22 ` [PATCH 4/8] firmware: arm_ffa: Fix Rx buffer release in fwk notification handler Sudeep Holla
@ 2026-04-23 17:22 ` Sudeep Holla
  2026-04-23 17:22 ` [PATCH 6/8] firmware: arm_ffa: Unregister v1.0 bus notifier on teardown Sudeep Holla
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Sudeep Holla @ 2026-04-23 17:22 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel; +Cc: Jens Wiklander, Sudeep Holla

Framework notification callbacks copy an indirect message payload out of
the shared Rx buffer. Validate the reported offset and size before
kmemdup() so malformed firmware data cannot drive an out-of-bounds read
or an oversized allocation.

Fixes: 285a5ea0f542 ("firmware: arm_ffa: Add support for handling framework notifications")
Signed-off-by: Sudeep Holla <sudeep.holla@kernel.org>
---
 drivers/firmware/arm_ffa/driver.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c
index 764cb1226182..0e030f377985 100644
--- a/drivers/firmware/arm_ffa/driver.c
+++ b/drivers/firmware/arm_ffa/driver.c
@@ -1469,6 +1469,7 @@ static void handle_fwk_notif_callbacks(u32 bitmap)
 	int notify_id = 0, target;
 	struct ffa_indirect_msg_hdr *msg;
 	struct notifier_cb_info *cb_info = NULL;
+	size_t min_offset = offsetof(struct ffa_indirect_msg_hdr, uuid);
 
 	/* Only one framework notification defined and supported for now */
 	if (!(bitmap & FRAMEWORK_NOTIFY_RX_BUFFER_FULL))
@@ -1476,6 +1477,13 @@ static void handle_fwk_notif_callbacks(u32 bitmap)
 
 	scoped_guard(mutex, &drv_info->rx_lock) {
 		msg = drv_info->rx_buffer;
+		if ((msg->offset != min_offset && msg->offset < sizeof(*msg)) ||
+		    msg->offset > drv_info->rxtx_bufsz ||
+		    msg->size > drv_info->rxtx_bufsz - msg->offset) {
+			pr_err("invalid framework notification message\n");
+			goto release_rx;
+		}
+
 		buf = kmemdup((void *)msg + msg->offset, msg->size, GFP_KERNEL);
 		if (!buf)
 			goto release_rx;

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6/8] firmware: arm_ffa: Unregister v1.0 bus notifier on teardown
  2026-04-23 17:22 [PATCH 0/8] firmware: arm_ffa: Fix cleanup, notification, and discovery paths Sudeep Holla
                   ` (4 preceding siblings ...)
  2026-04-23 17:22 ` [PATCH 5/8] firmware: arm_ffa: Validate framework notification payload bounds Sudeep Holla
@ 2026-04-23 17:22 ` Sudeep Holla
  2026-04-23 17:22 ` [PATCH 7/8] firmware: arm_ffa: Fix sched-recv callback partition lookup Sudeep Holla
  2026-04-23 17:22 ` [PATCH 8/8] firmware: arm_ffa: Bound PARTITION_INFO_GET_REGS copies Sudeep Holla
  7 siblings, 0 replies; 9+ messages in thread
From: Sudeep Holla @ 2026-04-23 17:22 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel; +Cc: Jens Wiklander, Sudeep Holla

For FF-A v1.0 the driver registers a bus notifier to backfill UUID
matching, but the notifier was never unregistered on cleanup paths.
Track the registration state and unregister it during teardown and early
partition-setup failure.

Fixes: 9dd15934f60d ("firmware: arm_ffa: Move the FF-A v1.0 NULL UUID workaround to bus notifier")
Signed-off-by: Sudeep Holla <sudeep.holla@kernel.org>
---
 drivers/firmware/arm_ffa/driver.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c
index 0e030f377985..4edb88079bac 100644
--- a/drivers/firmware/arm_ffa/driver.c
+++ b/drivers/firmware/arm_ffa/driver.c
@@ -100,6 +100,7 @@ struct ffa_drv_info {
 	bool mem_ops_native;
 	bool msg_direct_req2_supp;
 	bool bitmap_created;
+	bool bus_notifier_registered;
 	bool notif_enabled;
 	unsigned int sched_recv_irq;
 	unsigned int notif_pend_irq;
@@ -1638,6 +1639,15 @@ static struct notifier_block ffa_bus_nb = {
 	.notifier_call = ffa_bus_notifier,
 };
 
+static void ffa_bus_notifier_unregister(void)
+{
+	if (!drv_info->bus_notifier_registered)
+		return;
+
+	bus_unregister_notifier(&ffa_bus_type, &ffa_bus_nb);
+	drv_info->bus_notifier_registered = false;
+}
+
 static int ffa_xa_add_partition_info(struct ffa_device *dev)
 {
 	struct ffa_dev_part_info *info;
@@ -1721,6 +1731,8 @@ static void ffa_partitions_cleanup(void)
 	struct list_head *phead;
 	unsigned long idx;
 
+	ffa_bus_notifier_unregister();
+
 	/* Clean up/free all registered devices */
 	ffa_devices_unregister();
 
@@ -1748,11 +1760,14 @@ static int ffa_setup_partitions(void)
 		ret = bus_register_notifier(&ffa_bus_type, &ffa_bus_nb);
 		if (ret)
 			pr_err("Failed to register FF-A bus notifiers\n");
+		else
+			drv_info->bus_notifier_registered = true;
 	}
 
 	count = ffa_partition_probe(&uuid_null, &pbuf);
 	if (count <= 0) {
 		pr_info("%s: No partitions found, error %d\n", __func__, count);
+		ffa_bus_notifier_unregister();
 		return -EINVAL;
 	}
 

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 7/8] firmware: arm_ffa: Fix sched-recv callback partition lookup
  2026-04-23 17:22 [PATCH 0/8] firmware: arm_ffa: Fix cleanup, notification, and discovery paths Sudeep Holla
                   ` (5 preceding siblings ...)
  2026-04-23 17:22 ` [PATCH 6/8] firmware: arm_ffa: Unregister v1.0 bus notifier on teardown Sudeep Holla
@ 2026-04-23 17:22 ` Sudeep Holla
  2026-04-23 17:22 ` [PATCH 8/8] firmware: arm_ffa: Bound PARTITION_INFO_GET_REGS copies Sudeep Holla
  7 siblings, 0 replies; 9+ messages in thread
From: Sudeep Holla @ 2026-04-23 17:22 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel; +Cc: Jens Wiklander, Sudeep Holla

ffa_sched_recv_cb_update() used list_for_each_entry_safe() to search for
a matching partition and then tested the iterator against NULL. That is
not a valid end-of-list check for circular lists and can fall through
with an invalid pointer. Use a normal iterator and detect the not-found
case correctly before touching the partition state.

Fixes: be61da938576 ("firmware: arm_ffa: Allow multiple UUIDs per partition to register SRI callback")
Signed-off-by: Sudeep Holla <sudeep.holla@kernel.org>
---
 drivers/firmware/arm_ffa/driver.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c
index 4edb88079bac..40ade6edcf33 100644
--- a/drivers/firmware/arm_ffa/driver.c
+++ b/drivers/firmware/arm_ffa/driver.c
@@ -1190,7 +1190,7 @@ static int
 ffa_sched_recv_cb_update(struct ffa_device *dev, ffa_sched_recv_cb callback,
 			 void *cb_data, bool is_registration)
 {
-	struct ffa_dev_part_info *partition = NULL, *tmp;
+	struct ffa_dev_part_info *partition = NULL;
 	struct list_head *phead;
 	bool cb_valid;
 
@@ -1203,11 +1203,11 @@ ffa_sched_recv_cb_update(struct ffa_device *dev, ffa_sched_recv_cb callback,
 		return -EINVAL;
 	}
 
-	list_for_each_entry_safe(partition, tmp, phead, node)
+	list_for_each_entry(partition, phead, node)
 		if (partition->dev == dev)
 			break;
 
-	if (!partition) {
+	if (&partition->node == phead) {
 		pr_err("%s: No such partition ID 0x%x\n", __func__, dev->vm_id);
 		return -EINVAL;
 	}

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 8/8] firmware: arm_ffa: Bound PARTITION_INFO_GET_REGS copies
  2026-04-23 17:22 [PATCH 0/8] firmware: arm_ffa: Fix cleanup, notification, and discovery paths Sudeep Holla
                   ` (6 preceding siblings ...)
  2026-04-23 17:22 ` [PATCH 7/8] firmware: arm_ffa: Fix sched-recv callback partition lookup Sudeep Holla
@ 2026-04-23 17:22 ` Sudeep Holla
  7 siblings, 0 replies; 9+ messages in thread
From: Sudeep Holla @ 2026-04-23 17:22 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel; +Cc: Jens Wiklander, Sudeep Holla

The register-based PARTITION_INFO_GET path trusted the firmware-provided
indices when copying partition descriptors into the caller buffer.
Reject inconsistent counts or index progressions so the copy loop cannot
write past the allocated array.

Fixes: ba85c644ac8d ("firmware: arm_ffa: Add support for FFA_PARTITION_INFO_GET_REGS")
Signed-off-by: Sudeep Holla <sudeep.holla@kernel.org>
---
 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 40ade6edcf33..4bb86eb721cd 100644
--- a/drivers/firmware/arm_ffa/driver.c
+++ b/drivers/firmware/arm_ffa/driver.c
@@ -336,7 +336,7 @@ __ffa_partition_info_get_regs(u32 uuid0, u32 uuid1, u32 uuid2, u32 uuid3,
 
 	do {
 		__le64 *regs;
-		int idx;
+		int idx, nr_desc, buf_idx;
 
 		start_idx = prev_idx ? prev_idx + 1 : 0;
 
@@ -354,15 +354,25 @@ __ffa_partition_info_get_regs(u32 uuid0, u32 uuid1, u32 uuid2, u32 uuid3,
 			count = PARTITION_COUNT(partition_info.a2);
 		if (!buffer || !num_parts) /* count only */
 			return count;
+		if (count > num_parts)
+			return -EINVAL;
 
 		cur_idx = CURRENT_INDEX(partition_info.a2);
+		if (cur_idx < start_idx || cur_idx >= count)
+			return -EINVAL;
+
+		nr_desc = cur_idx - start_idx + 1;
+		buf_idx = buf - buffer;
+		if (buf_idx + nr_desc > num_parts)
+			return -EINVAL;
+
 		tag = UUID_INFO_TAG(partition_info.a2);
 		buf_sz = PARTITION_INFO_SZ(partition_info.a2);
 		if (buf_sz > sizeof(*buffer))
 			buf_sz = sizeof(*buffer);
 
 		regs = (void *)&partition_info.a3;
-		for (idx = 0; idx < cur_idx - start_idx + 1; idx++, buf++) {
+		for (idx = 0; idx < nr_desc; idx++, buf++) {
 			union {
 				uuid_t uuid;
 				u64 regs[2];

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-04-23 17:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-23 17:22 [PATCH 0/8] firmware: arm_ffa: Fix cleanup, notification, and discovery paths Sudeep Holla
2026-04-23 17:22 ` [PATCH 1/8] firmware: arm_ffa: Check for NULL FF-A ID table while driver registration Sudeep Holla
2026-04-23 17:22 ` [PATCH 2/8] firmware: arm_ffa: Skip free_pages on RX buffer alloc failure Sudeep Holla
2026-04-23 17:22 ` [PATCH 3/8] firmware: arm_ffa: Align RxTx buffer size before mapping Sudeep Holla
2026-04-23 17:22 ` [PATCH 4/8] firmware: arm_ffa: Fix Rx buffer release in fwk notification handler Sudeep Holla
2026-04-23 17:22 ` [PATCH 5/8] firmware: arm_ffa: Validate framework notification payload bounds Sudeep Holla
2026-04-23 17:22 ` [PATCH 6/8] firmware: arm_ffa: Unregister v1.0 bus notifier on teardown Sudeep Holla
2026-04-23 17:22 ` [PATCH 7/8] firmware: arm_ffa: Fix sched-recv callback partition lookup Sudeep Holla
2026-04-23 17:22 ` [PATCH 8/8] firmware: arm_ffa: Bound PARTITION_INFO_GET_REGS copies Sudeep Holla

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