From: Kuniyuki Iwashima Date: Tue, 23 Aug 2022 21:58:04 +0000 (-0700) Subject: bpf: Fix a data-race around bpf_jit_limit. X-Git-Tag: v6.1-rc5~503^2~26^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0947ae1121083d363d522ff7518ee72b55bd8d29;p=platform%2Fkernel%2Flinux-starfive.git bpf: Fix a data-race around bpf_jit_limit. While reading bpf_jit_limit, it can be changed concurrently via sysctl, WRITE_ONCE() in __do_proc_doulongvec_minmax(). The size of bpf_jit_limit is long, so we need to add a paired READ_ONCE() to avoid load-tearing. Fixes: ede95a63b5e8 ("bpf: add bpf_jit_limit knob to restrict unpriv allocations") Signed-off-by: Kuniyuki Iwashima Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20220823215804.2177-1-kuniyu@amazon.com --- diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index c1e10d0..3d9eb3a 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -971,7 +971,7 @@ pure_initcall(bpf_jit_charge_init); int bpf_jit_charge_modmem(u32 size) { - if (atomic_long_add_return(size, &bpf_jit_current) > bpf_jit_limit) { + if (atomic_long_add_return(size, &bpf_jit_current) > READ_ONCE(bpf_jit_limit)) { if (!bpf_capable()) { atomic_long_sub(size, &bpf_jit_current); return -EPERM;