[PATCH V3 v3 1/2] firewire: core: validate overall descriptor length in fw_core_add_descriptor()

From: Sreeraj S Kurup

Date: Sat Jul 25 2026 - 11:54:49 EST


In fw_core_add_descriptor(), incoming descriptor structures are processed
without checking whether the descriptor's specified length falls within
valid boundaries. An empty descriptor (length 0) or an oversized descriptor
exceeding the IEEE 1394 Config ROM capacity can lead to invalid processing.

Add bounds checking at the start of fw_core_add_descriptor() using the
in_range() helper macro to reject descriptors with length 0 or length
exceeding 256 quadlets (the standard maximum Configuration ROM size).

Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@xxxxxxxxx>
---
drivers/firewire/core-card.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
index a754c6366b97..eaec54ea287a 100644
--- a/drivers/firewire/core-card.c
+++ b/drivers/firewire/core-card.c
@@ -16,6 +16,7 @@
#include <linux/list.h>
#include <linux/module.h>
#include <linux/mutex.h>
+#include <linux/minmax.h>
#include <linux/spinlock.h>
#include <linux/workqueue.h>

@@ -167,11 +168,10 @@ int fw_core_add_descriptor(struct fw_descriptor *desc)
{
size_t i;

- /*
- * Check descriptor is valid; the length of all blocks in the
- * descriptor has to add up to exactly the length of the
- * block.
- */
+ /* Reject empty descriptors or those exceeding max Config ROM size (256 quadlets) */
+ if (!in_range(desc->length, 1, 256))
+ return -EINVAL;
+
i = 0;
while (i < desc->length)
i += (desc->data[i] >> 16) + 1;
--
2.54.0