diff options
author | Kuniyuki Iwashima <kuniyu@amazon.com> | 2022-08-23 10:46:49 -0700 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2022-08-24 13:46:57 +0100 |
commit | 7de6d09f51917c829af2b835aba8bb5040f8e86a (patch) | |
tree | 89c4f938d7771f6a35cc25e7e2c3db1d6566f293 /net/core/bpf_sk_storage.c | |
parent | 6bae8ceb90ba76cdba39496db936164fa672b9be (diff) |
net: Fix data-races around sysctl_optmem_max.
While reading sysctl_optmem_max, it can be changed concurrently.
Thus, we need to add READ_ONCE() to its readers.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/bpf_sk_storage.c')
-rw-r--r-- | net/core/bpf_sk_storage.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c index 1b7f385643b4..94374d529ea4 100644 --- a/net/core/bpf_sk_storage.c +++ b/net/core/bpf_sk_storage.c @@ -310,11 +310,12 @@ BPF_CALL_2(bpf_sk_storage_delete, struct bpf_map *, map, struct sock *, sk) static int bpf_sk_storage_charge(struct bpf_local_storage_map *smap, void *owner, u32 size) { + int optmem_max = READ_ONCE(sysctl_optmem_max); struct sock *sk = (struct sock *)owner; /* same check as in sock_kmalloc() */ - if (size <= sysctl_optmem_max && - atomic_read(&sk->sk_omem_alloc) + size < sysctl_optmem_max) { + if (size <= optmem_max && + atomic_read(&sk->sk_omem_alloc) + size < optmem_max) { atomic_add(size, &sk->sk_omem_alloc); return 0; } |