Skip to content

Commit 92e9bac

Browse files
ivanorlov2206kees
authored andcommitted
kunit/overflow: Fix UB in overflow_allocation_test
The 'device_name' array doesn't exist out of the 'overflow_allocation_test' function scope. However, it is being used as a driver name when calling 'kunit_driver_create' from 'kunit_device_register'. It produces the kernel panic with KASAN enabled. Since this variable is used in one place only, remove it and pass the device name into kunit_device_register directly as an ascii string. Signed-off-by: Ivan Orlov <[email protected]> Reviewed-by: David Gow <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent f32e90c commit 92e9bac

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

lib/overflow_kunit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,6 @@ DEFINE_TEST_ALLOC(devm_kzalloc, devm_kfree, 1, 1, 0);
668668

669669
static void overflow_allocation_test(struct kunit *test)
670670
{
671-
const char device_name[] = "overflow-test";
672671
struct device *dev;
673672
int count = 0;
674673

@@ -678,7 +677,7 @@ static void overflow_allocation_test(struct kunit *test)
678677
} while (0)
679678

680679
/* Create dummy device for devm_kmalloc()-family tests. */
681-
dev = kunit_device_register(test, device_name);
680+
dev = kunit_device_register(test, "overflow-test");
682681
KUNIT_ASSERT_FALSE_MSG(test, IS_ERR(dev),
683682
"Cannot register test device\n");
684683

0 commit comments

Comments
 (0)