diff options
| author | He Fengqing <hefengqing@huawei.com> | 2022-01-22 10:29:36 +0000 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-02-05 12:39:58 +0100 |
| commit | ed1707d0a64d92432b9fac368983c1b4465220f0 (patch) | |
| tree | a37d3ff1dc5040b3b973c9ef8c280aaf30ba2f8e | |
| parent | 577f932216d02157637c621dc318014bcfa5ed82 (diff) | |
| download | linux-ed1707d0a64d92432b9fac368983c1b4465220f0.tar.gz linux-ed1707d0a64d92432b9fac368983c1b4465220f0.tar.bz2 linux-ed1707d0a64d92432b9fac368983c1b4465220f0.zip | |
bpf: Fix possible race in inc_misses_counter
commit 0e3135d3bfa5dfb658145238d2bc723a8e30c3a3 upstream.
It seems inc_misses_counter() suffers from same issue fixed in
the commit d979617aa84d ("bpf: Fixes possible race in update_prog_stats()
for 32bit arches"):
As it can run while interrupts are enabled, it could
be re-entered and the u64_stats syncp could be mangled.
Fixes: 9ed9e9ba2337 ("bpf: Count the number of times recursion was prevented")
Signed-off-by: He Fengqing <hefengqing@huawei.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/r/20220122102936.1219518-1-hefengqing@huawei.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
| -rw-r--r-- | kernel/bpf/trampoline.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c index e98de5e73ba5..507d06590579 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -542,11 +542,12 @@ static __always_inline u64 notrace bpf_prog_start_time(void) static void notrace inc_misses_counter(struct bpf_prog *prog) { struct bpf_prog_stats *stats; + unsigned int flags; stats = this_cpu_ptr(prog->stats); - u64_stats_update_begin(&stats->syncp); + flags = u64_stats_update_begin_irqsave(&stats->syncp); u64_stats_inc(&stats->misses); - u64_stats_update_end(&stats->syncp); + u64_stats_update_end_irqrestore(&stats->syncp, flags); } /* The logic is similar to bpf_prog_run(), but with an explicit |
