diff options
author | Yonghong Song <yhs@fb.com> | 2022-06-12 22:43:14 -0700 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2022-06-14 17:01:54 +0200 |
commit | c49a44b39b313a4191ca2f06316c547ee673264e (patch) | |
tree | 07804cbfb15725bbea1db0e9a2b0ba15c6dfcfcf /tools | |
parent | 6dbdc9f35360d4ef4704462c265f63b32fcb5354 (diff) | |
download | linux-stable-c49a44b39b313a4191ca2f06316c547ee673264e.tar.gz linux-stable-c49a44b39b313a4191ca2f06316c547ee673264e.tar.bz2 linux-stable-c49a44b39b313a4191ca2f06316c547ee673264e.zip |
libbpf: Fix an unsigned < 0 bug
Andrii reported a bug with the following information:
2859 if (enum64_placeholder_id == 0) {
2860 enum64_placeholder_id = btf__add_int(btf, "enum64_placeholder", 1, 0);
>>> CID 394804: Control flow issues (NO_EFFECT)
>>> This less-than-zero comparison of an unsigned value is never true. "enum64_placeholder_id < 0U".
2861 if (enum64_placeholder_id < 0)
2862 return enum64_placeholder_id;
2863 ...
Here enum64_placeholder_id declared as '__u32' so enum64_placeholder_id < 0
is always false. Declare enum64_placeholder_id as 'int' in order to capture
the potential error properly.
Fixes: f2a625889bb8 ("libbpf: Add enum64 sanitization")
Reported-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220613054314.1251905-1-yhs@fb.com
Diffstat (limited to 'tools')
-rw-r--r-- | tools/lib/bpf/libbpf.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 0781fae58a06..d989b0a17a89 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -2786,7 +2786,7 @@ static int bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *btf) bool has_decl_tag = kernel_supports(obj, FEAT_BTF_DECL_TAG); bool has_type_tag = kernel_supports(obj, FEAT_BTF_TYPE_TAG); bool has_enum64 = kernel_supports(obj, FEAT_BTF_ENUM64); - __u32 enum64_placeholder_id = 0; + int enum64_placeholder_id = 0; struct btf_type *t; int i, j, vlen; |