tcp: annotate data-races around tp->keepalive_time
[ Upstream commit 4164245c76ff906c9086758e1c3f87082a7f5ef5 ]
do_tcp_getsockopt() reads tp->keepalive_time while another cpu
might change its value.
Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20230719212857.3943972-4-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
2c84a3d78a
commit
87b8466eb0
2 changed files with 7 additions and 3 deletions
|
|
@ -1519,9 +1519,12 @@ static inline int keepalive_intvl_when(const struct tcp_sock *tp)
|
||||||
static inline int keepalive_time_when(const struct tcp_sock *tp)
|
static inline int keepalive_time_when(const struct tcp_sock *tp)
|
||||||
{
|
{
|
||||||
struct net *net = sock_net((struct sock *)tp);
|
struct net *net = sock_net((struct sock *)tp);
|
||||||
|
int val;
|
||||||
|
|
||||||
return tp->keepalive_time ? :
|
/* Paired with WRITE_ONCE() in tcp_sock_set_keepidle_locked() */
|
||||||
READ_ONCE(net->ipv4.sysctl_tcp_keepalive_time);
|
val = READ_ONCE(tp->keepalive_time);
|
||||||
|
|
||||||
|
return val ? : READ_ONCE(net->ipv4.sysctl_tcp_keepalive_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int keepalive_probes(const struct tcp_sock *tp)
|
static inline int keepalive_probes(const struct tcp_sock *tp)
|
||||||
|
|
|
||||||
|
|
@ -3418,7 +3418,8 @@ int tcp_sock_set_keepidle_locked(struct sock *sk, int val)
|
||||||
if (val < 1 || val > MAX_TCP_KEEPIDLE)
|
if (val < 1 || val > MAX_TCP_KEEPIDLE)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
tp->keepalive_time = val * HZ;
|
/* Paired with WRITE_ONCE() in keepalive_time_when() */
|
||||||
|
WRITE_ONCE(tp->keepalive_time, val * HZ);
|
||||||
if (sock_flag(sk, SOCK_KEEPOPEN) &&
|
if (sock_flag(sk, SOCK_KEEPOPEN) &&
|
||||||
!((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))) {
|
!((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))) {
|
||||||
u32 elapsed = keepalive_time_elapsed(tp);
|
u32 elapsed = keepalive_time_elapsed(tp);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue