Skip to content

Commit 0e3135d

Browse files
hefengqingAlexei Starovoitov
authored andcommitted
bpf: Fix possible race in inc_misses_counter
It seems inc_misses_counter() suffers from same issue fixed in the commit d979617 ("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: 9ed9e9b ("bpf: Count the number of times recursion was prevented") Signed-off-by: He Fengqing <[email protected]> Acked-by: John Fastabend <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 63ee956 commit 0e3135d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

kernel/bpf/trampoline.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,11 +550,12 @@ static __always_inline u64 notrace bpf_prog_start_time(void)
550550
static void notrace inc_misses_counter(struct bpf_prog *prog)
551551
{
552552
struct bpf_prog_stats *stats;
553+
unsigned int flags;
553554

554555
stats = this_cpu_ptr(prog->stats);
555-
u64_stats_update_begin(&stats->syncp);
556+
flags = u64_stats_update_begin_irqsave(&stats->syncp);
556557
u64_stats_inc(&stats->misses);
557-
u64_stats_update_end(&stats->syncp);
558+
u64_stats_update_end_irqrestore(&stats->syncp, flags);
558559
}
559560

560561
/* The logic is similar to bpf_prog_run(), but with an explicit

0 commit comments

Comments
 (0)