Skip to contentSkip to conversation

netfilter: iptables target SYNPROXY

RFC PATCH In review Changli Gao 3 participants 8 messages May 25, 2010

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

RFC PATCH 1/1 netfilter: iptables target SYNPROXY

iptables target SYNPROXY.

This patch implements an iptables target SYNPROXY, which works in the raw table of the PREROUTING chain, before conntracking system. Syncookies is used, so no new state is introduced into the conntracking system. In fact, until the first connection is established, conntracking system doesn't see any packets. So when there is a SYN-flood attack, conntracking system won't be busy on finding and deleting the un-assured ct.

As the SYN-packet of the second connection request is sent locally, the DNAT rules which are in the PREROUTING chain should be moved to the OUTPUT chain.

----

 include/net/netfilter/nf_conntrack.h        |    8 
 include/net/netfilter/nf_conntrack_core.h   |   15 
 include/net/netfilter/nf_conntrack_extend.h |    2 
 include/net/tcp.h                           |   14 
 net/ipv4/netfilter/Kconfig                  |   12 
 net/ipv4/netfilter/Makefile                 |    1 
 net/ipv4/netfilter/ipt_SYNPROXY.c           |  658 ++++++++++++++++++++++++++++
 net/ipv4/syncookies.c                       |   21 
 net/ipv4/tcp_ipv4.c                         |    5 
 net/netfilter/nf_conntrack_core.c           |   44 +
 10 files changed, 764 insertions(+), 16 deletions(-)
include/net/netfilter/nf_conntrack.h +8 -0
index bde095f..001e6ee 100644
@@ -310,5 +310,13 @@ do {							\
 #define MODULE_ALIAS_NFCT_HELPER(helper) \
         MODULE_ALIAS("nfct-helper-" helper)
 
+#if defined(CONFIG_IP_NF_TARGET_SYNPROXY) || \
+    defined(CONFIG_IP_NF_TARGET_SYNPROXY_MODULE)
+extern int (*syn_proxy_pre_hook)(struct sk_buff *skb, struct nf_conn *ct,
+				 enum ip_conntrack_info ctinfo);
+
+extern int (*syn_proxy_post_hook)(struct sk_buff *skb, struct nf_conn *ct,
+				  enum ip_conntrack_info ctinfo);
+#endif
 #endif /* __KERNEL__ */
 #endif /* _NF_CONNTRACK_H */
include/net/netfilter/nf_conntrack_core.h +14 -1
index dffde8e..ae7d4be 100644
@@ -63,8 +63,21 @@ static inline int nf_conntrack_confirm(struct sk_buff *skb)
 	if (ct && ct != &nf_conntrack_untracked) {
 		if (!nf_ct_is_confirmed(ct) && !nf_ct_is_dying(ct))
 			ret = __nf_conntrack_confirm(skb);
-		if (likely(ret == NF_ACCEPT))
+		if (likely(ret == NF_ACCEPT)) {
+#if defined(CONFIG_IP_NF_TARGET_SYNPROXY) || \
+    defined(CONFIG_IP_NF_TARGET_SYNPROXY_MODULE)
+			int (*syn_proxy)(struct sk_buff *, struct nf_conn *,
+					 enum ip_conntrack_info);
+#endif
+
 			nf_ct_deliver_cached_events(ct);
+#if defined(CONFIG_IP_NF_TARGET_SYNPROXY) || \
+    defined(CONFIG_IP_NF_TARGET_SYNPROXY_MODULE)
+			syn_proxy = rcu_dereference(syn_proxy_post_hook);
+			if (syn_proxy)
+				ret = syn_proxy(skb, ct, skb->nfctinfo);
+#endif
+		}
 	}
 	return ret;
 }
include/net/netfilter/nf_conntrack_extend.h +2 -0
index 32d15bd..b2ae7e9 100644
@@ -11,6 +11,7 @@ enum nf_ct_ext_id {
 	NF_CT_EXT_ACCT,
 	NF_CT_EXT_ECACHE,
 	NF_CT_EXT_ZONE,
+	NF_CT_EXT_SYNPROXY,
 	NF_CT_EXT_NUM,
 };
 
@@ -19,6 +20,7 @@ enum nf_ct_ext_id {
 #define NF_CT_EXT_ACCT_TYPE struct nf_conn_counter
 #define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache
 #define NF_CT_EXT_ZONE_TYPE struct nf_conntrack_zone
+#define NF_CT_EXT_SYNPROXY_TYPE struct syn_proxy_state
 
 /* Extensions: optional stuff which isn't permanently in struct. */
 struct nf_ct_ext {
include/net/tcp.h +12 -2
index a144914..b1d59c2 100644
@@ -460,8 +460,18 @@ extern int			tcp_disconnect(struct sock *sk, int flags);
 extern __u32 syncookie_secret[2][16-4+SHA_DIGEST_WORDS];
 extern struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, 
 				    struct ip_options *opt);
-extern __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, 
-				     __u16 *mss);
+extern __u32 __cookie_v4_init_sequence(__be32 saddr, __be32 daddr,
+				       __be16 sport, __be16 dport, __u32 seq,
+				       __u16 *mssp);
+static inline __u32 cookie_v4_init_sequence(const struct iphdr *iph,
+					    const struct tcphdr *th,
+					    __u16 *mssp)
+{
+	return __cookie_v4_init_sequence(iph->saddr, iph->daddr, th->source,
+					 th->dest, ntohl(th->seq), mssp);
+}
+extern int cookie_v4_check_sequence(const struct iphdr *iph,
+				    const struct tcphdr *th, __u32 cookie);
 
 extern __u32 cookie_init_timestamp(struct request_sock *req);
 extern void cookie_check_timestamp(struct tcp_options_received *tcp_opt);
net/ipv4/netfilter/Kconfig +12 -0
index 1833bdb..4c0b5df 100644
@@ -343,6 +343,18 @@ config IP_NF_RAW
 	  If you want to compile it as a module, say M here and read
 	  <file:Documentation/kbuild/modules.txt>.  If unsure, say `N'.
 
+config IP_NF_TARGET_SYNPROXY
+	tristate "SYNPROXY target support (EXPERIMENTAL)"
+	depends on IP_NF_RAW && EXPERIMENTAL
+	depends on NF_CONNTRACK_IPV4
+	depends on SYN_COOKIES
+	help
+	  The SYNPROXY target allows a raw rule to specify that some TCP
+	  connections are relayed to protect the TCP servers from the SYN-flood
+	  DoS attacks.
+
+	  To compile it as a module, choose M here.  If unsure, say N.
+
 # security table for MAC policy
 config IP_NF_SECURITY
 	tristate "Security table"
net/ipv4/netfilter/Makefile +1 -0
index 4811159..ae6a688 100644
@@ -61,6 +61,7 @@ obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
 obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
 obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
 obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
+obj-$(CONFIG_IP_NF_TARGET_SYNPROXY) += ipt_SYNPROXY.o
 
 # generic ARP tables
 obj-$(CONFIG_IP_NF_ARPTABLES) += arp_tables.o
net/ipv4/netfilter/ipt_SYNPROXY.c new file +658 -0

658 lines not on this page · raw message

net/ipv4/syncookies.c +9 -12
index 5c24db4..d61d374 100644
@@ -160,26 +160,22 @@ static __u16 const msstab[] = {
  * Generate a syncookie.  mssp points to the mss, which is returned
  * rounded down to the value encoded in the cookie.
  */
-__u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, __u16 *mssp)
+__u32 __cookie_v4_init_sequence(__be32 saddr, __be32 daddr, __be16 sport,
+				__be16 dport, __u32 seq, __u16 *mssp)
 {
-	const struct iphdr *iph = ip_hdr(skb);
-	const struct tcphdr *th = tcp_hdr(skb);
 	int mssind;
 	const __u16 mss = *mssp;
 
-	tcp_synq_overflow(sk);
-
 	/* XXX sort msstab[] by probability?  Binary search? */
 	for (mssind = 0; mss > msstab[mssind + 1]; mssind++)
 		;
 	*mssp = msstab[mssind] + 1;
 
-	NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SYNCOOKIESSENT);
 
-	return secure_tcp_syn_cookie(iph->saddr, iph->daddr,
-				     th->source, th->dest, ntohl(th->seq),
+	return secure_tcp_syn_cookie(saddr, daddr, sport, dport, seq,
 				     jiffies / (HZ * 60), mssind);
 }
+EXPORT_SYMBOL(__cookie_v4_init_sequence);
 
 /*
  * This (misnamed) value is the age of syncookie which is permitted.
@@ -192,10 +188,9 @@ __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, __u16 *mssp)
  * Check if a ack sequence number is a valid syncookie.
  * Return the decoded mss if it is, or 0 if not.
  */
-static inline int cookie_check(struct sk_buff *skb, __u32 cookie)
+int cookie_v4_check_sequence(const struct iphdr *iph, const struct tcphdr *th,
+			     __u32 cookie)
 {
-	const struct iphdr *iph = ip_hdr(skb);
-	const struct tcphdr *th = tcp_hdr(skb);
 	__u32 seq = ntohl(th->seq) - 1;
 	__u32 mssind = check_tcp_syn_cookie(cookie, iph->saddr, iph->daddr,
 					    th->source, th->dest, seq,
@@ -204,6 +199,7 @@ static inline int cookie_check(struct sk_buff *skb, __u32 cookie)
 
 	return mssind < NUM_MSS ? msstab[mssind] + 1 : 0;
 }
+EXPORT_SYMBOL(cookie_v4_check_sequence);
 
 static inline struct sock *get_cookie_sock(struct sock *sk, struct sk_buff *skb,
 					   struct request_sock *req,
@@ -270,7 +266,8 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
 		goto out;
 
 	if (tcp_synq_no_recent_overflow(sk) ||
-	    (mss = cookie_check(skb, cookie)) == 0) {
+	    (mss = cookie_v4_check_sequence(ip_hdr(skb), tcp_hdr(skb),
+					    cookie)) == 0) {
 		NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SYNCOOKIESFAILED);
 		goto out;
 	}
net/ipv4/tcp_ipv4.c +4 -1
index 202cf09..9879c3b 100644
@@ -1330,8 +1330,11 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
 #ifdef CONFIG_SYN_COOKIES
 		syn_flood_warning(skb);
 		req->cookie_ts = tmp_opt.tstamp_ok;
+		tcp_synq_overflow(sk);
+		NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SYNCOOKIESSENT);
+		isn = cookie_v4_init_sequence(ip_hdr(skb), tcp_hdr(skb),
+					      &req->mss);
 #endif
-		isn = cookie_v4_init_sequence(sk, skb, &req->mss);
 	} else if (!isn) {
 		struct inet_peer *peer = NULL;
 
net/netfilter/nf_conntrack_core.c +44 -0

70 lines not on this page · raw message

#1 lore raw
Quoted 6 lines · Changli Gao
net/ipv4/netfilter/Kconfig                  |   12 
net/ipv4/netfilter/Makefile                 |    1 
net/ipv4/netfilter/ipt_SYNPROXY.c           |  658 ++++++++++++++++++++++++++++
net/ipv4/syncookies.c                       |   21 
net/ipv4/tcp_ipv4.c                         |    5 
net/netfilter/nf_conntrack_core.c           |   44 +

Please make this an Xtables extension.
There is excellent documentation ("Writing Netfilter Modules" to google) on the details if needed.

Quoted 15 lines
include/net/netfilter/nf_conntrack_core.h +7 -1
@@ -63,8 +63,21 @@ static inline int nf_conntrack_confirm(struct sk_buff *skb)
 	if (ct && ct != &nf_conntrack_untracked) {
 		if (!nf_ct_is_confirmed(ct) && !nf_ct_is_dying(ct))
 			ret = __nf_conntrack_confirm(skb);
-		if (likely(ret == NF_ACCEPT))
+		if (likely(ret == NF_ACCEPT)) {
+#if defined(CONFIG_IP_NF_TARGET_SYNPROXY) || \
+    defined(CONFIG_IP_NF_TARGET_SYNPROXY_MODULE)
+			int (*syn_proxy)(struct sk_buff *, struct nf_conn *,
+					 enum ip_conntrack_info);
+#endif
+
 			nf_ct_deliver_cached_events(ct);

include/net/netfilter/nf_conntrack_core.h static inline int nf_conntrack_confirm(struct sk_buff *skb) · line 83

Quoted 10 lines
include/net/netfilter/nf_conntrack_core.h +7 -0
+#if defined(CONFIG_IP_NF_TARGET_SYNPROXY) || \
+    defined(CONFIG_IP_NF_TARGET_SYNPROXY_MODULE)
+			syn_proxy = rcu_dereference(syn_proxy_post_hook);
+			if (syn_proxy)
+				ret = syn_proxy(skb, ct, skb->nfctinfo);
+#endif
+		}
 	}
 	return ret;
 }

I'm sure this is possible with lesser macro intrusion - use a separate function. Same in nf_conntrack_core.c

Quoted 8 lines
include/net/tcp.h +0 -2
@@ -460,8 +460,18 @@ extern int			tcp_disconnect(struct sock *sk, int flags);
 extern __u32 syncookie_secret[2][16-4+SHA_DIGEST_WORDS];
 extern struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, 
 				    struct ip_options *opt);
-extern __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, 
-				     __u16 *mss);

include/net/tcp.h extern int tcp_disconnect(struct sock *sk, int flags); · line 472

Quoted 10 lines
include/net/tcp.h +10 -0
+extern __u32 __cookie_v4_init_sequence(__be32 saddr, __be32 daddr,
+				       __be16 sport, __be16 dport, __u32 seq,
+				       __u16 *mssp);
+static inline __u32 cookie_v4_init_sequence(const struct iphdr *iph,
+					    const struct tcphdr *th,
+					    __u16 *mssp)
+{
+	return __cookie_v4_init_sequence(iph->saddr, iph->daddr, th->source,
+					 th->dest, ntohl(th->seq), mssp);
+}

Since there is only one cookie_v4_init_sequence user AFAICS, moving the function there seems to make best sense.

include/net/tcp.h extern int tcp_disconnect(struct sock *sk, int flags); · line 473

Quoted 1 line
include/net/tcp.h +1 -0
+static int get_mss(u8 *data, int len)

unsigned

include/net/tcp.h extern int tcp_disconnect(struct sock *sk, int flags); · line 474

Quoted 1 line
include/net/tcp.h +1 -0
+	/* only support IPv4 now */

Please fix :)

include/net/tcp.h extern int tcp_disconnect(struct sock *sk, int flags); · line 476

Quoted 2 lines
include/net/tcp.h +2 -0
+	th = skb_header_pointer(skb, iph->ihl * 4, sizeof(_th), &_th);
+	BUG_ON(th == NULL);

I wouldn't call that a bug. I think that can happen on an evil TCP tinygram (with proper IPV4 header).

include/net/tcp.h extern int tcp_disconnect(struct sock *sk, int flags);

Quoted 8 lines
include/net/tcp.h +8 -0
+static int syn_proxy_mangle_pkt(struct sk_buff *skb, struct iphdr *iph,
+				struct tcphdr *th, u32 seq_diff)
+{
+	__be32 new;
+	int olen;
+
+	if (skb->len < (iph->ihl + th->doff) * 4)
+		return NF_DROP;

Verdicts are unsigned too. (Also in other functions.)

include/net/tcp.h

Quoted 6 lines
include/net/tcp.h +6 -0
+static struct xt_target synproxy_tg_reg __read_mostly = {
+	.name		= "SYNPROXY",
+	.family		= NFPROTO_IPV4,
+	.target		= synproxy_tg,
+	.table		= "raw",
+	.hooks		= (1 << NF_INET_PRE_ROUTING),

No need for (),

include/net/tcp.h

Quoted 10 lines
include/net/tcp.h +10 -0
+	.proto		= IPPROTO_TCP,
+	.me		= THIS_MODULE,
+};
+
+static int __init synproxy_tg_init(void)
+{
+	int err, cpu;
+
+	for_each_possible_cpu(cpu)
+		per_cpu(syn_proxy_state, cpu).seq_inited = 0;

Static data starts out zeroed. That also applies to percpu data, doesn't it?

#2 lore raw
Quoted 9 lines · Jan Engelhardt
Quoted 6 lines · Changli Gao

net/ipv4/netfilter/Kconfig                  |   12 net/ipv4/netfilter/Makefile                 |    1 net/ipv4/netfilter/ipt_SYNPROXY.c           |  658 ++++++++++++++++++++++++++++ net/ipv4/syncookies.c                       |   21 net/ipv4/tcp_ipv4.c                         |    5 net/netfilter/nf_conntrack_core.c           |   44 +

Quoted 3 lines

Please make this an Xtables extension.
There is excellent documentation ("Writing Netfilter Modules" to google) on the details if needed.

Hmm. I don't know IPv6 well. So I leave it as an iptables extension, and hope sb. comes on with IPv6 support after it gets merged.

Quoted 21 lines
Quoted 21 lines
include/net/netfilter/nf_conntrack_core.h +12 -1
@@ -63,8 +63,21 @@ static inline int nf_conntrack_confirm(struct sk_buff *skb)
       if (ct && ct != &nf_conntrack_untracked) {
               if (!nf_ct_is_confirmed(ct) && !nf_ct_is_dying(ct))
                       ret = __nf_conntrack_confirm(skb);
-              if (likely(ret == NF_ACCEPT))
+              if (likely(ret == NF_ACCEPT)) {
+#if defined(CONFIG_IP_NF_TARGET_SYNPROXY) || \
+    defined(CONFIG_IP_NF_TARGET_SYNPROXY_MODULE)
+                      int (*syn_proxy)(struct sk_buff *, struct nf_conn *,
+                                       enum ip_conntrack_info);
+#endif
+
                       nf_ct_deliver_cached_events(ct);
+#if defined(CONFIG_IP_NF_TARGET_SYNPROXY) || \
+    defined(CONFIG_IP_NF_TARGET_SYNPROXY_MODULE)
+                      syn_proxy = rcu_dereference(syn_proxy_post_hook);
+                      if (syn_proxy)
+                              ret = syn_proxy(skb, ct, skb->nfctinfo);
Quoted 8 lines

include/net/netfilter/nf_conntrack_core.h static inline int nf_conntrack_confirm(struct sk_buff *skb) · line 83

Quoted 5 lines
include/net/netfilter/nf_conntrack_core.h +2 -0
+#endif
+              }
       }
       return ret;
 }

I'm sure this is possible with lesser macro intrusion - use a separate function. Same in nf_conntrack_core.c

I'm thinking about adding two helper functions into structure nf_conntrack_l4proto. Then the l4 protocol sepcific code won't be in nf_conntrack_core.c but in nf_conntrack_proto_tcp.c.

Quoted 14 lines
Quoted 14 lines
include/net/tcp.h +5 -2
@@ -460,8 +460,18 @@ extern int                        tcp_disconnect(struct sock *sk, int flags);
 extern __u32 syncookie_secret[2][16-4+SHA_DIGEST_WORDS];
 extern struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
                                   struct ip_options *opt);
-extern __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb,
-                                   __u16 *mss);
+extern __u32 __cookie_v4_init_sequence(__be32 saddr, __be32 daddr,
+                                     __be16 sport, __be16 dport, __u32 seq,
+                                     __u16 *mssp);
+static inline __u32 cookie_v4_init_sequence(const struct iphdr *iph,
+                                          const struct tcphdr *th,
Quoted 8 lines

include/net/tcp.h extern int tcp_disconnect(struct sock *sk, int flags); · line 472

Quoted 5 lines
include/net/tcp.h +5 -0
+                                          __u16 *mssp)
+{
+      return __cookie_v4_init_sequence(iph->saddr, iph->daddr, th->source,
+                                       th->dest, ntohl(th->seq), mssp);
+}

Since there is only one cookie_v4_init_sequence user AFAICS, moving the function there seems to make best sense.

OK. I wanted to keep cookie_v4_init_sequence() and cookie_v4_check_sequence() symmetric.

Quoted 4 lines

include/net/tcp.h extern int                        tcp_disconnect(struct sock *sk, int flags); · line 473

Quoted 2 lines
include/net/tcp.h +1 -0
+static int get_mss(u8 *data, int len)

unsigned

I am afraid that I can't do that. As get_mss() may return a negative value, if there is some invalid TCP option.

Quoted 4 lines

include/net/tcp.h extern int                        tcp_disconnect(struct sock *sk, int flags); · line 474

Quoted 2 lines
include/net/tcp.h +1 -0
+      /* only support IPv4 now */

Please fix :)

The same reasion as above.

Quoted 6 lines

include/net/tcp.h extern int                        tcp_disconnect(struct sock *sk, int flags); · line 476

Quoted 3 lines
include/net/tcp.h +2 -0
+      th = skb_header_pointer(skb, iph->ihl * 4, sizeof(_th), &_th);
+      BUG_ON(th == NULL);

I wouldn't call that a bug. I think that can happen on an evil TCP tinygram (with proper IPV4 header).

I copied the code from file nf_conntrack_proto_tcp.c. In fact, BUG_ON isn't useful at all, as tcp_error is called before this function is called.

Quoted 11 lines

include/net/tcp.h extern int                        tcp_disconnect(struct sock *sk, int flags);

Quoted 9 lines
include/net/tcp.h +8 -0
+static int syn_proxy_mangle_pkt(struct sk_buff *skb, struct iphdr *iph,
+                              struct tcphdr *th, u32 seq_diff)
+{
+      __be32 new;
+      int olen;
+
+      if (skb->len < (iph->ihl + th->doff) * 4)
+              return NF_DROP;

Verdicts are unsigned too. (Also in other functions.)

OK. Thanks.

Quoted 9 lines
Quoted 7 lines

+static struct xt_target synproxy_tg_reg __read_mostly = {
+      .name           = "SYNPROXY",
+      .family         = NFPROTO_IPV4,
+      .target         = synproxy_tg,
+      .table          = "raw",
+      .hooks          = (1 << NF_INET_PRE_ROUTING),

No need for (),

Yea. Thanks.

Quoted 14 lines

include/net/tcp.h

Quoted 11 lines

+      .proto          = IPPROTO_TCP,
+      .me             = THIS_MODULE,

include/net/tcp.h +8 -0
+};
+
+static int __init synproxy_tg_init(void)
+{
+      int err, cpu;
+
+      for_each_possible_cpu(cpu)
+              per_cpu(syn_proxy_state, cpu).seq_inited = 0;

Static data starts out zeroed. That also applies to percpu data, doesn't it?

Yea, Eric has mentioned that.

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 8 lines · Changli Gao
Quoted 8 lines · Changli Gao
Quoted 6 lines

net/ipv4/netfilter/Kconfig                  |   12 net/ipv4/netfilter/Makefile                 |    1 net/ipv4/netfilter/ipt_SYNPROXY.c           |  658 ++++++++++++++++++++++++++++ net/ipv4/syncookies.c                       |   21 net/ipv4/tcp_ipv4.c                         |    5 net/netfilter/nf_conntrack_core.c           |   44 +

Quoted 6 lines
Quoted 3 lines

Please make this an Xtables extension.
There is excellent documentation ("Writing Netfilter Modules" to google) on the details if needed.

Hmm. I don't know IPv6 well. So I leave it as an iptables extension, and hope sb. comes on with IPv6 support after it gets merged.

This should still be xt even if it does not do ipv6.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

+      th = skb_header_pointer(skb, iph->ihl * 4, sizeof(_th), &_th);
+      BUG_ON(th == NULL);

I wouldn't call that a bug. I think that can happen on an evil TCP tinygram (with proper IPV4 header).

I copied the code from file nf_conntrack_proto_tcp.c. In fact, BUG_ON isn't useful at all, as tcp_error is called before this function is called.

Ah I see it hard-depends on nf_conntrack_ipv4 (in Kconfig).
That too could be done instead by using nf_ct_get_l3proto at runtime. --
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

#4 lore raw
In reply to Changli Gao

Hi,

Quoted 8 lines · Changli Gao

iptables target SYNPROXY.

This patch implements an iptables target SYNPROXY, which works in the raw table of the PREROUTING chain, before conntracking system. Syncookies is used, so no new state is introduced into the conntracking system. In fact, until the first connection is established, conntracking system doesn't see any packets. So when there is a SYN-flood attack, conntracking system won't be busy on finding and deleting the un-assured ct.

My main problem with your target is that by using it, important and useful TCP options are lost: timestamp and SACK. That pushes back TCP by almost twenty years.

Here you reason for the target that it protects conntrack itself, but in the Kconfig text you write that it protects the servers behind the firewall. Both can be true, but if the real goal is to defend the servers then your target could simply send a faked ACK to complete the three way handshake and that way TCP would not be crippled (conntrack timeout should still be adjusted).

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
#5 lore raw
Quoted 13 lines · Jozsef Kadlecsik

Hi,

Quoted 8 lines · Changli Gao

iptables target SYNPROXY.

This patch implements an iptables target SYNPROXY, which works in the raw table of the PREROUTING chain, before conntracking system. Syncookies is used, so no new state is introduced into the conntracking system. In fact, until the first connection is established, conntracking system doesn't see any packets. So when there is a SYN-flood attack, conntracking system won't be busy on finding and deleting the un-assured ct.

Quoted 3 lines

My main problem with your target is that by using it, important and useful TCP options are lost: timestamp and SACK. That pushes back TCP by almost twenty years.

Yea. Only MSS option is supported. But it is better than being DoSed. And you can set a threshold for SYNPROXY with limit match, then there isn't any difference if there isn't any SYN-flood attack.

Quoted 8 lines

Here you reason for the target that it protects conntrack itself, but in the Kconfig text you write that it protects the servers behind the firewall. Both can be true, but if the real goal is to defend the servers then your target could simply send a faked ACK to complete the three way handshake and that way TCP would not be crippled (conntrack timeout should still be adjusted).

Yes, both can be true. You descried above is called SYNDefender by Checkpoint, and it doesn't work as well as SYNPROXY.

http://www.usenix.org/events/sec01/invitedtalks/oliver.pdf

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
#6 lore raw

Hi,

Quoted 14 lines · Changli Gao
Quoted 11 lines · Jozsef Kadlecsik
Quoted 8 lines · Changli Gao

iptables target SYNPROXY.

This patch implements an iptables target SYNPROXY, which works in the raw table of the PREROUTING chain, before conntracking system. Syncookies is used, so no new state is introduced into the conntracking system. In fact, until the first connection is established, conntracking system doesn't see any packets. So when there is a SYN-flood attack, conntracking system won't be busy on finding and deleting the un-assured ct.

Quoted 7 lines
Quoted 3 lines

My main problem with your target is that by using it, important and useful TCP options are lost: timestamp and SACK. That pushes back TCP by almost twenty years.

Yea. Only MSS option is supported. But it is better than being DoSed. And you can set a threshold for SYNPROXY with limit match, then there isn't any difference if there isn't any SYN-flood attack.

If I (have to) limit SYNPROXY, why shouldn't I better limit the SYN packets directly instead?

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
#7 lore raw
Quoted 8 lines · Jozsef Kadlecsik
Quoted 4 lines

Yea. Only MSS option is  supported. But it is better than being DoSed. And you can set a threshold for SYNPROXY with limit match, then there isn't any difference if there isn't any SYN-flood attack.

If I (have to) limit SYNPROXY, why shouldn't I better limit the SYN packets directly instead?

Without SYNPROXY, you have to drop the over limit SYN packets, and maybe normal SYN packets are dropped.

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