[PATCH] firewire: core: fix use-after-free in build_tree() error path

From: Takashi Sakamoto

Date: Sat Dec 05 2026 - 01:33:32 EST


The error path of build_tree() calls free_fw_node() from inside
for_each_fw_node(). free_fw_node() calls kfree() while for_each_fw_node()
is still iterating over the nodes. This results in a use-after-free when
for_each_fw_node() accesses the freed node after the callback returns.

Instead of kfree(), drop the reference acquired by fw_node_create() with
fw_node_put(). This allows the final fw_node_put() in for_each_fw_node()
to release the node safely.

Fixes: 05bfb1327dc5 ("firewire: core: fix memory leak in error path of build_tree()")
Reported-by: Srh P. <sprystaiko@xxxxxxxxx>
Suggested-by: Srh P. <sprystaiko@xxxxxxxxx>
Signed-off-by: Takashi Sakamoto <o-takashi@xxxxxxxxxxxxx>
---
drivers/firewire/core-topology.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/firewire/core-topology.c b/drivers/firewire/core-topology.c
index 512b7e4473af..e16d07f6673f 100644
--- a/drivers/firewire/core-topology.c
+++ b/drivers/firewire/core-topology.c
@@ -96,7 +96,7 @@ static void for_each_fw_node(struct fw_card *card, struct fw_node *root,

static void free_fw_node(struct fw_card *card, struct fw_node *node, struct fw_node *parent)
{
- kfree(node);
+ fw_node_put(node);
}

/*

base-commit: 82d9180bdd384e36dc77c1700ab2f1dd18782a9d
prerequisite-patch-id: 97861a3446a8d3fc32017c2ff1f09502d36efe05
--
2.55.0