Patch "bpf: Fix possible race in inc_misses_counter" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    bpf: Fix possible race in inc_misses_counter

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     bpf-fix-possible-race-in-inc_misses_counter.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 9a45c44573ba9428f978d99230092ae474f16045
Author: He Fengqing <hefengqing@xxxxxxxxxx>
Date:   Sat Jan 22 10:29:36 2022 +0000

    bpf: Fix possible race in inc_misses_counter
    
    [ Upstream commit 0e3135d3bfa5dfb658145238d2bc723a8e30c3a3 ]
    
    It seems inc_misses_counter() suffers from same issue fixed in
    the commit d979617aa84d ("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: 9ed9e9ba2337 ("bpf: Count the number of times recursion was prevented")
    Signed-off-by: He Fengqing <hefengqing@xxxxxxxxxx>
    Acked-by: John Fastabend <john.fastabend@xxxxxxxxx>
    Link: https://lore.kernel.org/r/20220122102936.1219518-1-hefengqing@xxxxxxxxxx
    Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
index 6933a9bfee637..2660fbced9ad4 100644
--- a/kernel/bpf/trampoline.c
+++ b/kernel/bpf/trampoline.c
@@ -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



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux