Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61DE0356744; Sat, 12 Sep 2026 11:07:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789211230; cv=none; b=POwO4fTuxP4aa60B+AEkscoMT0+0LaTUcZ1nNDeP4QJx4qmR6v+mzvTuApQGttpUx2ZLgOFyhC4Lb0HxswjL9bYpWm6H8k1RjsjYmjCzAHusxWKARXRcX596JWwzzjIgmmdD45qQxUJsdMbA2tcMYe39Ch6kWjj+npxtZYjIDSQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789211230; c=relaxed/simple; bh=SpcAfrgVcMIwFtWsMfl0SBuTiRgO8yj+8yjJtv7ohaQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YK/9mzxmatv8REHJH23NIaIUaqjbQV4pPPAE+sIPGnia7hl1Xh+zPS+nF+lnIoBRsdIvKkQfQoUNmEEmro5qoDlSHxE4lbHm35kWPK1Id/vR7ZSMhxKJP6nrZdxHCZnbHDgV1xSyIqo1Q3ZykOnB6Q3MFaMRdVaOuzuERWuQsII= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=DoBK5vcd; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="DoBK5vcd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 785B11F000FF; Sat, 12 Sep 2026 11:07:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789211229; bh=YxUg5oHE5zs11cHlrBgYN3vVKCTdfKBGW5kTJgdwdCw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DoBK5vcdAotahBi4QyTUYyewV+knuQHyD29rgwBCfhE7ka/gkgRFWVTJscK2JglAf 8fIRKujvIx1g8ulr5MQlneG5ahLJem1L7fGgFzSrqacN8Qjfue0pxFGWzJzb5R2YUA 7lrpQsGfmR3w3uq1CuHGohAUFbDA1P2kIQxryHFM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Takashi Sakamoto , Sasha Levin Subject: [PATCH 6.18 1151/1518] firewire: core: add KUnit tests for failure of tree building Date: Sat, 12 Sep 2026 08:55:20 +0200 Message-ID: <20260912065649.494152940@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065623.398859879@linuxfoundation.org> References: <20260912065623.398859879@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Sakamoto [ Upstream commit f744022705b7eb479a1931ddd95aae4e9a4be221 ] Abdun Nihaal has reported a memory leak when tree building fails in the middle of self ID sequence enumeration. This is caused by an invalid self ID sequence and is not a common occurrence. This commit is intended to assist in fixing the issue by adding KUnit tests to show the cases in which the memory leak is triggered. The leak occurs internally in the build_tree() function, therefore it cannot be detected directly by the tests. Link: https://lore.kernel.org/r/20260810064119.410324-4-o-takashi@sakamocchi.jp Signed-off-by: Takashi Sakamoto Stable-dep-of: 05bfb1327dc5 ("firewire: core: fix memory leak in error path of build_tree()") Signed-off-by: Sasha Levin --- drivers/firewire/node-tree-test.c | 84 +++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/drivers/firewire/node-tree-test.c b/drivers/firewire/node-tree-test.c index 6f404df3d50e0..251c0113639f2 100644 --- a/drivers/firewire/node-tree-test.c +++ b/drivers/firewire/node-tree-test.c @@ -506,6 +506,86 @@ static void node_tree_test_four_nodes_case3(struct kunit *test) KUNIT_EXPECT_EQ(test, data->release_count, 4); } +static void node_tree_test_invalid_extended_self_id_sequence(struct kunit *test) +{ + // Use the same node tree as node_tree_test_four_nodes_case1, except for the invalid + // content of self ID packet for the phy 3. + static const u32 self_id_sequence[] = { + 0x80000094, + 0x81000080, + 0x820000bc, + 0x830000d1, // Invalid. + }; + struct private_data *data = test->priv; + struct fw_card *card = data->card; + + card->node_id = LOCAL_BUS | 0x03; + + // TODO: Memory leak. + card->local_node = build_tree(card, self_id_sequence, ARRAY_SIZE(self_id_sequence), 123); + KUNIT_EXPECT_NULL(test, card->local_node); +} + +static void node_tree_test_invalid_phy_id(struct kunit *test) +{ + // Use the same node tree as node_tree_test_four_nodes_case1, except for the invalid + // phy ID for phy 3. + static const u32 self_id_sequence[] = { + 0x80000094, + 0x81000080, + 0x820000bc, + 0x8f0000d0, // Invalid. + }; + struct private_data *data = test->priv; + struct fw_card *card = data->card; + + card->node_id = LOCAL_BUS | 0x03; + + // TODO: Memory leak. + card->local_node = build_tree(card, self_id_sequence, ARRAY_SIZE(self_id_sequence), 123); + KUNIT_EXPECT_NULL(test, card->local_node); +} + +static void node_tree_test_invalid_child_port_count(struct kunit *test) +{ + // Use the same node tree as node_tree_test_four_nodes_case1, except for the invalid + // count of child ports for phy 3. + static const u32 self_id_sequence[] = { + 0x80000094, + 0x81000080, + 0x820000bc, + 0x830000fc, // Invalid. + }; + struct private_data *data = test->priv; + struct fw_card *card = data->card; + + card->node_id = LOCAL_BUS | 0x03; + + // TODO: Memory leak. + card->local_node = build_tree(card, self_id_sequence, ARRAY_SIZE(self_id_sequence), 123); + KUNIT_EXPECT_NULL(test, card->local_node); +} + +static void node_tree_test_invalid_parent_port_count(struct kunit *test) +{ + // Use the same node tree as node_tree_test_four_nodes_case1, except for the invalid + // count of parent ports for phy 3. + static const u32 self_id_sequence[] = { + 0x80000094, + 0x81000080, + 0x820000bc, + 0x830000e8, // Invalid. + }; + struct private_data *data = test->priv; + struct fw_card *card = data->card; + + card->node_id = LOCAL_BUS | 0x03; + + // TODO: Memory leak. + card->local_node = build_tree(card, self_id_sequence, ARRAY_SIZE(self_id_sequence), 123); + KUNIT_EXPECT_NULL(test, card->local_node); +} + static struct kunit_case node_tree_test_cases[] = { KUNIT_CASE(node_tree_test_two_nodes), KUNIT_CASE(node_tree_test_two_nodes_1394a), @@ -515,6 +595,10 @@ static struct kunit_case node_tree_test_cases[] = { KUNIT_CASE(node_tree_test_four_nodes_case1), KUNIT_CASE(node_tree_test_four_nodes_case2), KUNIT_CASE(node_tree_test_four_nodes_case3), + KUNIT_CASE(node_tree_test_invalid_extended_self_id_sequence), + KUNIT_CASE(node_tree_test_invalid_phy_id), + KUNIT_CASE(node_tree_test_invalid_child_port_count), + KUNIT_CASE(node_tree_test_invalid_parent_port_count), {} }; -- 2.53.0