mm/slub, kunit: Use inverted data to corrupt kmem cache
PATCH 1/1 mm/slub, kunit: Use inverted data to corrupt kmem cache
Two failure patterns are seen randomly when running slub_kunit tests with CONFIG_SLAB_FREELIST_RANDOM and CONFIG_SLAB_FREELIST_HARDENED enabled.
Pattern 1:
# test_clobber_zone: pass:1 fail:0 skip:0 total:1 ok 1 test_clobber_zone
# test_next_pointer: EXPECTATION FAILED at lib/slub_kunit.c:72 Expected 3 == slab_errors, but
slab_errors == 0 (0x0)
# test_next_pointer: EXPECTATION FAILED at lib/slub_kunit.c:84 Expected 2 == slab_errors, but
slab_errors == 0 (0x0)
# test_next_pointer: pass:0 fail:1 skip:0 total:1 not ok 2 test_next_pointer
In this case, test_next_pointer() overwrites p[s->offset], but the data at p[s->offset] is already 0x12.
Pattern 2:
ok 1 test_clobber_zone
# test_next_pointer: EXPECTATION FAILED at lib/slub_kunit.c:72 Expected 3 == slab_errors, but
slab_errors == 2 (0x2)
# test_next_pointer: pass:0 fail:1 skip:0 total:1 not ok 2 test_next_pointer
In this case, p[s->offset] has a value other than 0x12, but one of the expected failures is nevertheless missing.
Invert data instead of writing a fixed value to corrupt the cache data structures to fix the problem.
--- lib/slub_kunit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/slub_kunit.c +1 -1
@@ -55,7 +55,7 @@ static void test_next_pointer(struct kunit *test) ptr_addr = (unsigned long *)(p + s->offset); tmp = *ptr_addr; - p[s->offset] =0x12 ; + p[s->offset] = ~p[s->offset];/* * Expecting three errors.
Signature · 1 line
2.39.2
Quoted 32 lines · Guenter Roeck
Two failure patterns are seen randomly when running
slub_kunittests withCONFIG_SLAB_FREELIST_RANDOMandCONFIG_SLAB_FREELIST_HARDENEDenabled.Pattern 1:
#test_clobber_zone: pass:1 fail:0 skip:0 total:1 ok 1test_clobber_zone
#test_next_pointer: EXPECTATION FAILED atlib/slub_kunit.c:72Expected 3 ==slab_errors, but
slab_errors== 0 (0x0)
#test_next_pointer: EXPECTATION FAILED atlib/slub_kunit.c:84Expected 2 ==slab_errors, but
slab_errors== 0 (0x0)
#test_next_pointer: pass:0 fail:1 skip:0 total:1 not ok 2test_next_pointerIn this case,
test_next_pointer()overwrites p[s->offset], but the data at p[s->offset] is already0x12.Pattern 2:
ok 1test_clobber_zone
#test_next_pointer: EXPECTATION FAILED atlib/slub_kunit.c:72Expected 3 ==slab_errors, but
slab_errors== 2 (0x2)
#test_next_pointer: pass:0 fail:1 skip:0 total:1 not ok 2test_next_pointerIn this case, p[s->offset] has a value other than
0x12, but one of the expected failures is nevertheless missing.Invert data instead of writing a fixed value to corrupt the cache data structures to fix the problem.
Quoted 6 lines
Fixes 1f9f78b1b376 ("mm/slub, kunit: add a KUnit test for SLUB debugging functionality")Cc Oliver Glitta <[email protected]>Cc Vlastimil Babka <[email protected]>CC Daniel Latypov <[email protected]>Cc Marco Elver <[email protected]>Signed-off-by Guenter Roeck <[email protected]>
Added to slab/for-next, thanks.
Quoted 17 lines
--- lib/slub_kunit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/slub_kunit.c +1
-1@@ -55,7 +55,7 @@ static void test_next_pointer(struct kunit *test) ptr_addr = (unsigned long *)(p + s->offset); tmp = *ptr_addr; - p[s->offset] =0x12 ; + p[s->offset] = ~p[s->offset];/* * Expecting three errors.