Skip to content

Commit dfdd608

Browse files
Lorenz BauerMartin KaFai Lau
authored andcommitted
selftests/bpf: check that modifier resolves after pointer
Add a regression test that ensures that a VAR pointing at a modifier which follows a PTR (or STRUCT or ARRAY) is resolved correctly by the datasec validator. Signed-off-by: Lorenz Bauer <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
1 parent 9b45980 commit dfdd608

File tree

1 file changed

+28
-0
lines changed
  • tools/testing/selftests/bpf/prog_tests

1 file changed

+28
-0
lines changed

tools/testing/selftests/bpf/prog_tests/btf.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,34 @@ static struct btf_raw_test raw_tests[] = {
879879
.btf_load_err = true,
880880
.err_str = "Invalid elem",
881881
},
882+
{
883+
.descr = "var after datasec, ptr followed by modifier",
884+
.raw_types = {
885+
/* .bss section */ /* [1] */
886+
BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 2),
887+
sizeof(void*)+4),
888+
BTF_VAR_SECINFO_ENC(4, 0, sizeof(void*)),
889+
BTF_VAR_SECINFO_ENC(6, sizeof(void*), 4),
890+
/* int */ /* [2] */
891+
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
892+
/* int* */ /* [3] */
893+
BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 2),
894+
BTF_VAR_ENC(NAME_TBD, 3, 0), /* [4] */
895+
/* const int */ /* [5] */
896+
BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 2),
897+
BTF_VAR_ENC(NAME_TBD, 5, 0), /* [6] */
898+
BTF_END_RAW,
899+
},
900+
.str_sec = "\0a\0b\0c\0",
901+
.str_sec_size = sizeof("\0a\0b\0c\0"),
902+
.map_type = BPF_MAP_TYPE_ARRAY,
903+
.map_name = ".bss",
904+
.key_size = sizeof(int),
905+
.value_size = sizeof(void*)+4,
906+
.key_type_id = 0,
907+
.value_type_id = 1,
908+
.max_entries = 1,
909+
},
882910
/* Test member exceeds the size of struct.
883911
*
884912
* struct A {

0 commit comments

Comments
 (0)