Skip to content

Commit 354e4aa

Browse files
edumazetdavem330
authored andcommitted
tcp: RFC 5961 5.2 Blind Data Injection Attack Mitigation
RFC 5961 5.2 [Blind Data Injection Attack].[Mitigation] All TCP stacks MAY implement the following mitigation. TCP stacks that implement this mitigation MUST add an additional input check to any incoming segment. The ACK value is considered acceptable only if it is in the range of ((SND.UNA - MAX.SND.WND) <= SEG.ACK <= SND.NXT). All incoming segments whose ACK value doesn't satisfy the above condition MUST be discarded and an ACK sent back. Move tcp_send_challenge_ack() before tcp_ack() to avoid a forward declaration. Signed-off-by: Eric Dumazet <[email protected]> Cc: Neal Cardwell <[email protected]> Cc: Yuchung Cheng <[email protected]> Cc: Jerry Chu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 46baac3 commit 354e4aa

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

net/ipv4/tcp_input.c

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3552,6 +3552,24 @@ static bool tcp_process_frto(struct sock *sk, int flag)
35523552
return false;
35533553
}
35543554

3555+
/* RFC 5961 7 [ACK Throttling] */
3556+
static void tcp_send_challenge_ack(struct sock *sk)
3557+
{
3558+
/* unprotected vars, we dont care of overwrites */
3559+
static u32 challenge_timestamp;
3560+
static unsigned int challenge_count;
3561+
u32 now = jiffies / HZ;
3562+
3563+
if (now != challenge_timestamp) {
3564+
challenge_timestamp = now;
3565+
challenge_count = 0;
3566+
}
3567+
if (++challenge_count <= sysctl_tcp_challenge_ack_limit) {
3568+
NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPCHALLENGEACK);
3569+
tcp_send_ack(sk);
3570+
}
3571+
}
3572+
35553573
/* This routine deals with incoming acks, but not outgoing ones. */
35563574
static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
35573575
{
@@ -3571,8 +3589,14 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
35713589
/* If the ack is older than previous acks
35723590
* then we can probably ignore it.
35733591
*/
3574-
if (before(ack, prior_snd_una))
3592+
if (before(ack, prior_snd_una)) {
3593+
/* RFC 5961 5.2 [Blind Data Injection Attack].[Mitigation] */
3594+
if (before(ack, prior_snd_una - tp->max_window)) {
3595+
tcp_send_challenge_ack(sk);
3596+
return -1;
3597+
}
35753598
goto old_ack;
3599+
}
35763600

35773601
/* If the ack includes data we haven't sent yet, discard
35783602
* this segment (RFC793 Section 3.9).
@@ -5241,23 +5265,6 @@ static bool tcp_dma_try_early_copy(struct sock *sk, struct sk_buff *skb,
52415265
}
52425266
#endif /* CONFIG_NET_DMA */
52435267

5244-
static void tcp_send_challenge_ack(struct sock *sk)
5245-
{
5246-
/* unprotected vars, we dont care of overwrites */
5247-
static u32 challenge_timestamp;
5248-
static unsigned int challenge_count;
5249-
u32 now = jiffies / HZ;
5250-
5251-
if (now != challenge_timestamp) {
5252-
challenge_timestamp = now;
5253-
challenge_count = 0;
5254-
}
5255-
if (++challenge_count <= sysctl_tcp_challenge_ack_limit) {
5256-
NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPCHALLENGEACK);
5257-
tcp_send_ack(sk);
5258-
}
5259-
}
5260-
52615268
/* Does PAWS and seqno based validation of an incoming segment, flags will
52625269
* play significant role here.
52635270
*/

0 commit comments

Comments
 (0)