lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANn89iJDxA5nCTiw9SzHVfzhz2F124Z_PMEf_oJz3DGAp=UeOQ@mail.gmail.com>
Date: Fri, 19 Apr 2024 19:31:58 +0200
From: Eric Dumazet <edumazet@...gle.com>
To: Jonathan Heathcote <jonathan.heathcote@....co.uk>
Cc: "netdev@...r.kernel.org" <netdev@...r.kernel.org>, 
	"regressions@...ts.linux.dev" <regressions@...ts.linux.dev>
Subject: Re: [REGRESSION] sk_memory_allocated counter leaking on aarch64

On Fri, Apr 19, 2024 at 5:59 PM Jonathan Heathcote
<jonathan.heathcote@....co.uk> wrote:
>
> I'm very sorry but I won't be able to give this a try until Wednesday next week (I'm currently working part time) but I'll give this a go first-thing. Thank you very much for your swift response!

SGTM, I rewrote the patch to remove the not needed
preempt_disable()/preempt_enable()

I will test it soon.

diff --git a/include/net/sock.h b/include/net/sock.h
index f57bfd8a2ad2deaedf3f351325ab9336ae040504..bae62604c5ffc8a3ecbe3e996b87c9fb25914c0f
100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1410,32 +1410,34 @@ sk_memory_allocated(const struct sock *sk)
 #define SK_MEMORY_PCPU_RESERVE (1 << (20 - PAGE_SHIFT))
 extern int sysctl_mem_pcpu_rsv;

+static inline void sk_memory_pcpu_drain(const struct proto *proto)
+{
+       int val = this_cpu_xchg(*proto->per_cpu_fw_alloc, 0);
+
+       if (val)
+               atomic_long_add(val, proto->memory_allocated);
+}
+
 static inline void
 sk_memory_allocated_add(struct sock *sk, int amt)
 {
-       int local_reserve;
+       int val;

-       preempt_disable();
-       local_reserve =
__this_cpu_add_return(*sk->sk_prot->per_cpu_fw_alloc, amt);
-       if (local_reserve >= READ_ONCE(sysctl_mem_pcpu_rsv)) {
-               __this_cpu_sub(*sk->sk_prot->per_cpu_fw_alloc, local_reserve);
-               atomic_long_add(local_reserve, sk->sk_prot->memory_allocated);
-       }
-       preempt_enable();
+       val = this_cpu_add_return(*sk->sk_prot->per_cpu_fw_alloc, amt);
+
+       if (unlikely(val >= READ_ONCE(sysctl_mem_pcpu_rsv)))
+               sk_memory_pcpu_drain(sk->sk_prot);
 }

 static inline void
 sk_memory_allocated_sub(struct sock *sk, int amt)
 {
-       int local_reserve;
+       int val;

-       preempt_disable();
-       local_reserve =
__this_cpu_sub_return(*sk->sk_prot->per_cpu_fw_alloc, amt);
-       if (local_reserve <= -READ_ONCE(sysctl_mem_pcpu_rsv)) {
-               __this_cpu_sub(*sk->sk_prot->per_cpu_fw_alloc, local_reserve);
-               atomic_long_add(local_reserve, sk->sk_prot->memory_allocated);
-       }
-       preempt_enable();
+       val = this_cpu_sub_return(*sk->sk_prot->per_cpu_fw_alloc, amt);
+
+       if (unlikely(val <= -READ_ONCE(sysctl_mem_pcpu_rsv)))
+               sk_memory_pcpu_drain(sk->sk_prot);
 }

 #define SK_ALLOC_PERCPU_COUNTER_BATCH 16

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ