diff options
author | Eduard Zingerman <eddyz87@gmail.com> | 2024-01-31 23:26:15 +0200 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2024-02-01 11:13:45 +0100 |
commit | 8263b3382d8c1af0fffa27095a9f1db6f2dad899 (patch) | |
tree | aaf52c8edacd92fe52eea3edc723ebc760ecc6ee /Documentation/bpf | |
parent | b3d3e29376a3f898bc90063a1e8c36c76cea1901 (diff) | |
download | linux-8263b3382d8c1af0fffa27095a9f1db6f2dad899.tar.gz linux-8263b3382d8c1af0fffa27095a9f1db6f2dad899.tar.bz2 linux-8263b3382d8c1af0fffa27095a9f1db6f2dad899.zip |
libbpf: Remove unnecessary null check in kernel_supports()
After recent changes, Coverity complained about inconsistent null checks
in kernel_supports() function:
kernel_supports(const struct bpf_object *obj, ...)
[...]
// var_compare_op: Comparing obj to null implies that obj might be null
if (obj && obj->gen_loader)
return true;
// var_deref_op: Dereferencing null pointer obj
if (obj->token_fd)
return feat_supported(obj->feat_cache, feat_id);
[...]
- The original null check was introduced by commit [0], which introduced
a call `kernel_supports(NULL, ...)` in function bump_rlimit_memlock();
- This call was refactored to use `feat_supported(NULL, ...)` in commit [1].
Looking at all places where kernel_supports() is called:
- There is either `obj->...` access before the call;
- Or `obj` comes from `prog->obj` expression, where `prog` comes from
enumeration of programs in `obj`;
- Or `obj` comes from `prog->obj`, where `prog` is a parameter to one
of the API functions:
- bpf_program__attach_kprobe_opts;
- bpf_program__attach_kprobe;
- bpf_program__attach_ksyscall.
Assuming correct API usage, it appears that `obj` can never be null when
passed to kernel_supports(). Silence the Coverity warning by removing
redundant null check.
[0] e542f2c4cd16 ("libbpf: Auto-bump RLIMIT_MEMLOCK if kernel needs it for BPF")
[1] d6dd1d49367a ("libbpf: Further decouple feature checking logic from bpf_object")
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20240131212615.20112-1-eddyz87@gmail.com
Diffstat (limited to 'Documentation/bpf')
0 files changed, 0 insertions, 0 deletions