Skip to content

Commit 11f46ea

Browse files
JasonXingkuba-moo
authored andcommitted
tcp: rstreason: fully support in tcp_check_req()
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> Link: https://lore.kernel.org/r/20240510122502.27850-6-kerneljasonxing@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 22a3255 commit 11f46ea

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

include/net/rstreason.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
FN(TCP_OLD_ACK) \
1717
FN(TCP_ABORT_ON_DATA) \
1818
FN(TCP_TIMEWAIT_SOCKET) \
19+
FN(INVALID_SYN) \
1920
FN(MPTCP_RST_EUNSPEC) \
2021
FN(MPTCP_RST_EMPTCP) \
2122
FN(MPTCP_RST_ERESOURCE) \
@@ -76,6 +77,13 @@ enum sk_rst_reason {
7677
/* Here start with the independent reasons */
7778
/** @SK_RST_REASON_TCP_TIMEWAIT_SOCKET: happen on the timewait socket */
7879
SK_RST_REASON_TCP_TIMEWAIT_SOCKET,
80+
/**
81+
* @SK_RST_REASON_INVALID_SYN: receive bad syn packet
82+
* RFC 793 says if the state is not CLOSED/LISTEN/SYN-SENT then
83+
* "fourth, check the SYN bit,...If the SYN is in the window it is
84+
* an error, send a reset"
85+
*/
86+
SK_RST_REASON_INVALID_SYN,
7987

8088
/* Copy from include/uapi/linux/mptcp.h.
8189
* These reset fields will not be changed since they adhere to

net/ipv4/tcp_minisocks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
879879
* avoid becoming vulnerable to outside attack aiming at
880880
* resetting legit local connections.
881881
*/
882-
req->rsk_ops->send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
882+
req->rsk_ops->send_reset(sk, skb, SK_RST_REASON_INVALID_SYN);
883883
} else if (fastopen) { /* received a valid RST pkt */
884884
reqsk_fastopen_remove(sk, req, true);
885885
tcp_reset(sk, skb);

0 commit comments

Comments
 (0)