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 <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>
1 parent 63ee956 commit 0e3135d

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

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)