From: Wang Hai <wanghai38@huawei.com>
To: Eric Dumazet <edumazet@google.com>
Cc: <ncardwell@google.com>, <kuniyu@amazon.com>,
<davem@davemloft.net>, <dsahern@kernel.org>, <kuba@kernel.org>,
<pabeni@redhat.com>, <horms@kernel.org>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
Jason Xing <kerneljasonxing@gmail.com>
Subject: Re: [PATCH net] tcp: Fix error ts_recent time during three-way handshake
Date: Wed, 19 Feb 2025 11:08:30 +0800 [thread overview]
Message-ID: <4dff834e-f652-447c-a1f0-bfd851449f70@huawei.com> (raw)
In-Reply-To: <CANn89iKF+LC_isruAAd+nyxgytr4LPeFTe9=ey0j=Xy5URMvkg@mail.gmail.com>
On 2025/2/18 21:35, Eric Dumazet wrote:
> On Tue, Feb 18, 2025 at 12:00 PM Wang Hai <wanghai38@huawei.com> wrote:
>>
>> If two ack packets from a connection enter tcp_check_req at the same time
>> through different cpu, it may happen that req->ts_recent is updated with
>> with a more recent time and the skb with an older time creates a new sock,
>> which will cause the tcp_validate_incoming check to fail.
>>
>> cpu1 cpu2
>> tcp_check_req
>> tcp_check_req
>> req->ts_recent = tmp_opt.rcv_tsval = t1
>> req->ts_recent = tmp_opt.rcv_tsval = t2
>>
>> newsk->ts_recent = req->ts_recent = t2 // t1 < t2
>> tcp_child_process
>> tcp_rcv_state_process
>> tcp_validate_incoming
>> tcp_paws_check
>> if ((s32)(rx_opt->ts_recent - rx_opt->rcv_tsval) <= paws_win) // failed
>>
>> In tcp_check_req, restore ts_recent to this skb's to fix this bug.
>>
>> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>> Signed-off-by: Wang Hai <wanghai38@huawei.com>
>> ---
>> net/ipv4/tcp_minisocks.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
>> index b089b08e9617..0208455f9eb8 100644
>> --- a/net/ipv4/tcp_minisocks.c
>> +++ b/net/ipv4/tcp_minisocks.c
>> @@ -878,6 +878,10 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
>> sock_rps_save_rxhash(child, skb);
>> tcp_synack_rtt_meas(child, req);
>> *req_stolen = !own_req;
>> + if (own_req && tcp_sk(child)->rx_opt.tstamp_ok &&
>> + unlikely(tcp_sk(child)->rx_opt.ts_recent != tmp_opt.rcv_tsval))
>> + tcp_sk(child)->rx_opt.ts_recent = tmp_opt.rcv_tsval;
>> +
>> return inet_csk_complete_hashdance(sk, child, req, own_req);
>
> Have you seen the comment at line 818 ?
>
> /* TODO: We probably should defer ts_recent change once
> * we take ownership of @req.
> */
>
> Plan was clear and explained. Why implement something else (and buggy) ?
Hi Eric,
According to the plan, can we fix it like this?
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index b089b08e9617..1210d4967b94 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -814,13 +814,6 @@ struct sock *tcp_check_req(struct sock *sk, struct
sk_buff *skb,
}
/* In sequence, PAWS is OK. */
-
- /* TODO: We probably should defer ts_recent change once
- * we take ownership of @req.
- */
- if (tmp_opt.saw_tstamp && !after(TCP_SKB_CB(skb)->seq,
tcp_rsk(req)->rcv_nxt))
- WRITE_ONCE(req->ts_recent, tmp_opt.rcv_tsval);
-
if (TCP_SKB_CB(skb)->seq == tcp_rsk(req)->rcv_isn) {
/* Truncate SYN, it is out of window starting
at tcp_rsk(req)->rcv_isn + 1. */
@@ -878,6 +871,9 @@ struct sock *tcp_check_req(struct sock *sk, struct
sk_buff *skb,
sock_rps_save_rxhash(child, skb);
tcp_synack_rtt_meas(child, req);
*req_stolen = !own_req;
+ if (own_req && tmp_opt.saw_tstamp && !after(TCP_SKB_CB(skb)-
seq, tcp_rsk(req)->rcv_nxt))
+ tcp_sk(child)->rx_opt.ts_recent = tmp_opt.rcv_tsval;
+
return inet_csk_complete_hashdance(sk, child, req, own_req);
listen_overflow:
>
next prev parent reply other threads:[~2025-02-19 3:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-18 10:58 Wang Hai
2025-02-18 12:02 ` Jason Xing
2025-02-19 2:09 ` Wang Hai
2025-02-18 13:35 ` Eric Dumazet
2025-02-19 2:16 ` Wang Hai
2025-02-19 3:31 ` Jason Xing
2025-02-19 13:11 ` Wang Hai
2025-02-20 3:04 ` Jason Xing
2025-02-20 14:03 ` Wang Hai
2025-02-20 14:45 ` Jason Xing
2025-02-19 3:08 ` Wang Hai [this message]
2025-02-20 8:41 ` Eric Dumazet
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=4dff834e-f652-447c-a1f0-bfd851449f70@huawei.com \
--to=wanghai38@huawei.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kerneljasonxing@gmail.com \
--cc=kuba@kernel.org \
--cc=kuniyu@amazon.com \
--cc=linux-kernel@vger.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
all inboxes | Powered by JetHome®