Skip to content

Commit ea7f45e

Browse files
edumazetdavem330
authored andcommitted
net: annotate data-races around sk->sk_max_pacing_rate
sk_getsockopt() runs locklessly. This means sk->sk_max_pacing_rate can be read while other threads are changing its value. Fixes: 62748f3 ("net: introduce SO_MAX_PACING_RATE") Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c76a032 commit ea7f45e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

net/core/sock.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,8 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
14391439
cmpxchg(&sk->sk_pacing_status,
14401440
SK_PACING_NONE,
14411441
SK_PACING_NEEDED);
1442-
sk->sk_max_pacing_rate = ulval;
1442+
/* Pairs with READ_ONCE() from sk_getsockopt() */
1443+
WRITE_ONCE(sk->sk_max_pacing_rate, ulval);
14431444
sk->sk_pacing_rate = min(sk->sk_pacing_rate, ulval);
14441445
break;
14451446
}
@@ -1903,12 +1904,14 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
19031904
#endif
19041905

19051906
case SO_MAX_PACING_RATE:
1907+
/* The READ_ONCE() pair with the WRITE_ONCE() in sk_setsockopt() */
19061908
if (sizeof(v.ulval) != sizeof(v.val) && len >= sizeof(v.ulval)) {
19071909
lv = sizeof(v.ulval);
1908-
v.ulval = sk->sk_max_pacing_rate;
1910+
v.ulval = READ_ONCE(sk->sk_max_pacing_rate);
19091911
} else {
19101912
/* 32bit version */
1911-
v.val = min_t(unsigned long, sk->sk_max_pacing_rate, ~0U);
1913+
v.val = min_t(unsigned long, ~0U,
1914+
READ_ONCE(sk->sk_max_pacing_rate));
19121915
}
19131916
break;
19141917

0 commit comments

Comments
 (0)