Skip to content

Commit 0947ae1

Browse files
q2venborkmann
authored andcommitted
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: ede95a6 ("bpf: add bpf_jit_limit knob to restrict unpriv allocations") Signed-off-by: Kuniyuki Iwashima <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 7d6620f commit 0947ae1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/bpf/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ pure_initcall(bpf_jit_charge_init);
971971

972972
int bpf_jit_charge_modmem(u32 size)
973973
{
974-
if (atomic_long_add_return(size, &bpf_jit_current) > bpf_jit_limit) {
974+
if (atomic_long_add_return(size, &bpf_jit_current) > READ_ONCE(bpf_jit_limit)) {
975975
if (!bpf_capable()) {
976976
atomic_long_sub(size, &bpf_jit_current);
977977
return -EPERM;

0 commit comments

Comments
 (0)