From 0eefccd9cce8a98abf8260b44d5cd299980a9a35 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Tue, 1 Sep 2026 22:45:32 +0900 Subject: [PATCH] firewire: core: add test for invalid length in config ROM generator Although the unit drivers and the userspace applications are allowed to extend the system configuration ROM, they could provide invalid extension data. Add a KUnit test to verify that the generator handles an extension with an invalid length. Link: https://lore.kernel.org/r/20260901134534.2386577-12-o-takashi@sakamocchi.jp Signed-off-by: Takashi Sakamoto --- drivers/firewire/config-rom-generator-test.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/firewire/config-rom-generator-test.c b/drivers/firewire/config-rom-generator-test.c index 7d76580c2004..260b3d6e9a27 100644 --- a/drivers/firewire/config-rom-generator-test.c +++ b/drivers/firewire/config-rom-generator-test.c @@ -306,6 +306,16 @@ static void test_config_rom_generator(struct kunit *test) fw_core_remove_descriptor(&avc_unit_entry); } +static void add_descriptor_with_invalid_length(struct kunit *test) +{ + // Use kernel stack since they should be mutable for doubly linked-list. + struct fw_descriptor entry_with_invalid_length = { + .length = 257, + }; + + KUNIT_EXPECT_EQ(test, fw_core_add_descriptor(&entry_with_invalid_length), -EINVAL); +} + static const struct fw_card_driver dummy_card_driver; static int config_rom_generator_test_init(struct kunit *test) @@ -336,6 +346,7 @@ static void config_rom_generator_test_exit(struct kunit *test) static struct kunit_case config_rom_generator_test_cases[] = { KUNIT_CASE_PARAM(test_config_rom_generator, generator_test_gen_params), + KUNIT_CASE(add_descriptor_with_invalid_length), {} };