Skip to content

Commit 369b976

Browse files
author
Alexei Starovoitov
committed
Merge branch 'fix-btf_dedup'
Andrii Nakryiko says: ==================== This patch set fixes bug in btf_dedup_is_equiv() check mishandling equivalence comparison between VOID kind in candidate type graph versus anonymous non-VOID kind in canonical type graph. Patch #1 fixes bug, by comparing candidate and canonical kinds for equality, before proceeding to kind-specific checks. Patch #2 adds a test case testing this specific scenario. ==================== Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2 parents f52c97d + eb76899 commit 369b976

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

tools/lib/bpf/btf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,9 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id,
21072107
return fwd_kind == real_kind;
21082108
}
21092109

2110+
if (cand_kind != canon_kind)
2111+
return 0;
2112+
21102113
switch (cand_kind) {
21112114
case BTF_KIND_INT:
21122115
return btf_equal_int(cand_type, canon_type);

tools/testing/selftests/bpf/test_btf.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5776,6 +5776,53 @@ const struct btf_dedup_test dedup_tests[] = {
57765776
.dedup_table_size = 1, /* force hash collisions */
57775777
},
57785778
},
5779+
{
5780+
.descr = "dedup: void equiv check",
5781+
/*
5782+
* // CU 1:
5783+
* struct s {
5784+
* struct {} *x;
5785+
* };
5786+
* // CU 2:
5787+
* struct s {
5788+
* int *x;
5789+
* };
5790+
*/
5791+
.input = {
5792+
.raw_types = {
5793+
/* CU 1 */
5794+
BTF_STRUCT_ENC(0, 0, 1), /* [1] struct {} */
5795+
BTF_PTR_ENC(1), /* [2] ptr -> [1] */
5796+
BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [3] struct s */
5797+
BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
5798+
/* CU 2 */
5799+
BTF_PTR_ENC(0), /* [4] ptr -> void */
5800+
BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [5] struct s */
5801+
BTF_MEMBER_ENC(NAME_NTH(2), 4, 0),
5802+
BTF_END_RAW,
5803+
},
5804+
BTF_STR_SEC("\0s\0x"),
5805+
},
5806+
.expect = {
5807+
.raw_types = {
5808+
/* CU 1 */
5809+
BTF_STRUCT_ENC(0, 0, 1), /* [1] struct {} */
5810+
BTF_PTR_ENC(1), /* [2] ptr -> [1] */
5811+
BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [3] struct s */
5812+
BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
5813+
/* CU 2 */
5814+
BTF_PTR_ENC(0), /* [4] ptr -> void */
5815+
BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [5] struct s */
5816+
BTF_MEMBER_ENC(NAME_NTH(2), 4, 0),
5817+
BTF_END_RAW,
5818+
},
5819+
BTF_STR_SEC("\0s\0x"),
5820+
},
5821+
.opts = {
5822+
.dont_resolve_fwds = false,
5823+
.dedup_table_size = 1, /* force hash collisions */
5824+
},
5825+
},
57795826
{
57805827
.descr = "dedup: all possible kinds (no duplicates)",
57815828
.input = {

0 commit comments

Comments
 (0)