netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/5] tcp: support rstreasons in the passive logic
@ 2024-05-10 12:24 Jason Xing
  2024-05-10 12:24 ` [PATCH net-next v2 1/5] tcp: rstreason: fully support in tcp_rcv_synsent_state_process() Jason Xing
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Jason Xing @ 2024-05-10 12:24 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.

v2
1. add more comments and adjust the titles.

Jason Xing (5):
  tcp: rstreason: fully support in tcp_rcv_synsent_state_process()
  tcp: rstreason: fully support in tcp_ack()
  tcp: rstreason: fully support in tcp_rcv_state_process()
  tcp: rstreason: handle timewait cases in the receive path
  tcp: rstreason: fully support in tcp_check_req()

 include/net/rstreason.h  | 61 ++++++++++++++++++++++++++++++++++++++++
 net/ipv4/tcp_ipv4.c      |  2 +-
 net/ipv4/tcp_minisocks.c |  2 +-
 net/ipv6/tcp_ipv6.c      |  2 +-
 4 files changed, 64 insertions(+), 3 deletions(-)

-- 
2.37.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 1/5] tcp: rstreason: fully support in tcp_rcv_synsent_state_process()
  2024-05-10 12:24 [PATCH net-next v2 0/5] tcp: support rstreasons in the passive logic Jason Xing
@ 2024-05-10 12:24 ` Jason Xing
  2024-05-10 12:24 ` [PATCH net-next v2 2/5] tcp: rstreason: fully support in tcp_ack() Jason Xing
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jason Xing @ 2024-05-10 12:24 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 v2 2/5] tcp: rstreason: fully support in tcp_ack()
  2024-05-10 12:24 [PATCH net-next v2 0/5] tcp: support rstreasons in the passive logic Jason Xing
  2024-05-10 12:24 ` [PATCH net-next v2 1/5] tcp: rstreason: fully support in tcp_rcv_synsent_state_process() Jason Xing
@ 2024-05-10 12:24 ` Jason Xing
  2024-05-10 12:25 ` [PATCH net-next v2 3/5] tcp: rstreason: fully support in tcp_rcv_state_process() Jason Xing
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jason Xing @ 2024-05-10 12:24 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 | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/net/rstreason.h b/include/net/rstreason.h
index f87814a60205..69404c14f45d 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,13 @@ 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: TCP ACK for data we haven't
+	 * sent yet
+	 */
+	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 +139,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 v2 3/5] tcp: rstreason: fully support in tcp_rcv_state_process()
  2024-05-10 12:24 [PATCH net-next v2 0/5] tcp: support rstreasons in the passive logic Jason Xing
  2024-05-10 12:24 ` [PATCH net-next v2 1/5] tcp: rstreason: fully support in tcp_rcv_synsent_state_process() Jason Xing
  2024-05-10 12:24 ` [PATCH net-next v2 2/5] tcp: rstreason: fully support in tcp_ack() Jason Xing
@ 2024-05-10 12:25 ` Jason Xing
  2024-05-10 12:25 ` [PATCH net-next v2 4/5] tcp: rstreason: handle timewait cases in the receive path Jason Xing
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jason Xing @ 2024-05-10 12:25 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 69404c14f45d..fc1b99702771 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)		\
@@ -59,6 +62,15 @@ enum sk_rst_reason {
 	 * sent yet
 	 */
 	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
@@ -143,6 +155,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 v2 4/5] tcp: rstreason: handle timewait cases in the receive path
  2024-05-10 12:24 [PATCH net-next v2 0/5] tcp: support rstreasons in the passive logic Jason Xing
                   ` (2 preceding siblings ...)
  2024-05-10 12:25 ` [PATCH net-next v2 3/5] tcp: rstreason: fully support in tcp_rcv_state_process() Jason Xing
@ 2024-05-10 12:25 ` Jason Xing
  2024-05-10 12:25 ` [PATCH net-next v2 5/5] tcp: rstreason: fully support in tcp_check_req() Jason Xing
  2024-05-14  0:50 ` [PATCH net-next v2 0/5] tcp: support rstreasons in the passive logic patchwork-bot+netdevbpf
  5 siblings, 0 replies; 7+ messages in thread
From: Jason Xing @ 2024-05-10 12:25 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 fc1b99702771..7ae5bb55559b 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)		\
@@ -72,6 +73,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 108a438dc247..30ef0c8f5e92 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2427,7 +2427,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 7f6693e794bd..4c3605485b68 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 v2 5/5] tcp: rstreason: fully support in tcp_check_req()
  2024-05-10 12:24 [PATCH net-next v2 0/5] tcp: support rstreasons in the passive logic Jason Xing
                   ` (3 preceding siblings ...)
  2024-05-10 12:25 ` [PATCH net-next v2 4/5] tcp: rstreason: handle timewait cases in the receive path Jason Xing
@ 2024-05-10 12:25 ` Jason Xing
  2024-05-14  0:50 ` [PATCH net-next v2 0/5] tcp: support rstreasons in the passive logic patchwork-bot+netdevbpf
  5 siblings, 0 replies; 7+ messages in thread
From: Jason Xing @ 2024-05-10 12:25 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 7ae5bb55559b..2575c85d7f7a 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)		\
@@ -76,6 +77,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 v2 0/5] tcp: support rstreasons in the passive logic
  2024-05-10 12:24 [PATCH net-next v2 0/5] tcp: support rstreasons in the passive logic Jason Xing
                   ` (4 preceding siblings ...)
  2024-05-10 12:25 ` [PATCH net-next v2 5/5] tcp: rstreason: fully support in tcp_check_req() Jason Xing
@ 2024-05-14  0:50 ` patchwork-bot+netdevbpf
  5 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-05-14  0:50 UTC (permalink / raw)
  To: Jason Xing; +Cc: edumazet, dsahern, kuba, pabeni, davem, netdev, kernelxing

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Fri, 10 May 2024 20:24:57 +0800 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [net-next,v2,1/5] tcp: rstreason: fully support in tcp_rcv_synsent_state_process()
    https://git.kernel.org/netdev/net-next/c/2b9669d63400
  - [net-next,v2,2/5] tcp: rstreason: fully support in tcp_ack()
    https://git.kernel.org/netdev/net-next/c/459a2b37a41c
  - [net-next,v2,3/5] tcp: rstreason: fully support in tcp_rcv_state_process()
    https://git.kernel.org/netdev/net-next/c/f6d5e2cc291f
  - [net-next,v2,4/5] tcp: rstreason: handle timewait cases in the receive path
    https://git.kernel.org/netdev/net-next/c/22a32557758a
  - [net-next,v2,5/5] tcp: rstreason: fully support in tcp_check_req()
    https://git.kernel.org/netdev/net-next/c/11f46ea9814d

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-05-14  0:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-10 12:24 [PATCH net-next v2 0/5] tcp: support rstreasons in the passive logic Jason Xing
2024-05-10 12:24 ` [PATCH net-next v2 1/5] tcp: rstreason: fully support in tcp_rcv_synsent_state_process() Jason Xing
2024-05-10 12:24 ` [PATCH net-next v2 2/5] tcp: rstreason: fully support in tcp_ack() Jason Xing
2024-05-10 12:25 ` [PATCH net-next v2 3/5] tcp: rstreason: fully support in tcp_rcv_state_process() Jason Xing
2024-05-10 12:25 ` [PATCH net-next v2 4/5] tcp: rstreason: handle timewait cases in the receive path Jason Xing
2024-05-10 12:25 ` [PATCH net-next v2 5/5] tcp: rstreason: fully support in tcp_check_req() Jason Xing
2024-05-14  0:50 ` [PATCH net-next v2 0/5] tcp: support rstreasons in the passive logic patchwork-bot+netdevbpf

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).