From: Andrii Nakryiko <andriin@fb•com>
To: <andrii.nakryiko@gmail•com>, <kernel-team@fb•com>, <ast@fb•com>,
<acme@kernel•org>, <netdev@vger•kernel.org>,
<bpf@vger•kernel.org>, <daniel@iogearbox•net>
Cc: Andrii Nakryiko <andriin@fb•com>
Subject: [PATCH bpf-next 4/5] btf: fix bug with resolving STRUCT/UNION into corresponding FWD
Date: Wed, 27 Feb 2019 14:46:40 -0800 [thread overview]
Message-ID: <20190227224642.1069138-5-andriin@fb.com> (raw)
In-Reply-To: <20190227224642.1069138-1-andriin@fb.com>
When checking available canonical candidates for struct/union algorithm
utilizes btf_dedup_is_equiv to determine if candidate is suitable. This
check is not enough when candidate is corresponding FWD for that
struct/union, because according to equivalence logic they are
equivalent. When it so happens that FWD and STRUCT/UNION end in hashing
to the same bucket, it's possible to create remapping loop from FWD to
STRUCT and STRUCT to same FWD, which will cause btf_dedup() to loop
forever.
This patch fixes the issue by additionally checking that type and
canonical candidate are strictly equal (utilizing btf_equal_struct).
Fixes: d5caef5b5655 ("btf: add BTF types deduplication algorithm")
Reported-by: Arnaldo Carvalho de Melo <acme@redhat•com>
Signed-off-by: Andrii Nakryiko <andriin@fb•com>
---
tools/lib/bpf/btf.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 6bbb710216e6..53db26d158c9 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -2255,7 +2255,7 @@ static void btf_dedup_merge_hypot_map(struct btf_dedup *d)
static int btf_dedup_struct_type(struct btf_dedup *d, __u32 type_id)
{
struct btf_dedup_node *cand_node;
- struct btf_type *t;
+ struct btf_type *cand_type, *t;
/* if we don't find equivalent type, then we are canonical */
__u32 new_id = type_id;
__u16 kind;
@@ -2275,6 +2275,10 @@ static int btf_dedup_struct_type(struct btf_dedup *d, __u32 type_id)
for_each_dedup_cand(d, h, cand_node) {
int eq;
+ cand_type = d->btf->types[cand_node->type_id];
+ if (!btf_equal_struct(t, cand_type))
+ continue;
+
btf_dedup_clear_hypot_map(d);
eq = btf_dedup_is_equiv(d, type_id, cand_node->type_id);
if (eq < 0)
--
2.17.1
next prev parent reply other threads:[~2019-02-27 22:47 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-27 22:46 [PATCH bpf-next 0/5] btf_dedup algorithm and test fixes Andrii Nakryiko
2019-02-27 22:46 ` [PATCH bpf-next 1/5] selftests/bpf: fix btf_dedup testing code Andrii Nakryiko
2019-02-28 18:17 ` Song Liu
2019-02-28 18:19 ` Yonghong Song
2019-02-28 18:52 ` Arnaldo Carvalho de Melo
2019-02-28 19:19 ` Andrii Nakryiko
2019-02-27 22:46 ` [PATCH bpf-next 2/5] libbpf: fix formatting for btf_ext__get_raw_data Andrii Nakryiko
2019-02-28 18:17 ` Song Liu
2019-02-28 18:53 ` Arnaldo Carvalho de Melo
2019-02-28 19:20 ` Andrii Nakryiko
2019-02-27 22:46 ` [PATCH bpf-next 3/5] btf: allow to customize dedup hash table size Andrii Nakryiko
2019-02-28 18:27 ` Song Liu
2019-02-28 18:51 ` Andrii Nakryiko
2019-02-28 19:02 ` Song Liu
2019-02-28 19:40 ` Andrii Nakryiko
2019-02-28 19:56 ` Song Liu
2019-02-28 18:57 ` Arnaldo Carvalho de Melo
2019-02-28 20:08 ` Andrii Nakryiko
2019-02-27 22:46 ` Andrii Nakryiko [this message]
2019-02-28 18:18 ` [PATCH bpf-next 4/5] btf: fix bug with resolving STRUCT/UNION into corresponding FWD Yonghong Song
2019-02-28 19:07 ` Andrii Nakryiko
2019-02-28 19:41 ` Yonghong Song
2019-02-28 20:26 ` Andrii Nakryiko
2019-02-28 18:29 ` Song Liu
2019-02-27 22:46 ` [PATCH bpf-next 5/5] selftests/bpf: add btf_dedup test of FWD/STRUCT resolution Andrii Nakryiko
2019-02-28 18:29 ` Song Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190227224642.1069138-5-andriin@fb.com \
--to=andriin@fb$(echo .)com \
--cc=acme@kernel$(echo .)org \
--cc=andrii.nakryiko@gmail$(echo .)com \
--cc=ast@fb$(echo .)com \
--cc=bpf@vger$(echo .)kernel.org \
--cc=daniel@iogearbox$(echo .)net \
--cc=kernel-team@fb$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox