]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: add get_next_key boundary test for cgroup_storage
authorWeiming Shi <bestswngs@gmail.com>
Fri, 3 Apr 2026 13:29:51 +0000 (21:29 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 6 Apr 2026 01:45:05 +0000 (18:45 -0700)
Verify that bpf_map__get_next_key() correctly returns -ENOENT when
called on the last (and only) key in a cgroup_storage map. Before the
fix in the previous patch, this would succeed with bogus key data
instead of failing.

Suggested-by: Paul Chaignon <paul.chaignon@gmail.com>
Signed-off-by: Weiming Shi <bestswngs@gmail.com>
Acked-by: Paul Chaignon <paul.chaignon@gmail.com>
Link: https://lore.kernel.org/r/20260403132951.43533-3-bestswngs@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/cgroup_storage.c

index cf395715ced47037d9730dca9e2aba098a55582a..5451a43b3563e431b1ead2c2ce414ce808f6f8ee 100644 (file)
@@ -86,6 +86,11 @@ void test_cgroup_storage(void)
        err = SYS_NOFAIL(PING_CMD);
        ASSERT_OK(err, "sixth ping");
 
+       err = bpf_map__get_next_key(skel->maps.cgroup_storage, &key, &key,
+                                   sizeof(key));
+       ASSERT_ERR(err, "bpf_map__get_next_key should fail");
+       ASSERT_EQ(errno, ENOENT, "no second key");
+
 cleanup_progs:
        cgroup_storage__destroy(skel);
 cleanup_network: