From: Simon Horman <horms@kernel.org>
To: Eric Dumazet <edumazet@google.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, Neal Cardwell <ncardwell@google.com>,
eric.dumazet@gmail.com, David Ahern <dsahern@kernel.org>
Subject: Re: [PATCH net] tcp: fix race in tcp_v6_syn_recv_sock()
Date: Sat, 8 Jun 2024 14:25:44 +0100 [thread overview]
Message-ID: <20240608132544.GF27689@kernel.org> (raw)
In-Reply-To: <20240606154652.360331-1-edumazet@google.com>
+ David Ahern
On Thu, Jun 06, 2024 at 03:46:51PM +0000, Eric Dumazet wrote:
> tcp_v6_syn_recv_sock() calls ip6_dst_store() before
> inet_sk(newsk)->pinet6 has been set up.
>
> This means ip6_dst_store() writes over the parent (listener)
> np->dst_cookie.
>
> This is racy because multiple threads could share the same
> parent and their final np->dst_cookie could be wrong.
>
> Move ip6_dst_store() call after inet_sk(newsk)->pinet6
> has been changed and after the copy of parent ipv6_pinfo.
>
> Fixes: e994b2f0fb92 ("tcp: do not lock listener to process SYN packets")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Simon Horman <horms@kernel.org>
> ---
> net/ipv6/tcp_ipv6.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
> index 8c577b651bfcd2f94b45e339ed4a2b47e93ff17a..729faf8bd366ad25d093a4ae931fb46ebd45b79c 100644
> --- a/net/ipv6/tcp_ipv6.c
> +++ b/net/ipv6/tcp_ipv6.c
> @@ -1439,7 +1439,6 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *
> */
>
> newsk->sk_gso_type = SKB_GSO_TCPV6;
> - ip6_dst_store(newsk, dst, NULL, NULL);
> inet6_sk_rx_dst_set(newsk, skb);
>
> inet_sk(newsk)->pinet6 = tcp_inet6_sk(newsk);
> @@ -1450,6 +1449,8 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *
>
> memcpy(newnp, np, sizeof(struct ipv6_pinfo));
>
> + ip6_dst_store(newsk, dst, NULL, NULL);
> +
> newsk->sk_v6_daddr = ireq->ir_v6_rmt_addr;
> newnp->saddr = ireq->ir_v6_loc_addr;
> newsk->sk_v6_rcv_saddr = ireq->ir_v6_loc_addr;
> --
> 2.45.1.467.gbab1589fc0-goog
>
>
next prev parent reply other threads:[~2024-06-08 13:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-06 15:46 [PATCH net] tcp: fix race in tcp_v6_syn_recv_sock() Eric Dumazet
2024-06-08 13:25 ` Simon Horman [this message]
2024-06-10 15:30 ` David Ahern
2024-06-10 12:20 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240608132544.GF27689@kernel.org \
--to=horms@kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=kuba@kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).