Commit ba632ad0 authored by Kuniyuki Iwashima's avatar Kuniyuki Iwashima Committed by Greg Kroah-Hartman
Browse files

bpf: Fix a data-race around bpf_jit_limit.



[ Upstream commit 0947ae11 ]

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: ede95a63 ("bpf: add bpf_jit_limit knob to restrict unpriv allocations")
Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220823215804.2177-1-kuniyu@amazon.com


Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 15f3b89b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1005,7 +1005,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;