Add a TEST_BTF_DUMP_DATA_OVER() case that dumps an all-zero union bpf_iter_link_info with a data_sz one byte short of the type size. Without the overflow check in btf_dump_type_data_check_zero() the zero-scan reads past data_end; with it, btf_dump__dump_type_data() returns -E2BIG. Suggested-by: Alexei Starovoitov Signed-off-by: Gu Bin --- tools/testing/selftests/bpf/prog_tests/btf_dump.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c b/tools/testing/selftests/bpf/prog_tests/btf_dump.c index 35f214e254da..68f33f8a54ab 100644 --- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c +++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c @@ -1156,6 +1156,15 @@ static void test_btf_dump_struct_data(struct btf *btf, struct btf_dump *d, "(union bpf_iter_link_info){.map = (struct){.map_fd = (__u32)1,},.cgroup = (struct){.order = (enum bpf_cgroup_iter_order)BPF_CGROUP_ITER_SELF_ONLY,.cgroup_fd = (__u32)1,},.task = (struct){.tid = (__u32)1,.pid = (__u32)1,},}", { .cgroup = { .order = 1, .cgroup_fd = 1, }}); + /* + * overflow test for all-zero union: with a data_sz one byte short + * of the type size, the zero-scan must not read past data_end and + * must return -E2BIG. + */ + TEST_BTF_DUMP_DATA_OVER(btf, d, "union", str, union bpf_iter_link_info, + sizeof(union bpf_iter_link_info) - 1, + "(union bpf_iter_link_info){\n", {}); + /* struct skb with nested structs/unions; because type output is so * complex, we don't do a string comparison, just verify we return * the type size as the amount of data displayed. -- 2.55.0.windows.3