diff options
author | Eric Dumazet <edumazet@google.com> | 2021-10-26 14:41:32 -0700 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2021-10-27 11:13:52 -0700 |
commit | d979617aa84d96acca44c2f5778892b4565e322f (patch) | |
tree | ff58a7ed0c96b37015fb26af06e914d4677256e7 /kernel/bpf/trampoline.c | |
parent | f941eadd8d6d4ee2f8c9aeab8e1da5e647533a7d (diff) | |
download | linux-d979617aa84d96acca44c2f5778892b4565e322f.tar.gz linux-d979617aa84d96acca44c2f5778892b4565e322f.tar.bz2 linux-d979617aa84d96acca44c2f5778892b4565e322f.zip |
bpf: Fixes possible race in update_prog_stats() for 32bit arches
It seems update_prog_stats() suffers from same issue fixed
in the prior patch:
As it can run while interrupts are enabled, it could
be re-entered and the u64_stats syncp could be mangled.
Fixes: fec56f5890d9 ("bpf: Introduce BPF trampoline")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211026214133.3114279-3-eric.dumazet@gmail.com
Diffstat (limited to 'kernel/bpf/trampoline.c')
-rw-r--r-- | kernel/bpf/trampoline.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c index 39eaaff81953..e5963de368ed 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -586,11 +586,13 @@ static void notrace update_prog_stats(struct bpf_prog *prog, * Hence check that 'start' is valid. */ start > NO_START_TIME) { + unsigned long flags; + stats = this_cpu_ptr(prog->stats); - u64_stats_update_begin(&stats->syncp); + flags = u64_stats_update_begin_irqsave(&stats->syncp); stats->cnt++; stats->nsecs += sched_clock() - start; - u64_stats_update_end(&stats->syncp); + u64_stats_update_end_irqrestore(&stats->syncp, flags); } } |