selftests/bpf: Add a selftest for invalid func btf with btf decl_tag
authorYonghong Song <yhs@fb.com>
Thu, 3 Feb 2022 19:17:32 +0000 (11:17 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 3 Feb 2022 21:06:04 +0000 (13:06 -0800)
Added a selftest similar to [1] which exposed a kernel bug.
Without the fix in the previous patch, the similar kasan error will appear.

  [1] https://lore.kernel.org/bpf/0000000000009b6eaa05d71a8c06@google.com/

Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20220203191732.742285-1-yhs@fb.com
tools/testing/selftests/bpf/prog_tests/btf.c

index 14f9b61..4038108 100644 (file)
@@ -3939,6 +3939,25 @@ static struct btf_raw_test raw_tests[] = {
        .err_str = "Invalid component_idx",
 },
 {
+       .descr = "decl_tag test #15, func, invalid func proto",
+       .raw_types = {
+               BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),  /* [1] */
+               BTF_DECL_TAG_ENC(NAME_TBD, 3, 0),               /* [2] */
+               BTF_FUNC_ENC(NAME_TBD, 8),                      /* [3] */
+               BTF_END_RAW,
+       },
+       BTF_STR_SEC("\0tag\0func"),
+       .map_type = BPF_MAP_TYPE_ARRAY,
+       .map_name = "tag_type_check_btf",
+       .key_size = sizeof(int),
+       .value_size = 4,
+       .key_type_id = 1,
+       .value_type_id = 1,
+       .max_entries = 1,
+       .btf_load_err = true,
+       .err_str = "Invalid type_id",
+},
+{
        .descr = "type_tag test #1",
        .raw_types = {
                BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),  /* [1] */