Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tcp: Fix data-races around sysctl_tcp_migrate_req.

While reading sysctl_tcp_migrate_req, it can be changed concurrently.
Thus, we need to add READ_ONCE() to its readers.

Fixes: f9ac779f881c ("net: Introduce net.ipv4.tcp_migrate_req.")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Kuniyuki Iwashima and committed by
David S. Miller
4177f545 f2e383b5

+2 -2
+2 -2
net/core/sock_reuseport.c
··· 387 387 prog = rcu_dereference_protected(reuse->prog, 388 388 lockdep_is_held(&reuseport_lock)); 389 389 390 - if (sock_net(sk)->ipv4.sysctl_tcp_migrate_req || 390 + if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_migrate_req) || 391 391 (prog && prog->expected_attach_type == BPF_SK_REUSEPORT_SELECT_OR_MIGRATE)) { 392 392 /* Migration capable, move sk from the listening section 393 393 * to the closed section. ··· 545 545 hash = migrating_sk->sk_hash; 546 546 prog = rcu_dereference(reuse->prog); 547 547 if (!prog || prog->expected_attach_type != BPF_SK_REUSEPORT_SELECT_OR_MIGRATE) { 548 - if (sock_net(sk)->ipv4.sysctl_tcp_migrate_req) 548 + if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_migrate_req)) 549 549 goto select_by_hash; 550 550 goto failure; 551 551 }