Skip to content

Commit

Permalink
tcp: fix races in tcp_v[46]_err()
Browse files Browse the repository at this point in the history
These functions have races when they:

1) Write sk->sk_err
2) call sk_error_report(sk)
3) call tcp_done(sk)

As described in prior patches in this series:

An smp_wmb() is missing.
We should call tcp_done() before sk_error_report(sk)
to have consistent tcp_poll() results on SMP hosts.

Use tcp_done_with_error() where we centralized the
correct sequence.

Fixes: 1da177e ("Linux-2.6.12-rc2")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Link: https://lore.kernel.org/r/20240528125253.1966136-5-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Eric Dumazet authored and Jakub Kicinski committed May 30, 2024
1 parent 5ce4645 commit fde6f89
Showing 2 changed files with 6 additions and 15 deletions.
11 changes: 3 additions & 8 deletions net/ipv4/tcp_ipv4.c
Original file line number Diff line number Diff line change
@@ -611,15 +611,10 @@ int tcp_v4_err(struct sk_buff *skb, u32 info)

ip_icmp_error(sk, skb, err, th->dest, info, (u8 *)th);

if (!sock_owned_by_user(sk)) {
WRITE_ONCE(sk->sk_err, err);

sk_error_report(sk);

tcp_done(sk);
} else {
if (!sock_owned_by_user(sk))
tcp_done_with_error(sk, err);
else
WRITE_ONCE(sk->sk_err_soft, err);
}
goto out;
}

10 changes: 3 additions & 7 deletions net/ipv6/tcp_ipv6.c
Original file line number Diff line number Diff line change
@@ -490,14 +490,10 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,

ipv6_icmp_error(sk, skb, err, th->dest, ntohl(info), (u8 *)th);

if (!sock_owned_by_user(sk)) {
WRITE_ONCE(sk->sk_err, err);
sk_error_report(sk); /* Wake people up to see the error (see connect in sock.c) */

tcp_done(sk);
} else {
if (!sock_owned_by_user(sk))
tcp_done_with_error(sk, err);
else
WRITE_ONCE(sk->sk_err_soft, err);
}
goto out;
case TCP_LISTEN:
break;

0 comments on commit fde6f89

Please sign in to comment.