Skip to content

Commit 0c24604

Browse files
edumazetdavem330
authored andcommitted
tcp: implement RFC 5961 4.2
Implement the RFC 5691 mitigation against Blind Reset attack using SYN bit. Section 4.2 of RFC 5961 advises to send a Challenge ACK and drop incoming packet, instead of resetting the session. Add a new SNMP counter to count number of challenge acks sent in response to SYN packets. (netstat -s | grep TCPSYNChallenge) Remove obsolete TCPAbortOnSyn, since we no longer abort a TCP session because of a SYN flag. Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Kiran Kumar Kella <kkiran@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5f3600e commit 0c24604

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

include/linux/snmp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ enum
208208
LINUX_MIB_TCPDSACKOFOSENT, /* TCPDSACKOfoSent */
209209
LINUX_MIB_TCPDSACKRECV, /* TCPDSACKRecv */
210210
LINUX_MIB_TCPDSACKOFORECV, /* TCPDSACKOfoRecv */
211-
LINUX_MIB_TCPABORTONSYN, /* TCPAbortOnSyn */
212211
LINUX_MIB_TCPABORTONDATA, /* TCPAbortOnData */
213212
LINUX_MIB_TCPABORTONCLOSE, /* TCPAbortOnClose */
214213
LINUX_MIB_TCPABORTONMEMORY, /* TCPAbortOnMemory */
@@ -238,6 +237,7 @@ enum
238237
LINUX_MIB_TCPOFODROP, /* TCPOFODrop */
239238
LINUX_MIB_TCPOFOMERGE, /* TCPOFOMerge */
240239
LINUX_MIB_TCPCHALLENGEACK, /* TCPChallengeACK */
240+
LINUX_MIB_TCPSYNCHALLENGE, /* TCPSYNChallenge */
241241
__LINUX_MIB_MAX
242242
};
243243

net/ipv4/proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ static const struct snmp_mib snmp4_net_list[] = {
232232
SNMP_MIB_ITEM("TCPDSACKOfoSent", LINUX_MIB_TCPDSACKOFOSENT),
233233
SNMP_MIB_ITEM("TCPDSACKRecv", LINUX_MIB_TCPDSACKRECV),
234234
SNMP_MIB_ITEM("TCPDSACKOfoRecv", LINUX_MIB_TCPDSACKOFORECV),
235-
SNMP_MIB_ITEM("TCPAbortOnSyn", LINUX_MIB_TCPABORTONSYN),
236235
SNMP_MIB_ITEM("TCPAbortOnData", LINUX_MIB_TCPABORTONDATA),
237236
SNMP_MIB_ITEM("TCPAbortOnClose", LINUX_MIB_TCPABORTONCLOSE),
238237
SNMP_MIB_ITEM("TCPAbortOnMemory", LINUX_MIB_TCPABORTONMEMORY),
@@ -262,6 +261,7 @@ static const struct snmp_mib snmp4_net_list[] = {
262261
SNMP_MIB_ITEM("TCPOFODrop", LINUX_MIB_TCPOFODROP),
263262
SNMP_MIB_ITEM("TCPOFOMerge", LINUX_MIB_TCPOFOMERGE),
264263
SNMP_MIB_ITEM("TCPChallengeACK", LINUX_MIB_TCPCHALLENGEACK),
264+
SNMP_MIB_ITEM("TCPSYNChallenge", LINUX_MIB_TCPSYNCHALLENGE),
265265
SNMP_MIB_SENTINEL
266266
};
267267

net/ipv4/tcp_input.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5270,8 +5270,8 @@ static void tcp_send_challenge_ack(struct sock *sk)
52705270
/* Does PAWS and seqno based validation of an incoming segment, flags will
52715271
* play significant role here.
52725272
*/
5273-
static int tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,
5274-
const struct tcphdr *th, int syn_inerr)
5273+
static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,
5274+
const struct tcphdr *th, int syn_inerr)
52755275
{
52765276
const u8 *hash_location;
52775277
struct tcp_sock *tp = tcp_sk(sk);
@@ -5323,20 +5323,22 @@ static int tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,
53235323

53245324
/* step 3: check security and precedence [ignored] */
53255325

5326-
/* step 4: Check for a SYN in window. */
5327-
if (th->syn && !before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) {
5326+
/* step 4: Check for a SYN
5327+
* RFC 5691 4.2 : Send a challenge ack
5328+
*/
5329+
if (th->syn) {
53285330
if (syn_inerr)
53295331
TCP_INC_STATS_BH(sock_net(sk), TCP_MIB_INERRS);
5330-
NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPABORTONSYN);
5331-
tcp_reset(sk);
5332-
return -1;
5332+
NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPSYNCHALLENGE);
5333+
tcp_send_challenge_ack(sk);
5334+
goto discard;
53335335
}
53345336

5335-
return 1;
5337+
return true;
53365338

53375339
discard:
53385340
__kfree_skb(skb);
5339-
return 0;
5341+
return false;
53405342
}
53415343

53425344
/*
@@ -5366,7 +5368,6 @@ int tcp_rcv_established(struct sock *sk, struct sk_buff *skb,
53665368
const struct tcphdr *th, unsigned int len)
53675369
{
53685370
struct tcp_sock *tp = tcp_sk(sk);
5369-
int res;
53705371

53715372
if (sk->sk_rx_dst) {
53725373
struct dst_entry *dst = sk->sk_rx_dst;
@@ -5555,9 +5556,8 @@ int tcp_rcv_established(struct sock *sk, struct sk_buff *skb,
55555556
* Standard slow path.
55565557
*/
55575558

5558-
res = tcp_validate_incoming(sk, skb, th, 1);
5559-
if (res <= 0)
5560-
return -res;
5559+
if (!tcp_validate_incoming(sk, skb, th, 1))
5560+
return 0;
55615561

55625562
step5:
55635563
if (th->ack && tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
@@ -5877,7 +5877,6 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
58775877
struct tcp_sock *tp = tcp_sk(sk);
58785878
struct inet_connection_sock *icsk = inet_csk(sk);
58795879
int queued = 0;
5880-
int res;
58815880

58825881
tp->rx_opt.saw_tstamp = 0;
58835882

@@ -5932,9 +5931,8 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
59325931
return 0;
59335932
}
59345933

5935-
res = tcp_validate_incoming(sk, skb, th, 0);
5936-
if (res <= 0)
5937-
return -res;
5934+
if (!tcp_validate_incoming(sk, skb, th, 0))
5935+
return 0;
59385936

59395937
/* step 5: check the ACK field */
59405938
if (th->ack) {

0 commit comments

Comments
 (0)