Skip to content

Commit

Permalink
bpf: Fix possible race in inc_misses_counter
Browse files Browse the repository at this point in the history
[ Upstream commit 0e3135d ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
hefengqing authored and gregkh committed Mar 8, 2022
1 parent aa50406 commit 07058fb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions kernel/bpf/trampoline.c
Expand Up @@ -541,11 +541,12 @@ static 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
Expand Down

0 comments on commit 07058fb

Please sign in to comment.