]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: Use ASSERT_STRNEQ to factor in long slab cache names
authorMatt Bobrowski <mattbobrowski@google.com>
Tue, 18 Nov 2025 07:37:34 +0000 (07:37 +0000)
committerMartin KaFai Lau <martin.lau@kernel.org>
Thu, 20 Nov 2025 17:26:06 +0000 (09:26 -0800)
subtest_kmem_cache_iter_check_slabinfo() fundamentally compares slab
cache names parsed out from /proc/slabinfo against those stored within
struct kmem_cache_result. The current problem is that the slab cache
name within struct kmem_cache_result is stored within a bounded
fixed-length array (sized to SLAB_NAME_MAX(32)), whereas the name
parsed out from /proc/slabinfo is not. Meaning, using ASSERT_STREQ()
can certainly lead to test failures, particularly when dealing with
slab cache names that are longer than SLAB_NAME_MAX(32)
bytes. Notably, kmem_cache_create() allows callers to create slab
caches with somewhat arbitrarily sized names via its __name identifier
argument, so exceeding the SLAB_NAME_MAX(32) limit that is in place
now can certainly happen.

Make subtest_kmem_cache_iter_check_slabinfo() more reliable by only
checking up to sizeof(struct kmem_cache_result.name) - 1 using
ASSERT_STRNEQ().

Fixes: a496d0cdc84d ("selftests/bpf: Add a test for kmem_cache_iter")
Signed-off-by: Matt Bobrowski <mattbobrowski@google.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Acked-by: Song Liu <song@kernel.org>
Link: https://patch.msgid.link/20251118073734.4188710-1-mattbobrowski@google.com
tools/testing/selftests/bpf/prog_tests/kmem_cache_iter.c

index 1de14b111931aacb921bbe0a36d795fd6406b8a0..6e35e13c20220ecb4d5a27ecde932a2c8c40fb8a 100644 (file)
@@ -57,7 +57,8 @@ static void subtest_kmem_cache_iter_check_slabinfo(struct kmem_cache_iter *skel)
                if (!ASSERT_OK(ret, "kmem_cache_lookup"))
                        break;
 
-               ASSERT_STREQ(r.name, name, "kmem_cache_name");
+               ASSERT_STRNEQ(r.name, name, sizeof(r.name) - 1,
+                             "kmem_cache_name");
                ASSERT_EQ(r.obj_size, objsize, "kmem_cache_objsize");
 
                seen++;