* [PATCH net-next 0/5] tcp: support rstreasons in the passive logic
@ 2024-05-09 13:13 Jason Xing
2024-05-09 13:13 ` [PATCH net-next 1/5] tcp: fully support sk reset reasons in tcp_rcv_synsent_state_process() Jason Xing
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Jason Xing @ 2024-05-09 13:13 UTC (permalink / raw)
To: edumazet, dsahern, kuba, pabeni, davem
Cc: netdev, kerneljasonxing, Jason Xing
From: Jason Xing <kernelxing@tencent.com>
In this series, I split all kinds of reasons into five part which, I
think, can be easily reviewed. I respectively implement corresponding
rstreasons in those functions. After this, we can trace the whole tcp
passive reset with clear reasons.
Jason Xing (5):
tcp: fully support sk reset reasons in tcp_rcv_synsent_state_process()
tcp: fully support sk reset reason in tcp_ack()
tcp: fully support sk reset reason in tcp_rcv_state_process()
tcp: handle timewait cases in rstreason logic
tcp: handle rstreason in tcp_check_req()
include/net/rstreason.h | 58 ++++++++++++++++++++++++++++++++++++++++
net/ipv4/tcp_ipv4.c | 2 +-
net/ipv4/tcp_minisocks.c | 2 +-
net/ipv6/tcp_ipv6.c | 2 +-
4 files changed, 61 insertions(+), 3 deletions(-)
--
2.37.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net-next 1/5] tcp: fully support sk reset reasons in tcp_rcv_synsent_state_process()
2024-05-09 13:13 [PATCH net-next 0/5] tcp: support rstreasons in the passive logic Jason Xing
@ 2024-05-09 13:13 ` Jason Xing
2024-05-09 13:13 ` [PATCH net-next 2/5] tcp: fully support sk reset reason in tcp_ack() Jason Xing
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Jason Xing @ 2024-05-09 13:13 UTC (permalink / raw)
To: edumazet, dsahern, kuba, pabeni, davem
Cc: netdev, kerneljasonxing, Jason Xing
From: Jason Xing <kernelxing@tencent.com>
In this function, only updating the map can finish the job for socket
reset reason because the corresponding drop reasons are ready.
Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
include/net/rstreason.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/include/net/rstreason.h b/include/net/rstreason.h
index df3b6ac0c9b3..f87814a60205 100644
--- a/include/net/rstreason.h
+++ b/include/net/rstreason.h
@@ -8,6 +8,8 @@
#define DEFINE_RST_REASON(FN, FNe) \
FN(NOT_SPECIFIED) \
FN(NO_SOCKET) \
+ FN(TCP_INVALID_ACK_SEQUENCE) \
+ FN(TCP_RFC7323_PAWS) \
FN(MPTCP_RST_EUNSPEC) \
FN(MPTCP_RST_EMPTCP) \
FN(MPTCP_RST_ERESOURCE) \
@@ -37,6 +39,17 @@ enum sk_rst_reason {
SK_RST_REASON_NOT_SPECIFIED,
/** @SK_RST_REASON_NO_SOCKET: no valid socket that can be used */
SK_RST_REASON_NO_SOCKET,
+ /**
+ * @SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE: Not acceptable ACK SEQ
+ * field because ack sequence is not in the window between snd_una
+ * and snd_nxt
+ */
+ SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE,
+ /**
+ * @SK_RST_REASON_TCP_RFC7323_PAWS: PAWS check, corresponding to
+ * LINUX_MIB_PAWSESTABREJECTED, LINUX_MIB_PAWSACTIVEREJECTED
+ */
+ SK_RST_REASON_TCP_RFC7323_PAWS,
/* Copy from include/uapi/linux/mptcp.h.
* These reset fields will not be changed since they adhere to
@@ -113,6 +126,10 @@ sk_rst_convert_drop_reason(enum skb_drop_reason reason)
return SK_RST_REASON_NOT_SPECIFIED;
case SKB_DROP_REASON_NO_SOCKET:
return SK_RST_REASON_NO_SOCKET;
+ case SKB_DROP_REASON_TCP_INVALID_ACK_SEQUENCE:
+ return SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE;
+ case SKB_DROP_REASON_TCP_RFC7323_PAWS:
+ return SK_RST_REASON_TCP_RFC7323_PAWS;
default:
/* If we don't have our own corresponding reason */
return SK_RST_REASON_NOT_SPECIFIED;
--
2.37.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net-next 2/5] tcp: fully support sk reset reason in tcp_ack()
2024-05-09 13:13 [PATCH net-next 0/5] tcp: support rstreasons in the passive logic Jason Xing
2024-05-09 13:13 ` [PATCH net-next 1/5] tcp: fully support sk reset reasons in tcp_rcv_synsent_state_process() Jason Xing
@ 2024-05-09 13:13 ` Jason Xing
2024-05-10 2:08 ` Jason Xing
2024-05-09 13:13 ` [PATCH net-next 3/5] tcp: fully support sk reset reason in tcp_rcv_state_process() Jason Xing
` (2 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: Jason Xing @ 2024-05-09 13:13 UTC (permalink / raw)
To: edumazet, dsahern, kuba, pabeni, davem
Cc: netdev, kerneljasonxing, Jason Xing
From: Jason Xing <kernelxing@tencent.com>
Based on the existing skb drop reason, updating the rstreason map can
help us finish the rstreason job in this function.
Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
include/net/rstreason.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/include/net/rstreason.h b/include/net/rstreason.h
index f87814a60205..a32b0fa17de2 100644
--- a/include/net/rstreason.h
+++ b/include/net/rstreason.h
@@ -10,6 +10,8 @@
FN(NO_SOCKET) \
FN(TCP_INVALID_ACK_SEQUENCE) \
FN(TCP_RFC7323_PAWS) \
+ FN(TCP_TOO_OLD_ACK) \
+ FN(TCP_ACK_UNSENT_DATA) \
FN(MPTCP_RST_EUNSPEC) \
FN(MPTCP_RST_EMPTCP) \
FN(MPTCP_RST_ERESOURCE) \
@@ -50,6 +52,10 @@ enum sk_rst_reason {
* LINUX_MIB_PAWSESTABREJECTED, LINUX_MIB_PAWSACTIVEREJECTED
*/
SK_RST_REASON_TCP_RFC7323_PAWS,
+ /** @SK_RST_REASON_TCP_TOO_OLD_ACK: TCP ACK is too old */
+ SK_RST_REASON_TCP_TOO_OLD_ACK,
+ /** @SK_RST_REASON_TCP_ACK_UNSENT_DATA */
+ SK_RST_REASON_TCP_ACK_UNSENT_DATA,
/* Copy from include/uapi/linux/mptcp.h.
* These reset fields will not be changed since they adhere to
@@ -130,6 +136,10 @@ sk_rst_convert_drop_reason(enum skb_drop_reason reason)
return SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE;
case SKB_DROP_REASON_TCP_RFC7323_PAWS:
return SK_RST_REASON_TCP_RFC7323_PAWS;
+ case SKB_DROP_REASON_TCP_TOO_OLD_ACK:
+ return SK_RST_REASON_TCP_TOO_OLD_ACK;
+ case SKB_DROP_REASON_TCP_ACK_UNSENT_DATA:
+ return SK_RST_REASON_TCP_ACK_UNSENT_DATA;
default:
/* If we don't have our own corresponding reason */
return SK_RST_REASON_NOT_SPECIFIED;
--
2.37.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net-next 3/5] tcp: fully support sk reset reason in tcp_rcv_state_process()
2024-05-09 13:13 [PATCH net-next 0/5] tcp: support rstreasons in the passive logic Jason Xing
2024-05-09 13:13 ` [PATCH net-next 1/5] tcp: fully support sk reset reasons in tcp_rcv_synsent_state_process() Jason Xing
2024-05-09 13:13 ` [PATCH net-next 2/5] tcp: fully support sk reset reason in tcp_ack() Jason Xing
@ 2024-05-09 13:13 ` Jason Xing
2024-05-09 13:13 ` [PATCH net-next 4/5] tcp: handle timewait cases in rstreason logic Jason Xing
2024-05-09 13:13 ` [PATCH net-next 5/5] tcp: handle rstreason in tcp_check_req() Jason Xing
4 siblings, 0 replies; 7+ messages in thread
From: Jason Xing @ 2024-05-09 13:13 UTC (permalink / raw)
To: edumazet, dsahern, kuba, pabeni, davem
Cc: netdev, kerneljasonxing, Jason Xing
From: Jason Xing <kernelxing@tencent.com>
Like the previous patch does in this series, finish the conversion map is
enough to let rstreason mechanism work in this function.
Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
include/net/rstreason.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/include/net/rstreason.h b/include/net/rstreason.h
index a32b0fa17de2..61855d4b27e2 100644
--- a/include/net/rstreason.h
+++ b/include/net/rstreason.h
@@ -12,6 +12,9 @@
FN(TCP_RFC7323_PAWS) \
FN(TCP_TOO_OLD_ACK) \
FN(TCP_ACK_UNSENT_DATA) \
+ FN(TCP_FLAGS) \
+ FN(TCP_OLD_ACK) \
+ FN(TCP_ABORT_ON_DATA) \
FN(MPTCP_RST_EUNSPEC) \
FN(MPTCP_RST_EMPTCP) \
FN(MPTCP_RST_ERESOURCE) \
@@ -56,6 +59,15 @@ enum sk_rst_reason {
SK_RST_REASON_TCP_TOO_OLD_ACK,
/** @SK_RST_REASON_TCP_ACK_UNSENT_DATA */
SK_RST_REASON_TCP_ACK_UNSENT_DATA,
+ /** @SK_RST_REASON_TCP_FLAGS: TCP flags invalid */
+ SK_RST_REASON_TCP_FLAGS,
+ /** @SK_RST_REASON_TCP_OLD_ACK: TCP ACK is old, but in window */
+ SK_RST_REASON_TCP_OLD_ACK,
+ /**
+ * @SK_RST_REASON_TCP_ABORT_ON_DATA: abort on data
+ * corresponding to LINUX_MIB_TCPABORTONDATA
+ */
+ SK_RST_REASON_TCP_ABORT_ON_DATA,
/* Copy from include/uapi/linux/mptcp.h.
* These reset fields will not be changed since they adhere to
@@ -140,6 +152,12 @@ sk_rst_convert_drop_reason(enum skb_drop_reason reason)
return SK_RST_REASON_TCP_TOO_OLD_ACK;
case SKB_DROP_REASON_TCP_ACK_UNSENT_DATA:
return SK_RST_REASON_TCP_ACK_UNSENT_DATA;
+ case SKB_DROP_REASON_TCP_FLAGS:
+ return SK_RST_REASON_TCP_FLAGS;
+ case SKB_DROP_REASON_TCP_OLD_ACK:
+ return SK_RST_REASON_TCP_OLD_ACK;
+ case SKB_DROP_REASON_TCP_ABORT_ON_DATA:
+ return SK_RST_REASON_TCP_ABORT_ON_DATA;
default:
/* If we don't have our own corresponding reason */
return SK_RST_REASON_NOT_SPECIFIED;
--
2.37.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net-next 4/5] tcp: handle timewait cases in rstreason logic
2024-05-09 13:13 [PATCH net-next 0/5] tcp: support rstreasons in the passive logic Jason Xing
` (2 preceding siblings ...)
2024-05-09 13:13 ` [PATCH net-next 3/5] tcp: fully support sk reset reason in tcp_rcv_state_process() Jason Xing
@ 2024-05-09 13:13 ` Jason Xing
2024-05-09 13:13 ` [PATCH net-next 5/5] tcp: handle rstreason in tcp_check_req() Jason Xing
4 siblings, 0 replies; 7+ messages in thread
From: Jason Xing @ 2024-05-09 13:13 UTC (permalink / raw)
To: edumazet, dsahern, kuba, pabeni, davem
Cc: netdev, kerneljasonxing, Jason Xing
From: Jason Xing <kernelxing@tencent.com>
There are two possible cases where TCP layer can send an RST. Since they
happen in the same place, I think using one independent reason is enough
to identify this special situation.
Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
include/net/rstreason.h | 5 +++++
net/ipv4/tcp_ipv4.c | 2 +-
net/ipv6/tcp_ipv6.c | 2 +-
3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/include/net/rstreason.h b/include/net/rstreason.h
index 61855d4b27e2..62e869089da4 100644
--- a/include/net/rstreason.h
+++ b/include/net/rstreason.h
@@ -15,6 +15,7 @@
FN(TCP_FLAGS) \
FN(TCP_OLD_ACK) \
FN(TCP_ABORT_ON_DATA) \
+ FN(TCP_TIMEWAIT_SOCKET) \
FN(MPTCP_RST_EUNSPEC) \
FN(MPTCP_RST_EMPTCP) \
FN(MPTCP_RST_ERESOURCE) \
@@ -69,6 +70,10 @@ enum sk_rst_reason {
*/
SK_RST_REASON_TCP_ABORT_ON_DATA,
+ /* Here start with the independent reasons */
+ /** @SK_RST_REASON_TCP_TIMEWAIT_SOCKET: happen on the timewait socket */
+ SK_RST_REASON_TCP_TIMEWAIT_SOCKET,
+
/* Copy from include/uapi/linux/mptcp.h.
* These reset fields will not be changed since they adhere to
* RFC 8684. So do not touch them. I'm going to list each definition
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 0427deca3e0e..d35cdb77d7b5 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2421,7 +2421,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
tcp_v4_timewait_ack(sk, skb);
break;
case TCP_TW_RST:
- tcp_v4_send_reset(sk, skb, sk_rst_convert_drop_reason(drop_reason));
+ tcp_v4_send_reset(sk, skb, SK_RST_REASON_TCP_TIMEWAIT_SOCKET);
inet_twsk_deschedule_put(inet_twsk(sk));
goto discard_it;
case TCP_TW_SUCCESS:;
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 37201c4fb393..bee26b961835 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1999,7 +1999,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
tcp_v6_timewait_ack(sk, skb);
break;
case TCP_TW_RST:
- tcp_v6_send_reset(sk, skb, sk_rst_convert_drop_reason(drop_reason));
+ tcp_v6_send_reset(sk, skb, SK_RST_REASON_TCP_TIMEWAIT_SOCKET);
inet_twsk_deschedule_put(inet_twsk(sk));
goto discard_it;
case TCP_TW_SUCCESS:
--
2.37.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net-next 5/5] tcp: handle rstreason in tcp_check_req()
2024-05-09 13:13 [PATCH net-next 0/5] tcp: support rstreasons in the passive logic Jason Xing
` (3 preceding siblings ...)
2024-05-09 13:13 ` [PATCH net-next 4/5] tcp: handle timewait cases in rstreason logic Jason Xing
@ 2024-05-09 13:13 ` Jason Xing
4 siblings, 0 replies; 7+ messages in thread
From: Jason Xing @ 2024-05-09 13:13 UTC (permalink / raw)
To: edumazet, dsahern, kuba, pabeni, davem
Cc: netdev, kerneljasonxing, Jason Xing
From: Jason Xing <kernelxing@tencent.com>
We're going to send an RST due to invalid syn packet which is already
checked whether 1) it is in sequence, 2) it is a retransmitted skb.
As RFC 793 says, if the state of socket is not CLOSED/LISTEN/SYN-SENT,
then we should send an RST when receiving bad syn packet:
"fourth, check the SYN bit,...If the SYN is in the window it is an
error, send a reset"
Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
include/net/rstreason.h | 8 ++++++++
net/ipv4/tcp_minisocks.c | 2 +-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/include/net/rstreason.h b/include/net/rstreason.h
index 62e869089da4..bfea05ff8d88 100644
--- a/include/net/rstreason.h
+++ b/include/net/rstreason.h
@@ -16,6 +16,7 @@
FN(TCP_OLD_ACK) \
FN(TCP_ABORT_ON_DATA) \
FN(TCP_TIMEWAIT_SOCKET) \
+ FN(INVALID_SYN) \
FN(MPTCP_RST_EUNSPEC) \
FN(MPTCP_RST_EMPTCP) \
FN(MPTCP_RST_ERESOURCE) \
@@ -73,6 +74,13 @@ enum sk_rst_reason {
/* Here start with the independent reasons */
/** @SK_RST_REASON_TCP_TIMEWAIT_SOCKET: happen on the timewait socket */
SK_RST_REASON_TCP_TIMEWAIT_SOCKET,
+ /**
+ * @SK_RST_REASON_INVALID_SYN: receive bad syn packet
+ * RFC 793 says if the state is not CLOSED/LISTEN/SYN-SENT then
+ * "fourth, check the SYN bit,...If the SYN is in the window it is
+ * an error, send a reset"
+ */
+ SK_RST_REASON_INVALID_SYN,
/* Copy from include/uapi/linux/mptcp.h.
* These reset fields will not be changed since they adhere to
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 7d543569a180..b93619b2384b 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -879,7 +879,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
* avoid becoming vulnerable to outside attack aiming at
* resetting legit local connections.
*/
- req->rsk_ops->send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
+ req->rsk_ops->send_reset(sk, skb, SK_RST_REASON_INVALID_SYN);
} else if (fastopen) { /* received a valid RST pkt */
reqsk_fastopen_remove(sk, req, true);
tcp_reset(sk, skb);
--
2.37.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net-next 2/5] tcp: fully support sk reset reason in tcp_ack()
2024-05-09 13:13 ` [PATCH net-next 2/5] tcp: fully support sk reset reason in tcp_ack() Jason Xing
@ 2024-05-10 2:08 ` Jason Xing
0 siblings, 0 replies; 7+ messages in thread
From: Jason Xing @ 2024-05-10 2:08 UTC (permalink / raw)
To: edumazet, dsahern, kuba, pabeni, davem; +Cc: netdev, Jason Xing
On Thu, May 9, 2024 at 9:13 PM Jason Xing <kerneljasonxing@gmail.com> wrote:
>
> From: Jason Xing <kernelxing@tencent.com>
>
> Based on the existing skb drop reason, updating the rstreason map can
> help us finish the rstreason job in this function.
>
> Signed-off-by: Jason Xing <kernelxing@tencent.com>
> ---
> include/net/rstreason.h | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/include/net/rstreason.h b/include/net/rstreason.h
> index f87814a60205..a32b0fa17de2 100644
> --- a/include/net/rstreason.h
> +++ b/include/net/rstreason.h
> @@ -10,6 +10,8 @@
> FN(NO_SOCKET) \
> FN(TCP_INVALID_ACK_SEQUENCE) \
> FN(TCP_RFC7323_PAWS) \
> + FN(TCP_TOO_OLD_ACK) \
> + FN(TCP_ACK_UNSENT_DATA) \
> FN(MPTCP_RST_EUNSPEC) \
> FN(MPTCP_RST_EMPTCP) \
> FN(MPTCP_RST_ERESOURCE) \
> @@ -50,6 +52,10 @@ enum sk_rst_reason {
> * LINUX_MIB_PAWSESTABREJECTED, LINUX_MIB_PAWSACTIVEREJECTED
> */
> SK_RST_REASON_TCP_RFC7323_PAWS,
> + /** @SK_RST_REASON_TCP_TOO_OLD_ACK: TCP ACK is too old */
> + SK_RST_REASON_TCP_TOO_OLD_ACK,
> + /** @SK_RST_REASON_TCP_ACK_UNSENT_DATA */
I'll add the detailed comment into this kdoc which was found by
patchwork in V2 series to make sure every item has its own
explanation.
Thanks,
Jason
> + SK_RST_REASON_TCP_ACK_UNSENT_DATA,
>
> /* Copy from include/uapi/linux/mptcp.h.
> * These reset fields will not be changed since they adhere to
> @@ -130,6 +136,10 @@ sk_rst_convert_drop_reason(enum skb_drop_reason reason)
> return SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE;
> case SKB_DROP_REASON_TCP_RFC7323_PAWS:
> return SK_RST_REASON_TCP_RFC7323_PAWS;
> + case SKB_DROP_REASON_TCP_TOO_OLD_ACK:
> + return SK_RST_REASON_TCP_TOO_OLD_ACK;
> + case SKB_DROP_REASON_TCP_ACK_UNSENT_DATA:
> + return SK_RST_REASON_TCP_ACK_UNSENT_DATA;
> default:
> /* If we don't have our own corresponding reason */
> return SK_RST_REASON_NOT_SPECIFIED;
> --
> 2.37.3
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-05-10 2:09 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-09 13:13 [PATCH net-next 0/5] tcp: support rstreasons in the passive logic Jason Xing
2024-05-09 13:13 ` [PATCH net-next 1/5] tcp: fully support sk reset reasons in tcp_rcv_synsent_state_process() Jason Xing
2024-05-09 13:13 ` [PATCH net-next 2/5] tcp: fully support sk reset reason in tcp_ack() Jason Xing
2024-05-10 2:08 ` Jason Xing
2024-05-09 13:13 ` [PATCH net-next 3/5] tcp: fully support sk reset reason in tcp_rcv_state_process() Jason Xing
2024-05-09 13:13 ` [PATCH net-next 4/5] tcp: handle timewait cases in rstreason logic Jason Xing
2024-05-09 13:13 ` [PATCH net-next 5/5] tcp: handle rstreason in tcp_check_req() Jason Xing
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).