]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Fix resetting logic for unreferenced kptrs
authorJules Irenge <jbi.octave@gmail.com>
Wed, 7 Sep 2022 15:24:20 +0000 (16:24 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 7 Sep 2022 18:15:18 +0000 (11:15 -0700)
commit2a0d22545d785746174736a9eacee98502944bc3
tree44399153a3ed1c94fb81141e31da24523542807c
parent375459affaf42c01202bdbdd77a60a9a4faa5df0
bpf: Fix resetting logic for unreferenced kptrs

Sparse reported a warning at bpf_map_free_kptrs()
"warning: Using plain integer as NULL pointer"
During the process of fixing this warning, it was discovered that the current
code erroneously writes to the pointer variable instead of deferencing and
writing to the actual kptr. Hence, Sparse tool accidentally helped to uncover
this problem. Fix this by doing WRITE_ONCE(*p, 0) instead of WRITE_ONCE(p, 0).

Note that the effect of this bug is that unreferenced kptrs will not be cleared
during check_and_free_fields. It is not a problem if the clearing is not done
during map_free stage, as there is nothing to free for them.

Fixes: 094624894a34 ("bpf: Wire up freeing of referenced kptr")
Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
Link: https://lore.kernel.org/r/Yxi3pJaK6UDjVJSy@playground
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/syscall.c