Skip to content

Commit

Permalink
libbpf: Make btf__resolve_size logic always check size error condition
Browse files Browse the repository at this point in the history
Perform size check always in btf__resolve_size. Makes the logic a bit more
robust against corrupted BTF and silences LGTM/Coverity complaining about
always true (size < 0) check.

Fixes: 69eaab0 ("btf: extract BTF type size calculation")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20191107020855.3834758-5-andriin@fb.com
  • Loading branch information
Andrii Nakryiko authored and Daniel Borkmann committed Nov 7, 2019
1 parent dd3ab12 commit 994021a
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions tools/lib/bpf/btf.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,9 @@ __s64 btf__resolve_size(const struct btf *btf, __u32 type_id)
t = btf__type_by_id(btf, type_id);
}

done:
if (size < 0)
return -EINVAL;

done:
if (nelems && size > UINT32_MAX / nelems)
return -E2BIG;

Expand Down

0 comments on commit 994021a

Please sign in to comment.