]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: Add test to verify checking padding bytes for BPF syscall common attri...
authorLeon Hwang <leon.hwang@linux.dev>
Mon, 18 May 2026 14:54:46 +0000 (22:54 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 19 May 2026 01:51:32 +0000 (18:51 -0700)
Add a test to verify that the tailing padding 4 bytes are checked in
syscall.c::__sys_bpf() using bpf_check_uarg_tail_zero().

Without the fix, the test fails with:

 test_common_attr_padding:FAIL:syscall unexpected syscall: actual 4 >= expected 0
 #213/12  map_create_failure/common_attr_padding:FAIL

Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
Link: https://lore.kernel.org/r/20260518145446.6794-6-leon.hwang@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/map_init.c

index b0b902d5783de2eca8a295ccf3d2a3f907f60c29..c804c3ce9be966ed9495e727751a61659c531ec5 100644 (file)
@@ -353,6 +353,30 @@ static void test_excl_prog_hash_size_2(void)
        test_map_create_array(&opts, msg);
 }
 
+static void test_common_attr_padding(void)
+{
+       struct bpf_common_attr_fake {
+               __u8 attrs[offsetofend(struct bpf_common_attr, log_true_size)];
+               __u32 pad;
+       } attr_common = {
+               .pad = 1,
+       };
+       union bpf_attr attr = {
+               .map_type    = BPF_MAP_TYPE_ARRAY,
+               .key_size    = 4,
+               .value_size  = 4,
+               .max_entries = 1,
+       };
+       int fd;
+
+       fd = syscall(__NR_bpf, BPF_MAP_CREATE | BPF_COMMON_ATTRS, &attr, sizeof(attr), &attr_common,
+                    sizeof(attr_common));
+       if (!ASSERT_LT(fd, 0, "syscall"))
+               close(fd);
+       else
+               ASSERT_EQ(errno, E2BIG, "errno");
+}
+
 void test_map_create_failure(void)
 {
        if (test__start_subtest("invalid_vmlinux_value_type_id_struct_ops"))
@@ -377,4 +401,6 @@ void test_map_create_failure(void)
                test_excl_prog_hash_size_1();
        if (test__start_subtest("invalid_excl_prog_hash_size_2"))
                test_excl_prog_hash_size_2();
+       if (test__start_subtest("common_attr_padding"))
+               test_common_attr_padding();
 }