Skip to contentSkip to conversation

Add seperated timeout for the connections that only receive packets in one direction

PATCH Changli Gao 3 participants 13 messages Nov 27, 2009 – Dec 1, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Add seperated timeout for the connections that only receive packets in one direction.

If we use tcp_timeouts[TCP_CONNTRACK_ESTABLISHED] to timeout the connections that only receive packets in one direction, ACK flood attack with fake source address A will exhaust A's connection limit, and A is DoSed. After the attack is stopped, A can't recover quickly due to the large timeout value.

This patch adds a new timeout value: nf_ct_tcp_timeout_loose_unreply for this kind of connections. It can help A to recover quickly after the attack is over.

----

 nf_conntrack_proto_tcp.c |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
net/netfilter/nf_conntrack_proto_tcp.c +19 -0
index 7eda8b8..471045a 100644
@@ -70,6 +70,8 @@ static const char *const tcp_conntrack_names[] = {
 static unsigned int nf_ct_tcp_timeout_max_retrans __read_mostly    =   5 MINS;
 static unsigned int nf_ct_tcp_timeout_unacknowledged __read_mostly =   5 MINS;
 
+static unsigned int nf_ct_tcp_timeout_loose_unreply __read_mostly  =   30 SECS;
+
 static unsigned int tcp_timeouts[TCP_CONNTRACK_MAX] __read_mostly = {
 	[TCP_CONNTRACK_SYN_SENT]	= 2 MINS,
 	[TCP_CONNTRACK_SYN_RECV]	= 60 SECS,
@@ -1006,6 +1008,9 @@ static int tcp_packet(struct nf_conn *ct,
 			nf_ct_kill_acct(ct, ctinfo, skb);
 			return NF_ACCEPT;
 		}
+		if (new_state == TCP_CONNTRACK_ESTABLISHED &&
+		    timeout > nf_ct_tcp_timeout_loose_unreply)
+			timeout = nf_ct_tcp_timeout_loose_unreply;
 	} else if (!test_bit(IPS_ASSURED_BIT, &ct->status)
 		   && (old_state == TCP_CONNTRACK_SYN_RECV
 		       || old_state == TCP_CONNTRACK_ESTABLISHED)
@@ -1298,6 +1303,13 @@ static struct ctl_table tcp_sysctl_table[] = {
 		.proc_handler	= proc_dointvec,
 	},
 	{
+		.procname	= "nf_conntrack_tcp_timeout_loose_unreply",
+		.data		= &nf_ct_tcp_timeout_loose_unreply,
+		.maxlen		= sizeof(unsigned int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_jiffies,
+	},
+	{
 		.procname       = "nf_conntrack_tcp_be_liberal",
 		.data           = &nf_ct_tcp_be_liberal,
 		.maxlen         = sizeof(unsigned int),
@@ -1394,6 +1406,13 @@ static struct ctl_table tcp_compat_sysctl_table[] = {
 		.proc_handler	= proc_dointvec,
 	},
 	{
+		.procname	= "ip_conntrack_tcp_timeout_loose_unreply",
+		.data		= &nf_ct_tcp_timeout_loose_unreply,
+		.maxlen		= sizeof(unsigned int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_jiffies,
+	},
+	{
 		.procname	= "ip_conntrack_tcp_be_liberal",
 		.data		= &nf_ct_tcp_be_liberal,
 		.maxlen		= sizeof(unsigned int),
#1 lore raw

Hi,

Quoted 31 lines · Changli Gao

Add seperated timeout for the connections that only receive packets in one direction.

If we use tcp_timeouts[TCP_CONNTRACK_ESTABLISHED] to timeout the connections that only receive packets in one direction, ACK flood attack with fake source address A will exhaust A's connection limit, and A is DoSed. After the attack is stopped, A can't recover quickly due to the large timeout value.

This patch adds a new timeout value: nf_ct_tcp_timeout_loose_unreply for this kind of connections. It can help A to recover quickly after the attack is over.

----

 nf_conntrack_proto_tcp.c |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
net/netfilter/nf_conntrack_proto_tcp.c +2 -0
index 7eda8b8..471045a 100644
@@ -70,6 +70,8 @@ static const char *const tcp_conntrack_names[] = {
 static unsigned int nf_ct_tcp_timeout_max_retrans __read_mostly    =   5 MINS;
 static unsigned int nf_ct_tcp_timeout_unacknowledged __read_mostly =   5 MINS;
 
+static unsigned int nf_ct_tcp_timeout_loose_unreply __read_mostly  =   30 SECS;
+
 static unsigned int tcp_timeouts[TCP_CONNTRACK_MAX] __read_mostly = {
 	[TCP_CONNTRACK_SYN_SENT]	= 2 MINS,
 	[TCP_CONNTRACK_SYN_RECV]	= 60 SECS,

net/netfilter/nf_conntrack_proto_tcp.c static int tcp_packet(struct nf_conn *ct, · line 1013

Quoted 6 lines
net/netfilter/nf_conntrack_proto_tcp.c +3 -0
@@ -1006,6 +1008,9 @@ static int tcp_packet(struct nf_conn *ct,
 			nf_ct_kill_acct(ct, ctinfo, skb);
 			return NF_ACCEPT;
 		}
+		if (new_state == TCP_CONNTRACK_ESTABLISHED &&
+		    timeout > nf_ct_tcp_timeout_loose_unreply)
+			timeout = nf_ct_tcp_timeout_loose_unreply;

I don't see how can the condition be true. The first reply packet checked here and if that's a pure ACK, then the new_state cannot be TCP_CONNTRACK_ESTABLISHED (except for picked up connections).

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics

          H-1525 Budapest 114, POB. 49, Hungary
#2 lore raw
Quoted 9 lines · Jozsef Kadlecsik

Hi,

On Fri, 27 Nov 2009, Changli Gao wrote:

I don't see how can the condition be true. The first reply packet checked here and if that's a pure ACK, then the new_state cannot be TCP_CONNTRACK_ESTABLISHED (except for picked up connections).

Yes, as nf_conntrack_tcp_timeout_loose_unreply implied, it is for picked up connections.

Signature · 6 lines
Regards,
Changli Gao([email protected])
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
Quoted 6 lines · Changli Gao
Quoted 4 lines · Jozsef Kadlecsik

On Fri, 27 Nov 2009, Changli Gao wrote:

Quoted 6 lines
Quoted 3 lines

I don't see how can the condition be true. The first reply packet checked here and if that's a pure ACK, then the new_state cannot be TCP_CONNTRACK_ESTABLISHED (except for picked up connections).

Yes, as nf_conntrack_tcp_timeout_loose_unreply implied, it is for picked up connections.

Connection pickup can be disabled by proper rules or by setting nf_ct_tcp_loose to zero. So in which environment this third method is required? I'm curious what triggered you to write your patch.

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics

          H-1525 Budapest 114, POB. 49, Hungary
#4 lore raw
Quoted 10 lines · Jozsef Kadlecsik
Quoted 3 lines · Changli Gao

Yes, as nf_conntrack_tcp_timeout_loose_unreply implied, it is for picked up connections.

Connection pickup can be disabled by proper rules or by setting nf_ct_tcp_loose to zero. So in which environment this third method is required? I'm curious what triggered you to write your patch.

In some condition, you can't disable it. It's why we export nf_ct_tcp_loose. As a bridge, if its booting breaks connections, users won't happy, so we must allow loose mode.

Signature · 6 lines
Regards,
Changli Gao([email protected])
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw
Quoted 6 lines · Changli Gao
Quoted 4 lines · Jozsef Kadlecsik
Quoted 2 lines · Changli Gao

Yes, as nf_conntrack_tcp_timeout_loose_unreply implied, it is for picked up connections.

Quoted 8 lines
Quoted 4 lines

Connection pickup can be disabled by proper rules or by setting nf_ct_tcp_loose to zero. So in which environment this third method is required? I'm curious what triggered you to write your patch.

In some condition, you can't disable it. It's why we export nf_ct_tcp_loose. As a bridge, if its booting breaks connections, users won't happy, so we must allow loose mode.

That won't help much. If you're able to spoof packets, you might as well spoof packets for both direction so SEEN_REPLY is set.

#6 lore raw
Quoted 1 line · Changli Gao

It is not easy to spoof in both directions. Routers won't forward it if the destination is at the same side.

Please don't top post.

They don't need to forward anything, conntrack handles the packet before routing.

Quoted 13 lines
Quoted 11 lines · Patrick McHardy
Quoted 10 lines · Changli Gao
Quoted 8 lines · Jozsef Kadlecsik
Quoted 2 lines · Changli Gao

Yes, as nf_conntrack_tcp_timeout_loose_unreply implied, it is for picked up connections.

Connection pickup can be disabled by proper rules or by setting nf_ct_tcp_loose to zero. So in which environment this third method is required? I'm curious what triggered you to write your patch.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

In some condition, you can't disable it. It's why we export nf_ct_tcp_loose. As a bridge, if its booting breaks connections, users won't happy, so we must allow loose mode.

That won't help much. If you're able to spoof packets, you might as well spoof packets for both direction so SEEN_REPLY is set.

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw
Quoted 4 lines · Patrick McHardy
Quoted 1 line · Changli Gao

It is not easy to spoof in both directions. Routers won't forward it if the destination is at the same side.

Please don't top post.

Sorry, I don't notice that G1 top posts.

Quoted 4 lines

They don't need to forward anything, conntrack handles the packet before routing.

Think about this topologic:

Attacker -> router1 -> router2 -> ... -> Linux Router -> Apache.

the packets in the other direction won't be sent to the Linux Router, as the other routers will routed them to the other place.

Case 2:

Attacker ---+

                +-- Linux Router --> WAN

Victim-------+

If we do sth. like RPF before entering conntrack, the packets in the other direction won't be in.

Signature · 6 lines
Regards,
Changli Gao([email protected])
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#8 lore raw
Quoted 11 lines · Changli Gao
Quoted 3 lines · Patrick McHardy

They don't need to forward anything, conntrack handles the packet before routing.

Think about this topologic:

Attacker -> router1 -> router2 -> ... -> Linux Router -> Apache.

the packets in the other direction won't be sent to the Linux Router, as the other routers will routed them to the other place.

Yes, in that case it could help.

Quoted 8 lines

Case 2:

Attacker ---+

                +-- Linux Router --> WAN

Victim-------+

If we do sth. like RPF before entering conntrack, the packets in the other direction won't be in.

RPF doesn't help since its also done after conntrack.

#9 lore raw
Quoted 12 lines · Patrick McHardy
Quoted 8 lines · Changli Gao

Case 2:

Attacker ---+
                +-- Linux Router --> WAN
Victim-------+

If we do sth. like RPF before entering conntrack, the packets in the other direction won't be in.

RPF doesn't help since its also done after conntrack.

I didn't mean RPF. I meaned some other thing like RPF before conntrack.

Signature · 6 lines
Regards,
Changli Gao([email protected])
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#10 lore raw
In reply to Changli Gao
Quoted 6 lines · Changli Gao

Think about this topologic:

Attacker -> router1 -> router2 -> ... -> Linux Router -> Apache.

the packets in the other direction won't be sent to the Linux Router, as the other routers will routed them to the other place.

Sorry, I don't get it.

If the attacker forges the source IP of the packet so that Apache thinks it's a local machine from its own point of view and answers it on the LAN, then that's the fault of the Linux Router operator: ingress and egress filtering is a must, period.

If the attacker forges the source IP of the packet otherwise so that Apache thinks it's a non local machine, then Apache will send the answer via the Linux Router regardless of the routing table of any router out there.

Quoted 8 lines

Case 2:

Attacker ---+

                +-- Linux Router --> WAN

Victim-------+

If we do sth. like RPF before entering conntrack, the packets in the other direction won't be in.

Here again I don't understand it completely: if there's an attacker on the LAN, then the point is not to mitigate the load for the Linux Router but first to find the attacker and then to prevent source IP forging.

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics

          H-1525 Budapest 114, POB. 49, Hungary
#11 lore raw
Quoted 10 lines · Jozsef Kadlecsik
Quoted 6 lines · Changli Gao

Think about this topologic:

Attacker -> router1 -> router2 -> ... -> Linux Router -> Apache.

the packets in the other direction won't be sent to the Linux Router, as the other routers will routed them to the other place.

Sorry, I don't get it.

There is a assumption: the final receiver doesn't reply any packet for this packet in the invalid state.

Signature · 6 lines
Regards,
Changli Gao([email protected])
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#12 lore raw
Quoted 8 lines · Changli Gao
Quoted 6 lines · Jozsef Kadlecsik
Quoted 4 lines · Changli Gao

Think about this topologic:

Attacker -> router1 -> router2 -> ... -> Linux Router -> Apache.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

the packets in the other direction won't be sent to the Linux Router, as the other routers will routed them to the other place.

Sorry, I don't get it.

There is a assumption: the final receiver doesn't reply any packet for this packet in the invalid state.

Who's assumption? Mine? Yours? For which case did you answer this?

Please describe a complete example, not bits here and there and leaving out conditions.

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics

          H-1525 Budapest 114, POB. 49, Hungary