Message ID | 20220706234003.66760-10-kuniyu@amazon.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 310731e2f1611d1d13aae237abcf8e66d33345d5 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | sysctl: Fix data-races around ipv4_table. | expand |
Hello, On 07/07/2022 01:40, Kuniyuki Iwashima wrote: > While reading .sysctl_mem, it can be changed concurrently. > So, we need to add READ_ONCE() to avoid data-races. FYI, we got a small conflict when merging -net in net-next in the MPTCP tree due to this patch applied in -net: 310731e2f161 ("net: Fix data-races around sysctl_mem.") and this one from net-next: e70f3c701276 ("Revert "net: set SK_MEM_QUANTUM to 4096"") The conflict has been resolved on our side[1] and the resolution we suggest is attached to this email. I'm sharing this thinking it can help others but if it only creates noise, please tell me! :) Cheers, Matt [1] https://github.com/multipath-tcp/mptcp_net-next/commit/b01bda9d0fe6
diff --git a/include/net/sock.h b/include/net/sock.h index 72ca97ccb460..9fa54762e077 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1529,7 +1529,7 @@ void __sk_mem_reclaim(struct sock *sk, int amount); /* sysctl_mem values are in pages, we convert them in SK_MEM_QUANTUM units */ static inline long sk_prot_mem_limits(const struct sock *sk, int index) { - long val = sk->sk_prot->sysctl_mem[index]; + long val = READ_ONCE(sk->sk_prot->sysctl_mem[index]); #if PAGE_SIZE > SK_MEM_QUANTUM val <<= PAGE_SHIFT - SK_MEM_QUANTUM_SHIFT;
While reading .sysctl_mem, it can be changed concurrently. So, we need to add READ_ONCE() to avoid data-races. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> --- include/net/sock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)