Skip to content

Commit

Permalink
ipv4: annotate data races arount inet->min_ttl
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eric Dumazet authored and Jakub Kicinski committed Oct 26, 2021
1 parent 790eb67 commit 14834c4
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion net/ipv4/ip_sockglue.c
Original file line number Diff line number Diff line change
@@ -1352,7 +1352,10 @@ static int do_ip_setsockopt(struct sock *sk, int level, int optname,
goto e_inval;
if (val < 0 || val > 255)
goto e_inval;
inet->min_ttl = val;
/* tcp_v4_err() and tcp_v4_rcv() might read min_ttl
* while we are changint it.
*/
WRITE_ONCE(inet->min_ttl, val);
break;

default:
7 changes: 5 additions & 2 deletions net/ipv4/tcp_ipv4.c
Original file line number Diff line number Diff line change
@@ -508,7 +508,8 @@ int tcp_v4_err(struct sk_buff *skb, u32 info)
if (sk->sk_state == TCP_CLOSE)
goto out;

if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
/* min_ttl can be changed concurrently from do_ip_setsockopt() */
if (unlikely(iph->ttl < READ_ONCE(inet_sk(sk)->min_ttl))) {
__NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP);
goto out;
}
@@ -2068,7 +2069,9 @@ int tcp_v4_rcv(struct sk_buff *skb)
return 0;
}
}
if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {

/* min_ttl can be changed concurrently from do_ip_setsockopt() */
if (unlikely(iph->ttl < READ_ONCE(inet_sk(sk)->min_ttl))) {
__NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP);
goto discard_and_relse;
}

0 comments on commit 14834c4

Please sign in to comment.