bpf: Fix a data-race around bpf_jit_limit.
Subsystems (4)
PATCH v2 1/1 bpf: Fix a data-race around bpf_jit_limit.
While reading bpf_jit_limit, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader.
---
v2:
* Drop other 3 patches (No change for this patch)
v1: https://lore.kernel.org/bpf/[email protected]/
--- kernel/bpf/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/core.c +1 -1
@@ -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 ;
Signature · 1 line
2.30.2
Daniel Borkmann
maintainerQuoted 2 lines · Kuniyuki Iwashima
While reading
bpf_jit_limit, it can be changed concurrently. Thus, we need to addREAD_ONCE()to its reader.
For sake of a better/clearer commit message, please also provide data about the WRITE_ONCE() pairing that this READ_ONCE() targets. This seems to be the case in __do_proc_doulongvec_minmax() as far as I can see. For your 2nd sentence above please also include load-tearing as main motivation for your fix.
Quoted 25 lines
Fixes ede95a63b5e8 ("bpf: add bpf_jit_limit knob to restrict unpriv allocations")Signed-off-by Kuniyuki Iwashima <[email protected]>---
v2:
* Drop other 3 patches (No change for this patch)v1: https://lore.kernel.org/bpf/[email protected]/
--- kernel/bpf/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/bpf/core.c +1
-1@@ -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 ;
From: Daniel Borkmann <[email protected]> Date: Tue, 23 Aug 2022 23:20:29 +0200
Quoted 8 lines · Kuniyuki Iwashima
Quoted 2 lines
While reading
bpf_jit_limit, it can be changed concurrently. Thus, we need to addREAD_ONCE()to its reader.For sake of a better/clearer commit message, please also provide data about the
WRITE_ONCE()pairing that thisREAD_ONCE()targets. This seems to be the case in__do_proc_doulongvec_minmax()as far as I can see. For your 2nd sentence above please also include load-tearing as main motivation for your fix.
I'll add better description.
Thank you!
Quoted 26 lines
Quoted 26 lines
Fixes ede95a63b5e8 ("bpf: add bpf_jit_limit knob to restrict unpriv allocations")Signed-off-by Kuniyuki Iwashima <[email protected]>---
v2:
* Drop other 3 patches (No change for this patch)v1: https://lore.kernel.org/bpf/[email protected]/
--- kernel/bpf/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/bpf/core.c +1
-1@@ -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 ;