tcp: fix TCP_SKB_CB(skb)->tcp_tw_isn not being used
Subsystems (3)
PATCH 1/1 tcp: fix TCP_SKB_CB(skb)->tcp_tw_isn not being used
TCP_SKB_CB(skb)->tcp_tw_isn contains an ISN, chosen by tcp_timewait_state_process() , when SYN is received in TIMEWAIT state. But tcp_tw_isn is not used because it is overwritten by tcp_v4_restore_cb() after commit eeea10b83a13 ("tcp: add tcp_v4_fill_cb()/tcp_v4_restore_cb()").
To fix this case, we record tcp_tw_isn before tcp_v4_restore_cb() and then set it in tcp_v4_fill_cb(). V6 does the same.
--- net/ipv4/tcp_ipv4.c | 14 ++++++++------ net/ipv6/tcp_ipv6.c | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-)
net/ipv4/tcp_ipv4.c +8 -6
@@ -1892,7 +1892,7 @@ static void tcp_v4_restore_cb(struct sk_buff *skb) }static void tcp_v4_fill_cb (struct sk_buff *skb,const struct iphdr *iph, -const struct tcphdr *th) +const struct tcphdr *th,__u32 isn) {/* This is tricky : We move IPCB at its correct location into TCP_SKB_CB() * barrier() makes sure compiler wont play fool^Waliasing games.
@@ -1906,7 +1906,7 @@ static void tcp_v4_fill_cb(struct sk_buff *skb, const struct iphdr *iph, skb->len - th->doff * 4);TCP_SKB_CB (skb)->ack_seq =ntohl (th->ack_seq);TCP_SKB_CB (skb)->tcp_flags =tcp_flag_byte (th); -TCP_SKB_CB (skb)->tcp_tw_isn =0 ; +TCP_SKB_CB (skb)->tcp_tw_isn = isn;TCP_SKB_CB (skb)->ip_dsfield =ipv4_get_dsfield (iph);TCP_SKB_CB (skb)->sacked =0 ; TCP_SKB_CB(skb)->has_rxtstamp =
@@ -1927,6 +1927,7 @@ int tcp_v4_rcv(struct sk_buff *skb)const struct tcphdr *th;bool refcounted;struct sock *sk; +__u32 isn =0 ;int ret;if (skb->pkt_type !=PACKET_HOST )
@@ -1993,7 +1994,7 @@ int tcp_v4_rcv(struct sk_buff *skb)if (!tcp_filter (sk, skb)) { th = (const struct tcphdr *)skb->data; iph =ip_hdr (skb); -tcp_v4_fill_cb (skb, iph, th); +tcp_v4_fill_cb (skb, iph, th, isn); nsk =tcp_check_req (sk, skb, req, false, &req_stolen); }if (!nsk) {
@@ -2038,7 +2039,7 @@ int tcp_v4_rcv(struct sk_buff *skb) goto discard_and_relse; th = (const struct tcphdr *)skb->data; iph =ip_hdr (skb); -tcp_v4_fill_cb (skb, iph, th); +tcp_v4_fill_cb (skb, iph, th, isn); skb->dev =NULL ;
@@ -2075,7 +2076,7 @@ int tcp_v4_rcv(struct sk_buff *skb)if (!xfrm4_policy_check (NULL ,XFRM_POLICY_IN , skb)) goto discard_it; -tcp_v4_fill_cb (skb, iph, th); +tcp_v4_fill_cb (skb, iph, th, isn);if (tcp_checksum_complete (skb)) { csum_error:
@@ -2103,7 +2104,7 @@ int tcp_v4_rcv(struct sk_buff *skb) goto discard_it; } -tcp_v4_fill_cb (skb, iph, th); +tcp_v4_fill_cb (skb, iph, th, isn);if (tcp_checksum_complete (skb)) {inet_twsk_put (inet_twsk (sk));
@@ -2121,6 +2122,7 @@ int tcp_v4_rcv(struct sk_buff *skb)if (sk2) {inet_twsk_deschedule_put (inet_twsk (sk)); sk = sk2; + isn =TCP_SKB_CB (skb)->tcp_tw_isn;tcp_v4_restore_cb (skb); refcounted = false; goto process;
net/ipv6/tcp_ipv6.c +8 -6
@@ -1557,7 +1557,7 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) }static void tcp_v6_fill_cb (struct sk_buff *skb,const struct ipv6hdr *hdr, -const struct tcphdr *th) +const struct tcphdr *th,__u32 isn) {/* This is tricky: we move IP6CB at its correct location into * TCP_SKB_CB(). It must be done after xfrm6_policy_check(), because
@@ -1573,7 +1573,7 @@ static void tcp_v6_fill_cb(struct sk_buff *skb, const struct ipv6hdr *hdr, skb->len - th->doff*4);TCP_SKB_CB (skb)->ack_seq =ntohl (th->ack_seq);TCP_SKB_CB (skb)->tcp_flags =tcp_flag_byte (th); -TCP_SKB_CB (skb)->tcp_tw_isn =0 ; +TCP_SKB_CB (skb)->tcp_tw_isn = isn;TCP_SKB_CB (skb)->ip_dsfield =ipv6_get_dsfield (hdr);TCP_SKB_CB (skb)->sacked =0 ; TCP_SKB_CB(skb)->has_rxtstamp =
@@ -1589,6 +1589,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)const struct ipv6hdr *hdr;bool refcounted;struct sock *sk; +__u32 isn =0 ;int ret;struct net *net =dev_net (skb->dev);
@@ -1652,7 +1653,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)if (!tcp_filter (sk, skb)) { th = (const struct tcphdr *)skb->data; hdr =ipv6_hdr (skb); -tcp_v6_fill_cb (skb, hdr, th); +tcp_v6_fill_cb (skb, hdr, th, isn); nsk =tcp_check_req (sk, skb, req, false, &req_stolen); }if (!nsk) {
@@ -1695,7 +1696,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) goto discard_and_relse; th = (const struct tcphdr *)skb->data; hdr =ipv6_hdr (skb); -tcp_v6_fill_cb (skb, hdr, th); +tcp_v6_fill_cb (skb, hdr, th, isn); skb->dev =NULL ;
@@ -1730,7 +1731,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)if (!xfrm6_policy_check (NULL ,XFRM_POLICY_IN , skb)) goto discard_it; -tcp_v6_fill_cb (skb, hdr, th); +tcp_v6_fill_cb (skb, hdr, th, isn);if (tcp_checksum_complete (skb)) { csum_error:
@@ -1757,7 +1758,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) goto discard_it; } -tcp_v6_fill_cb (skb, hdr, th); +tcp_v6_fill_cb (skb, hdr, th, isn);if (tcp_checksum_complete (skb)) {inet_twsk_put (inet_twsk (sk));
@@ -1780,6 +1781,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)struct inet_timewait_sock *tw =inet_twsk (sk);inet_twsk_deschedule_put (tw); sk = sk2; + isn =TCP_SKB_CB (skb)->tcp_tw_isn;tcp_v6_restore_cb (skb); refcounted = false; goto process;
Signature · 1 line
1.8.3.1
Jakub Kicinski
maintainerQuoted 6 lines · On Tue, 29 Dec 2020 05:59:20 +0800 Pengcheng Yang wrote:
TCP_SKB_CB(skb)->tcp_tw_isn contains an ISN, chosen by
tcp_timewait_state_process(), when SYN is received in TIMEWAIT state. Buttcp_tw_isnis not used because it is overwritten bytcp_v4_restore_cb()after commiteeea10b83a13("tcp: add tcp_v4_fill_cb()/tcp_v4_restore_cb()").
Quoted 6 lines
To fix this case, we record
tcp_tw_isnbeforetcp_v4_restore_cb()and then set it intcp_v4_fill_cb(). V6 does the same.Fixes eeea10b83a13 ("tcp: add tcp_v4_fill_cb()/tcp_v4_restore_cb()")Reported-by chenc <[email protected]>Signed-off-by Pengcheng Yang <[email protected]>
Please fix the date and resend. This patch came in last night, but it has a date of December 28th.
Quoted 11 lines · Jakub Kicinski
Quoted 9 lines · On Tue, 29 Dec 2020 05:59:20 +0800 Pengcheng Yang wrote:
TCP_SKB_CB(skb)->tcp_tw_isn contains an ISN, chosen by
tcp_timewait_state_process(), when SYN is received in TIMEWAIT state. Buttcp_tw_isnis not used because it is overwritten bytcp_v4_restore_cb()after commiteeea10b83a13("tcp: add tcp_v4_fill_cb()/tcp_v4_restore_cb()").To fix this case, we record
tcp_tw_isnbeforetcp_v4_restore_cb()and then set it intcp_v4_fill_cb(). V6 does the same.
Quoted 6 lines
Quoted 3 lines
Fixes eeea10b83a13 ("tcp: add tcp_v4_fill_cb()/tcp_v4_restore_cb()")Reported-by chenc <[email protected]>Signed-off-by Pengcheng Yang <[email protected]>Please fix the date and resend. This patch came in last night, but it has a date of December 28th.
Not this whole madness about tcp_v4_fill_cb()/tcp_v4_restore_cb() could be reverted
now we have an RB tree for out-of-order packets.
Quoted 17 lines · Eric Dumazet
Quoted 15 lines · Jakub Kicinski
Quoted 12 lines · On Tue, 29 Dec 2020 05:59:20 +0800 Pengcheng Yang wrote:
TCP_SKB_CB(skb)->tcp_tw_isn contains an ISN, chosen by
tcp_timewait_state_process(), when SYN is received in TIMEWAIT state. Buttcp_tw_isnis not used because it is overwritten bytcp_v4_restore_cb()after commiteeea10b83a13("tcp: add tcp_v4_fill_cb()/tcp_v4_restore_cb()").To fix this case, we record
tcp_tw_isnbeforetcp_v4_restore_cb()and then set it intcp_v4_fill_cb(). V6 does the same.Fixes eeea10b83a13 ("tcp: add tcp_v4_fill_cb()/tcp_v4_restore_cb()")Reported-by chenc <[email protected]>Signed-off-by Pengcheng Yang <[email protected]>
Quoted 5 lines
Quoted 2 lines
Please fix the date and resend. This patch came in last night, but it has a date of December 28th.
Not this whole madness about tcp_v4_fill_cb()/tcp_v4_restore_cb() could be reverted
This makes isn always been 0 in tcp_conn_request(), because tcp_tw_isn is always initialized to 0 in tcp_v4_fill_cb() and tcp_tw_isn becomes meaningless. Do we need to make tcp_tw_isn work again?
Quoted 1 line
now we have an RB tree for out-of-order packets.
I don't quite understand how setting tcp_tw_isn for SYN would affect out_of_order_queue?