Skip to content

Commit 32dfc59

Browse files
author
Martin KaFai Lau
committed
Merge branch 'fix resolving VAR after DATASEC'
Lorenz Bauer says: ==================== See the first patch for a detailed explanation. v2: - Move RESOLVE_TBD assignment out of the loop (Martin) ==================== Signed-off-by: Martin KaFai Lau <[email protected]>
2 parents 294635a + dfdd608 commit 32dfc59

File tree

2 files changed

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

2 files changed

+29
-0
lines changed

kernel/bpf/btf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4569,6 +4569,7 @@ static int btf_datasec_resolve(struct btf_verifier_env *env,
45694569
struct btf *btf = env->btf;
45704570
u16 i;
45714571

4572+
env->resolve_mode = RESOLVE_TBD;
45724573
for_each_vsi_from(i, v->next_member, v->t, vsi) {
45734574
u32 var_type_id = vsi->type, type_id, type_size = 0;
45744575
const struct btf_type *var_type = btf_type_by_id(env->btf,

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)