Skip to contentSkip to conversation

ipt_limit patch for iptables-1.3.1 and linux-2.4.22

PATCH [email protected] 5 participants 10 messages Dec 23, 2005 – Dec 27, 2005

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

Hello.

Here is very small patch adding ! functionnality to ipt_limit (iptables -m limit).

Thanks to this patch, you can easly filter SYNs attack to your host.. and also limit your lusers trying to do SYNs attack.

Simple example:
iptables -t mangle -A FORWARD -i eth0 -s 1.2.3.4 \
-p tcp --tcp-flags SYN SYN \
-m limit ! --limit 2/s -- limit-burst 10 -j DROP Forwarding only 2 SYNs per second (burst up to 10 conn per sec). (You can put it in filter table, I used mangle since when packet is not dropping, it goes to my QoS tables)

To apply this patch simply run:

# cd /usr/src/linux
# patch -p1 < ipt_limit-linux-2.4.22.patch

And patch userland iptables

# cd iptables-1.3.1
# patch -p1 < ipt_limit-iptables-1.3.1.patch

Recompile kernel (dont forget about clean)
recompile and install new iptables
Install kernel.
Reboot.. vioala..

I hope it will get to the mainstream very soon! Im still suprised why its not here already.. It adds extra functionality w/o security risks nor performance loss.

Files:
ftp://ftp.benet.uu3.net/pub/linux/ipt_limit-linux-2.4.22.patch ftp://ftp.benet.uu3.net/pub/linux/ipt_limit-iptables-1.3.1.patch

Regards,
Borg

== File 'ipt_limit-linux-2.4.22.patch' ==============================

include/linux/netfilter_ipv4/ipt_limit.h 2005-12-22 13:33:56.000000000 +0100 renamed from include/linux/netfilter_ipv4/ipt_limit.h 2005-12-23 13:07:30.000000000 +0100 +5 -0
@@ -10,6 +10,11 @@
        u_int32_t avg;    /* Average secs between packets * scale */
        u_int32_t burst;  /* Period multiplier for upper limit. */
 
+       /* Borg
+       adding invert support
+       */
+       char invert;
+
        /* Used internally by the kernel */
        unsigned long prev;
        u_int32_t credit;
net/ipv4/netfilter/ipt_limit.c 2005-12-22 12:40:35.000000000 +0100 renamed from net/ipv4/netfilter/ipt_limit.c 2005-12-23 13:07:30.000000000 +0100 +2 -2
@@ -63,11 +63,11 @@
                /* We're not limited. */
                r->credit -= r->cost;
                spin_unlock_bh(&limit_lock);
-               return 1;
+               return 1 ^ r->invert;
        }
 
                spin_unlock_bh(&limit_lock);
-       return 0;
+       return 0 ^ r->invert;
 }
 
 /* Precision saver. */

=====================================================================

== File 'ipt_limit-linux-2.4.22.patch' ==============================

extensions/libipt_limit.c 2005-12-22 13:33:03.000000000 +0100 renamed from extensions/libipt_limit.c 2005-12-22 11:38:38.000000000 +0100 +8 -4
@@ -12,7 +12,8 @@
 #include <stddef.h>
 #include <linux/netfilter_ipv4/ip_tables.h>
 /* For 64bit kernel / 32bit userspace */
-#include "../include/linux/netfilter_ipv4/ipt_limit.h"
+//#include "../include/linux/netfilter_ipv4/ipt_limit.h"
+#include "linux/netfilter_ipv4/ipt_limit.h"
 
 #define IPT_LIMIT_AVG  "3/hour"
 #define IPT_LIMIT_BURST        5
@@ -120,9 +121,12 @@
                return 0;
        }
 
-       if (invert)
-               exit_error(PARAMETER_PROBLEM,
-                          "limit does not support invert");
+       if (invert) {
+               /* Borg
+               Adding invert support
+               */
+               r->invert = 1;
+       }
 
        return 1;
 }

=====================================================================

#1 lore raw

[email protected] ha scritto:

Quoted 4 lines

Hello.

Here is very small patch adding ! functionnality to ipt_limit (iptables -m limit).

I've sent in october a similar patch in witch were present the same errors that are present in yours.
Namely
- "0 ^ r->invert" and "1 ^ r->invert" are not very clear
- it break the userspace. This problem is solved using versions.

Look for the thread with the subject
"NETFILTER: add support for invert condition (!) in ipt_limit". My last patch (20 Oct) should be correct. Please review it.

Quoted 104 lines

Thanks to this patch, you can easly filter SYNs attack to your host.. and also limit your lusers trying to do SYNs attack.

Simple example:
iptables -t mangle -A FORWARD -i eth0 -s 1.2.3.4 \

(quoted diff) +0 -2
-p tcp --tcp-flags SYN SYN \
-m limit ! --limit 2/s -- limit-burst 10 -j DROP

Forwarding only 2 SYNs per second (burst up to 10 conn per sec). (You can put it in filter table, I used mangle since when packet is not dropping, it goes to my QoS tables)

To apply this patch simply run:

# cd /usr/src/linux
# patch -p1 < ipt_limit-linux-2.4.22.patch

And patch userland iptables

# cd iptables-1.3.1
# patch -p1 < ipt_limit-iptables-1.3.1.patch

Recompile kernel (dont forget about clean)
recompile and install new iptables
Install kernel.
Reboot.. vioala..

I hope it will get to the mainstream very soon! Im still suprised why its not here already.. It adds extra functionality w/o security risks nor performance loss.

Files:
ftp://ftp.benet.uu3.net/pub/linux/ipt_limit-linux-2.4.22.patch ftp://ftp.benet.uu3.net/pub/linux/ipt_limit-iptables-1.3.1.patch

Regards,
Borg

== File 'ipt_limit-linux-2.4.22.patch' ==============================

include/linux/netfilter_ipv4/ipt_limit.h 2005-12-22 13:33:56.000000000 +0100 renamed from include/linux/netfilter_ipv4/ipt_limit.h 2005-12-23 13:07:30.000000000 +0100 +5 -0
@@ -10,6 +10,11 @@
        u_int32_t avg;    /* Average secs between packets * scale */
        u_int32_t burst;  /* Period multiplier for upper limit. */
 
+       /* Borg
+       adding invert support
+       */
+       char invert;
+
        /* Used internally by the kernel */
        unsigned long prev;
        u_int32_t credit;
net/ipv4/netfilter/ipt_limit.c 2005-12-22 12:40:35.000000000 +0100 renamed from net/ipv4/netfilter/ipt_limit.c 2005-12-23 13:07:30.000000000 +0100 +2 -2
@@ -63,11 +63,11 @@
                /* We're not limited. */
                r->credit -= r->cost;
                spin_unlock_bh(&limit_lock);
-               return 1;
+               return 1 ^ r->invert;
        }
 
                spin_unlock_bh(&limit_lock);
-       return 0;
+       return 0 ^ r->invert;
 }
 
 /* Precision saver. */

=====================================================================

== File 'ipt_limit-linux-2.4.22.patch' ==============================

extensions/libipt_limit.c 2005-12-22 13:33:03.000000000 +0100 renamed from extensions/libipt_limit.c 2005-12-22 11:38:38.000000000 +0100 +8 -4
@@ -12,7 +12,8 @@
 #include <stddef.h>
 #include <linux/netfilter_ipv4/ip_tables.h>
 /* For 64bit kernel / 32bit userspace */
-#include "../include/linux/netfilter_ipv4/ipt_limit.h"
+//#include "../include/linux/netfilter_ipv4/ipt_limit.h"
+#include "linux/netfilter_ipv4/ipt_limit.h"
 
 #define IPT_LIMIT_AVG  "3/hour"
 #define IPT_LIMIT_BURST        5
@@ -120,9 +121,12 @@
                return 0;
        }
 
-       if (invert)
-               exit_error(PARAMETER_PROBLEM,
-                          "limit does not support invert");
+       if (invert) {
+               /* Borg
+               Adding invert support
+               */
+               r->invert = 1;
+       }
 
        return 1;
 }

=====================================================================

Signature · 6 lines
**********************************************************************
Marco Innocenti              Gruppo Infrastruttura e Sicurezza
CINECA                       phone:+39 0516171553 / fax:+39 0516132198
Via Magnanelli 6/3           e-mail: [email protected]
40033 Casalecchio di Reno    Bologna (Italia)
**********************************************************************
#2 lore raw

What do you mean it brakes userspace?
Can you please explain me that?
I've patched both iptables (userland),
and kernel ipt_limit.c and header.
The only mistake I see for now, is that I wrongly modified include/linux/netfilter_ipv4/ipt_limit.h I should add that char invert at the end of structrue.

The only userspace program using that is iptables. Or I am wrong?

Regards,
Borg

----- Original Message -----
From: [email protected]
To: [email protected]
Date: 23-12-2005, 14:40
Subject: ipt_limit patch for iptables-1.3.1 and linux-2.4.22

[email protected] ha scritto:

Quoted 4 lines

Hello.

Here is very small patch adding ! functionnality to ipt_limit (iptables -m limit).

I've sent in october a similar patch in witch were present the same errors that are present in yours.
Namely
- "0 ^ r->invert" and "1 ^ r->invert" are not very clear
- it break the userspace. This problem is solved using versions.

Look for the thread with the subject
"NETFILTER: add support for invert condition (!) in ipt_limit". My last patch (20 Oct) should be correct. Please review it.

Quoted 104 lines

Thanks to this patch, you can easly filter SYNs attack to your host.. and also limit your lusers trying to do SYNs attack.

Simple example:
iptables -t mangle -A FORWARD -i eth0 -s 1.2.3.4 \

(quoted diff) +0 -2
-p tcp --tcp-flags SYN SYN \
-m limit ! --limit 2/s -- limit-burst 10 -j DROP

Forwarding only 2 SYNs per second (burst up to 10 conn per sec). (You can put it in filter table, I used mangle since when packet is not dropping, it goes to my QoS tables)

To apply this patch simply run:

# cd /usr/src/linux
# patch -p1 < ipt_limit-linux-2.4.22.patch

And patch userland iptables

# cd iptables-1.3.1
# patch -p1 < ipt_limit-iptables-1.3.1.patch

Recompile kernel (dont forget about clean)
recompile and install new iptables
Install kernel.
Reboot.. vioala..

I hope it will get to the mainstream very soon! Im still suprised why its not here already.. It adds extra functionality w/o security risks nor performance loss.

Files:
ftp://ftp.benet.uu3.net/pub/linux/ipt_limit-linux-2.4.22.patch ftp://ftp.benet.uu3.net/pub/linux/ipt_limit-iptables-1.3.1.patch

Regards,
Borg

== File 'ipt_limit-linux-2.4.22.patch' ==============================

include/linux/netfilter_ipv4/ipt_limit.h 2005-12-22 13:33:56.000000000 +0100 renamed from include/linux/netfilter_ipv4/ipt_limit.h 2005-12-23 13:07:30.000000000 +0100 +5 -0
@@ -10,6 +10,11 @@
        u_int32_t avg;    /* Average secs between packets * scale */
        u_int32_t burst;  /* Period multiplier for upper limit. */
 
+       /* Borg
+       adding invert support
+       */
+       char invert;
+
        /* Used internally by the kernel */
        unsigned long prev;
        u_int32_t credit;
net/ipv4/netfilter/ipt_limit.c 2005-12-22 12:40:35.000000000 +0100 renamed from net/ipv4/netfilter/ipt_limit.c 2005-12-23 13:07:30.000000000 +0100 +2 -2
@@ -63,11 +63,11 @@
                /* We're not limited. */
                r->credit -= r->cost;
                spin_unlock_bh(&limit_lock);
-               return 1;
+               return 1 ^ r->invert;
        }
 
                spin_unlock_bh(&limit_lock);
-       return 0;
+       return 0 ^ r->invert;
 }
 
 /* Precision saver. */

=====================================================================

== File 'ipt_limit-linux-2.4.22.patch' ==============================

extensions/libipt_limit.c 2005-12-22 13:33:03.000000000 +0100 renamed from extensions/libipt_limit.c 2005-12-22 11:38:38.000000000 +0100 +8 -4
@@ -12,7 +12,8 @@
 #include <stddef.h>
 #include <linux/netfilter_ipv4/ip_tables.h>
 /* For 64bit kernel / 32bit userspace */
-#include "../include/linux/netfilter_ipv4/ipt_limit.h"
+//#include "../include/linux/netfilter_ipv4/ipt_limit.h"
+#include "linux/netfilter_ipv4/ipt_limit.h"
 
 #define IPT_LIMIT_AVG  "3/hour"
 #define IPT_LIMIT_BURST        5
@@ -120,9 +121,12 @@
                return 0;
        }
 
-       if (invert)
-               exit_error(PARAMETER_PROBLEM,
-                          "limit does not support invert");
+       if (invert) {
+               /* Borg
+               Adding invert support
+               */
+               r->invert = 1;
+       }
 
        return 1;
 }

=====================================================================

Signature · 6 lines
**********************************************************************
Marco Innocenti              Gruppo Infrastruttura e Sicurezza
CINECA                       phone:+39 0516171553 / fax:+39 0516132198
Via Magnanelli 6/3           e-mail: [email protected]
40033 Casalecchio di Reno    Bologna (Italia)
**********************************************************************
#3 lore raw
Quoted 10 lines · [email protected] wrote:

What do you mean it brakes userspace?
Can you please explain me that?
I've patched both iptables (userland),
and kernel ipt_limit.c and header.
The only mistake I see for now, is that I wrongly modified include/linux/netfilter_ipv4/ipt_limit.h I should add that char invert at the end of structrue.

The only userspace program using that is iptables. Or I am wrong?

You seem to forget about old versions that don't have your patch. 2.4 doesn't support revisions, so we can't make that change.

#4 lore raw

Well.. patching only kernel or only userland is pointless indeed. I still dont understand "brakes userspace"
I assume that we patch both iptables + kernel.
Where is the problem then?

Back to adding that to mainline...
First, ppl must have add this to kernel.
and after kernel.. you can add it to new iptables
its easy to detect what kernel is in use
by #ifdef and you can add/remove support for !
in libipt_limit.c.

Regards,
Borg

----- Original Message -----
From: [email protected]
To: [email protected]
Date: 23-12-2005, 20:26
Subject: ipt_limit patch for iptables-1.3.1 and linux-2.4.22

Quoted 10 lines · [email protected] wrote:

What do you mean it brakes userspace?
Can you please explain me that?
I've patched both iptables (userland),
and kernel ipt_limit.c and header.
The only mistake I see for now, is that I wrongly modified include/linux/netfilter_ipv4/ipt_limit.h I should add that char invert at the end of structrue.

The only userspace program using that is iptables. Or I am wrong?

You seem to forget about old versions that don't have your patch. 2.4 doesn't support revisions, so we can't make that change.

#5 lore raw
Quoted 3 lines · On Fri, Dec 23, 2005 at 09:13:01PM +0100, [email protected] wrote:

Well.. patching only kernel or only userland is pointless indeed. I still dont understand "brakes userspace"
I assume that we patch both iptables + kernel.

new kernel + old userspace = broken
old kernel + new userspace = broken

Quoted 1 line

Where is the problem then?

comprehension

Phil

#6 lore raw

Okey.. So you saying that my system is broken?
I have patched kernel + iptables.. installed new kernel + iptables.. but userland is not updated.. It it bad?
I know it is when there are major changes in kernel so userspace cannot see them. But in that case I think its not a big problem since this is only used in iptables?

I know that its necessary to rebuild world when new kernel comes... but I think, this is not a case in that situation.

Or am I wrong again?

Thx for your patience,
Borg

----- Original Message -----
From: [email protected]
To: [email protected]
Date: 23-12-2005, 21:19
Subject: ipt_limit patch for iptables-1.3.1 and linux-2.4.22

Quoted 3 lines · On Fri, Dec 23, 2005 at 09:13:01PM +0100, [email protected] wrote:

Well.. patching only kernel or only userland is pointless indeed. I still dont understand "brakes userspace"
I assume that we patch both iptables + kernel.

new kernel + old userspace = broken
old kernel + new userspace = broken

Quoted 1 line

Where is the problem then?

comprehension

Phil

#7 lore raw
Quoted 7 lines · On Fri, Dec 23, 2005 at 09:35:23PM +0100, [email protected] wrote:

Okey.. So you saying that my system is broken?
I have patched kernel + iptables.. installed new kernel + iptables.. but userland is not updated.. It it bad?
I know it is when there are major changes in kernel so userspace cannot see them. But in that case I think its not a big problem since this is only used in iptables?

iptables == userspace.

If 2.4.33 were to suddenly have a new version of the limit match, then anyone using an older iptables would be broken if they upgraded to it.

So while _you_ may have updated your kernel and iptables, the rest of the world has not. Backwards compatibility is important.

If you need limit inversion, please update to 2.6.x kernels where this feature exists. If you still do not understand, please search the archives for additional information.

Phil

#9 lore raw
In reply to [email protected]
Quoted 1 line

Okey.. So you saying that my system is broken?

No.

The patch would break other people's systems who DONT consistently patch kernel and userspace. Iptables developers have for years now resisted to accept patches that behave that way, because they don't want the "support hell" it creates. That's what people are telling you. That's why your patch is considered "broken". In this case, "broken" is a synonym for "not acceptable to our established way of changing things".

best regards
Patrick

#8 lore raw
In reply to Phil Oester

Phil Oester ha scritto:

Quoted 2 lines

If you need limit inversion, please update to 2.6.x kernels where this feature exists.

No, it doesn't (yet).

Signature · 6 lines
**********************************************************************
Marco Innocenti              Gruppo Infrastruttura e Sicurezza
CINECA                       phone:+39 0516171553 / fax:+39 0516132198
Via Magnanelli 6/3           e-mail: [email protected]
40033 Casalecchio di Reno    Bologna (Italia)
**********************************************************************