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

ipv4: annotate data races arount inet->min_ttl

No report yet from KCSAN, yet worth documenting the races.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
14834c4f 790eb673

+9 -3
+4 -1
net/ipv4/ip_sockglue.c
··· 1352 1352 goto e_inval; 1353 1353 if (val < 0 || val > 255) 1354 1354 goto e_inval; 1355 - inet->min_ttl = val; 1355 + /* tcp_v4_err() and tcp_v4_rcv() might read min_ttl 1356 + * while we are changint it. 1357 + */ 1358 + WRITE_ONCE(inet->min_ttl, val); 1356 1359 break; 1357 1360 1358 1361 default:
+5 -2
net/ipv4/tcp_ipv4.c
··· 508 508 if (sk->sk_state == TCP_CLOSE) 509 509 goto out; 510 510 511 - if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) { 511 + /* min_ttl can be changed concurrently from do_ip_setsockopt() */ 512 + if (unlikely(iph->ttl < READ_ONCE(inet_sk(sk)->min_ttl))) { 512 513 __NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP); 513 514 goto out; 514 515 } ··· 2069 2068 return 0; 2070 2069 } 2071 2070 } 2072 - if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) { 2071 + 2072 + /* min_ttl can be changed concurrently from do_ip_setsockopt() */ 2073 + if (unlikely(iph->ttl < READ_ONCE(inet_sk(sk)->min_ttl))) { 2073 2074 __NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP); 2074 2075 goto discard_and_relse; 2075 2076 }