Skip to content

Commit

Permalink
bpf: Fixes possible race in update_prog_stats() for 32bit arches
Browse files Browse the repository at this point in the history
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: fec56f5 ("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
  • Loading branch information
Eric Dumazet authored and Alexei Starovoitov committed Oct 27, 2021
1 parent f941ead commit d979617
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kernel/bpf/trampoline.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit d979617

Please sign in to comment.