提交 ad2c163f 编写于 作者: A Andrii Nakryiko 提交者: Zheng Zengkai

libbpf: Accomodate DWARF/compiler bug with duplicated identical arrays

mainline inclusion
from mainline-5.11-rc1
commit 6b6e6b1d
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6b6e6b1d09aa20c351a1fce0ea6402da436624a4

-------------------------------------------------

In some cases compiler seems to generate distinct DWARF types for identical
arrays within the same CU. That seems like a bug, but it's already out there
and breaks type graph equivalence checks, so accommodate it anyway by checking
for identical arrays, regardless of their type ID.
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Acked-by: NSong Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20201105043402.2530976-10-andrii@kernel.org
(cherry picked from commit 6b6e6b1d)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 89468d9c
...@@ -3786,6 +3786,19 @@ static inline __u16 btf_fwd_kind(struct btf_type *t) ...@@ -3786,6 +3786,19 @@ static inline __u16 btf_fwd_kind(struct btf_type *t)
return btf_kflag(t) ? BTF_KIND_UNION : BTF_KIND_STRUCT; return btf_kflag(t) ? BTF_KIND_UNION : BTF_KIND_STRUCT;
} }
/* Check if given two types are identical ARRAY definitions */
static int btf_dedup_identical_arrays(struct btf_dedup *d, __u32 id1, __u32 id2)
{
struct btf_type *t1, *t2;
t1 = btf_type_by_id(d->btf, id1);
t2 = btf_type_by_id(d->btf, id2);
if (!btf_is_array(t1) || !btf_is_array(t2))
return 0;
return btf_equal_array(t1, t2);
}
/* /*
* Check equivalence of BTF type graph formed by candidate struct/union (we'll * Check equivalence of BTF type graph formed by candidate struct/union (we'll
* call it "candidate graph" in this description for brevity) to a type graph * call it "candidate graph" in this description for brevity) to a type graph
...@@ -3896,8 +3909,18 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, ...@@ -3896,8 +3909,18 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id,
canon_id = resolve_fwd_id(d, canon_id); canon_id = resolve_fwd_id(d, canon_id);
hypot_type_id = d->hypot_map[canon_id]; hypot_type_id = d->hypot_map[canon_id];
if (hypot_type_id <= BTF_MAX_NR_TYPES) if (hypot_type_id <= BTF_MAX_NR_TYPES) {
return hypot_type_id == cand_id; /* In some cases compiler will generate different DWARF types
* for *identical* array type definitions and use them for
* different fields within the *same* struct. This breaks type
* equivalence check, which makes an assumption that candidate
* types sub-graph has a consistent and deduped-by-compiler
* types within a single CU. So work around that by explicitly
* allowing identical array types here.
*/
return hypot_type_id == cand_id ||
btf_dedup_identical_arrays(d, hypot_type_id, cand_id);
}
if (btf_dedup_hypot_map_add(d, canon_id, cand_id)) if (btf_dedup_hypot_map_add(d, canon_id, cand_id))
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册