Skip to content

Commit 8e7c8ca

Browse files
committed
test_overflow: Regularize test reporting output
Report test run summaries more regularly, so it's easier to understand the output: - Remove noisy "ok" reports for shift and allocator tests. - Reorganize per-type output to the end of each type's tests. - Replace redundant vmalloc tests with __vmalloc so that __GFP_NO_WARN can be used to keep the expected failure warnings out of dmesg, similar to commit 8e060c2 ("lib/test_overflow.c: avoid tainting the kernel and fix wrap size") Resulting output: test_overflow: 18 u8 arithmetic tests finished test_overflow: 19 s8 arithmetic tests finished test_overflow: 17 u16 arithmetic tests finished test_overflow: 17 s16 arithmetic tests finished test_overflow: 17 u32 arithmetic tests finished test_overflow: 17 s32 arithmetic tests finished test_overflow: 17 u64 arithmetic tests finished test_overflow: 21 s64 arithmetic tests finished test_overflow: 113 shift tests finished test_overflow: 17 overflow size helper tests finished test_overflow: 11 allocation overflow tests finished test_overflow: all tests passed Acked-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Link: https://lore.kernel.org/all/eb6d02ae-e2ed-e7bd-c700-8a6d004d84ce@rasmusvillemoes.dk/ Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Link: https://lore.kernel.org/all/CAKwvOdnYYa+72VhtJ4ug=SJVFn7w+n7Th+hKYE87BRDt4hvqOg@mail.gmail.com/ Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent dfd42fa commit 8e7c8ca

1 file changed

Lines changed: 30 additions & 24 deletions

File tree

lib/test_overflow.c

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ static int __init test_ ## t ## _overflow(void) { \
252252
int err = 0; \
253253
unsigned i; \
254254
\
255-
pr_info("%-3s: %zu arithmetic tests\n", #t, \
256-
ARRAY_SIZE(t ## _tests)); \
257255
for (i = 0; i < ARRAY_SIZE(t ## _tests); ++i) \
258256
err |= do_test_ ## t(&t ## _tests[i]); \
257+
pr_info("%zu %s arithmetic tests finished\n", \
258+
ARRAY_SIZE(t ## _tests), #t); \
259259
return err; \
260260
}
261261

@@ -291,6 +291,7 @@ static int __init test_overflow_calculation(void)
291291
static int __init test_overflow_shift(void)
292292
{
293293
int err = 0;
294+
int count = 0;
294295

295296
/* Args are: value, shift, type, expected result, overflow expected */
296297
#define TEST_ONE_SHIFT(a, s, t, expect, of) ({ \
@@ -313,9 +314,7 @@ static int __init test_overflow_shift(void)
313314
pr_warn("got %llu\n", (u64)__d); \
314315
__failed = 1; \
315316
} \
316-
if (!__failed) \
317-
pr_info("ok: (%s)(%s << %s) == %s\n", #t, #a, #s, \
318-
of ? "overflow" : #expect); \
317+
count++; \
319318
__failed; \
320319
})
321320

@@ -479,6 +478,10 @@ static int __init test_overflow_shift(void)
479478
err |= TEST_ONE_SHIFT(0, 31, s32, 0, false);
480479
err |= TEST_ONE_SHIFT(0, 63, s64, 0, false);
481480

481+
pr_info("%d shift tests finished\n", count);
482+
483+
#undef TEST_ONE_SHIFT
484+
482485
return err;
483486
}
484487

@@ -530,7 +533,6 @@ static int __init test_ ## func (void *arg) \
530533
free ## want_arg (free_func, arg, ptr); \
531534
return 1; \
532535
} \
533-
pr_info(#func " detected saturation\n"); \
534536
return 0; \
535537
}
536538

@@ -544,10 +546,7 @@ DEFINE_TEST_ALLOC(kmalloc, kfree, 0, 1, 0);
544546
DEFINE_TEST_ALLOC(kmalloc_node, kfree, 0, 1, 1);
545547
DEFINE_TEST_ALLOC(kzalloc, kfree, 0, 1, 0);
546548
DEFINE_TEST_ALLOC(kzalloc_node, kfree, 0, 1, 1);
547-
DEFINE_TEST_ALLOC(vmalloc, vfree, 0, 0, 0);
548-
DEFINE_TEST_ALLOC(vmalloc_node, vfree, 0, 0, 1);
549-
DEFINE_TEST_ALLOC(vzalloc, vfree, 0, 0, 0);
550-
DEFINE_TEST_ALLOC(vzalloc_node, vfree, 0, 0, 1);
549+
DEFINE_TEST_ALLOC(__vmalloc, vfree, 0, 1, 0);
551550
DEFINE_TEST_ALLOC(kvmalloc, kvfree, 0, 1, 0);
552551
DEFINE_TEST_ALLOC(kvmalloc_node, kvfree, 0, 1, 1);
553552
DEFINE_TEST_ALLOC(kvzalloc, kvfree, 0, 1, 0);
@@ -559,32 +558,39 @@ static int __init test_overflow_allocation(void)
559558
{
560559
const char device_name[] = "overflow-test";
561560
struct device *dev;
561+
int count = 0;
562562
int err = 0;
563563

564+
#define check_allocation_overflow(alloc) ({ \
565+
count++; \
566+
test_ ## alloc(dev); \
567+
})
568+
564569
/* Create dummy device for devm_kmalloc()-family tests. */
565570
dev = root_device_register(device_name);
566571
if (IS_ERR(dev)) {
567572
pr_warn("Cannot register test device\n");
568573
return 1;
569574
}
570575

571-
err |= test_kmalloc(NULL);
572-
err |= test_kmalloc_node(NULL);
573-
err |= test_kzalloc(NULL);
574-
err |= test_kzalloc_node(NULL);
575-
err |= test_kvmalloc(NULL);
576-
err |= test_kvmalloc_node(NULL);
577-
err |= test_kvzalloc(NULL);
578-
err |= test_kvzalloc_node(NULL);
579-
err |= test_vmalloc(NULL);
580-
err |= test_vmalloc_node(NULL);
581-
err |= test_vzalloc(NULL);
582-
err |= test_vzalloc_node(NULL);
583-
err |= test_devm_kmalloc(dev);
584-
err |= test_devm_kzalloc(dev);
576+
err |= check_allocation_overflow(kmalloc);
577+
err |= check_allocation_overflow(kmalloc_node);
578+
err |= check_allocation_overflow(kzalloc);
579+
err |= check_allocation_overflow(kzalloc_node);
580+
err |= check_allocation_overflow(__vmalloc);
581+
err |= check_allocation_overflow(kvmalloc);
582+
err |= check_allocation_overflow(kvmalloc_node);
583+
err |= check_allocation_overflow(kvzalloc);
584+
err |= check_allocation_overflow(kvzalloc_node);
585+
err |= check_allocation_overflow(devm_kmalloc);
586+
err |= check_allocation_overflow(devm_kzalloc);
585587

586588
device_unregister(dev);
587589

590+
pr_info("%d allocation overflow tests finished\n", count);
591+
592+
#undef check_allocation_overflow
593+
588594
return err;
589595
}
590596

0 commit comments

Comments
 (0)