NetFilter unclean modue in 2.6.x kernels
Subsystems (2)
Quoted 2 lines · Oleg V. Sapon
Can you help locate unclean module for 2.6.x kernel or we must use source files from 2.6.0-test4?
I fear nobody did that port to recent 2.6.x and put it into patch-o-matic :(
I just did that with the old code from 2.6.0-testX. I didn't have the time to give it any runtime testing, but at least it compiled (after fixing up some includes).
Quoted 1 line
Our company can test patches and even (if I can) sponsor this work.
Please test the code that is now (Version 3605) in patch-o-matic-ng.
Quoted 1 line
Oleg V. Sapon.
Signature · 5 lines
- Harald Welte <[email protected]> http://www.netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie
Hi Harald,
Quoted 10 lines · Harald Welte
Quoted 2 lines · Oleg V. Sapon
Can you help locate unclean module for 2.6.x kernel or we must use source files from 2.6.0-test4?
I fear nobody did that port to recent 2.6.x and put it into patch-o-matic :(
I just did that with the old code from 2.6.0-testX. I didn't have the time to give it any runtime testing, but at least it compiled (after fixing up some includes).
I also ported the unclean patch to 2.6 some time ago. The main reason I did not post it was the slightly modified API.
The port I created verifies the checksums as well, relying on hardware checksums when possible. It also flags the clean packet in nfcache (that is where the API was changed) so that the TCP connection tracking code can rely on the results of the unclean match:
iptables -t raw -A PREROUTING -m unclean -j DROP
If there are plans to submit the unclean match into the kernel, I think something like my port should be considered.
In order to make the unclean patch acceptable for kernel inclusion, we could probably add a '--check-reserved' flag to it which would enable all checkings, while the default would skip checking the reserved bits.
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
include/linux/netfilter.h +2 -0
@@ -24,6 +24,8 @@<= 0x2000 is used for protocol-flags. */ #define NFC_UNKNOWN 0x4000#define NFC_ALTERED 0x8000 +/* #define NFC_TRACE 0x10000 */ +#define NFC_CLEAN 0x20000#ifdef __KERNEL__#include <linux/config.h>
include/linux/netfilter_ipv4/ip_tables.h +1 -0
@@ -355,6 +355,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop);
net/ipv4/netfilter/Kconfig +23 -0
@@ -610,6 +610,29 @@ <file:Documentation/modules.txt>. If unsure, say `N'. help +config IP_NF_MATCH_UNCLEAN + tristate 'unclean match support' + depends on IP_NF_RAW + help + Unclean packet matching matches any strange or invalid packets, + by looking at a series of fields in the IP, TCP, UDP and ICMP + headers. + + If you want to compile it as a module, say M here and read + Documentation/modules.txt. If unsure, say `N'. + +config IP_NF_MATCH_UNCLEAN_HWCSUM + bool 'unclean match supporting hardware checksumming' + default n + depends on IP_NF_MATCH_UNCLEAN + help + With this option enabled, the unclean match will be able + to use the hardware checksums generated by the network + interfaces (if those support HW checksumming) with the price + that the match can then be used only in the PREROUTING chain. + If the option is disabled, the match itself have to compute + the checksums but it can be used in any chain. + config IP_NF_TARGET_NOTRACK tristate 'NOTRACK target support' depends on IP_NF_RAW
net/ipv4/netfilter/Makefile +1 -0
@@ -67,6 +67,7 @@ obj-$(CONFIG_IP_NF_MATCH_ADDRTYPE) += ipt_addrtype.o obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o obj-$(CONFIG_IP_NF_MATCH_COMMENT) += ipt_comment.o +obj-$(CONFIG_IP_NF_MATCH_UNCLEAN) += ipt_unclean.o # targets obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
net/ipv4/netfilter/ip_conntrack_proto_tcp.c +4 -0
@@ -776,6 +776,10 @@struct tcphdr _tcph, *th;unsigned int tcplen = skb->len - iph->ihl *4 ;u_int8_t tcpflags; + +/* Already verified by ipt_unclean? */ +if (skb->nfcache &NFC_CLEAN ) +return NF_ACCEPT ;/* Smaller that minimal TCP header? */ th = skb_header_pointer(skb, iph->ihl * 4,
net/ipv4/netfilter/ip_tables.c +7 -1
@@ -238,11 +238,13 @@ const struct sk_buff *skb, const struct net_device *in, const struct net_device *out, + u_int32_t *nfcache, int offset, int *hotdrop) { /* Stop iteration if it doesn't match */ - if (!m->u.kernel.match->match(skb, in, out, m->data, offset, hotdrop)) + if (!m->u.kernel.match->match(skb, in, out, m->data, + nfcache, offset, hotdrop)) return 1; else return 0;
@@ -318,6 +320,7 @@if (IPT_MATCH_ITERATE (e, do_match, *pskb, in, out, + &(*pskb)->nfcache, offset, &hotdrop) !=0 ) goto no_match;
@@ -1491,6 +1494,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
@@ -1572,6 +1576,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
@@ -1645,6 +1650,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_addrtype.c +1 -1
@@ -29,7 +29,7 @@static int match (const struct sk_buff *skb,const struct net_device *in,const struct net_device *out,const void *matchinfo, -int offset,int *hotdrop) +u_int32_t *nfcache,int offset,int *hotdrop) {const struct ipt_addrtype_info *info = matchinfo;const struct iphdr *iph = skb->nh.iph;
net/ipv4/netfilter/ipt_ah.c +1 -0
@@ -40,6 +40,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_comment.c +1 -0
@@ -18,6 +18,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_conntrack.c +1 -0
@@ -23,6 +23,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_dscp.c +1 -1
@@ -21,7 +21,7 @@static int match (const struct sk_buff *skb,const struct net_device *in,const struct net_device *out,const void *matchinfo, -int offset,int *hotdrop) +u_int32_t *nfcache,int offset,int *hotdrop) {const struct ipt_dscp_info *info = matchinfo;const struct iphdr *iph = skb->nh.iph;
net/ipv4/netfilter/ipt_ecn.c +1 -1
@@ -67,7 +67,7 @@static int match (const struct sk_buff *skb,const struct net_device *in,const struct net_device *out,const void *matchinfo, -int offset,int *hotdrop) +u_int32_t *nfcache,int offset,int *hotdrop) {const struct ipt_ecn_info *info = matchinfo;
net/ipv4/netfilter/ipt_esp.c +1 -0
@@ -41,6 +41,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_helper.c +1 -0
@@ -34,6 +34,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_iprange.c +1 -0
@@ -28,6 +28,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) { const struct ipt_iprange_info *info = matchinfo;
net/ipv4/netfilter/ipt_length.c +1 -0
@@ -21,6 +21,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_limit.c +1 -0
@@ -67,6 +67,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_mac.c +1 -0
@@ -24,6 +24,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_mark.c +1 -0
@@ -22,6 +22,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_multiport.c +1 -0
@@ -51,6 +51,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_owner.c +1 -0
@@ -125,6 +125,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_physdev.c +1 -0
@@ -25,6 +25,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_pkttype.c +1 -0
@@ -21,6 +21,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_realm.c +1 -0
@@ -26,6 +26,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_recent.c +3 -1
@@ -103,6 +103,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop);
@@ -317,7 +318,7 @@ skb->nh.iph->daddr =0 ;/* Clear ttl since we have no way of knowing it */ skb->nh.iph->ttl =0 ; -match (skb,NULL ,NULL ,info,0 ,NULL ); +match (skb,NULL ,NULL ,info,NULL ,0 ,NULL );kfree (skb->nh.iph); out_free_skb:
@@ -356,6 +357,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_sctp.c +1 -0
@@ -117,6 +117,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_state.c +1 -0
@@ -23,6 +23,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_tcpmss.c +1 -0
@@ -78,6 +78,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_tos.c +1 -0
@@ -22,6 +22,7 @@const struct net_device *in, const struct net_device *out, const void *matchinfo, + u_int32_t *nfcache, int offset, int *hotdrop) {
net/ipv4/netfilter/ipt_ttl.c +1 -1
@@ -21,7 +21,7 @@static int match (const struct sk_buff *skb,const struct net_device *in,const struct net_device *out,const void *matchinfo, -int offset,int *hotdrop) +u_int32_t *nfcache,int offset,int *hotdrop) {const struct ipt_ttl_info *info = matchinfo;
net/ipv4/netfilter/ipt_unclean.c +687 -0
687 lines not on this page · raw message
Hi Jozsef!
Quoted 7 lines · Jozsef Kadlecsik
I also ported the unclean patch to 2.6 some time ago. The main reason I did not post it was the slightly modified API.
[...]
If there are plans to submit the unclean match into the kernel, I think something like my port should be considered.
No, I think we're pretty sure that we don't want to have it in the kernel again.
Quoted 1 line
Jozsef
Signature · 5 lines
- Harald Welte <[email protected]> http://www.netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie
Hi Harald,
Quoted 5 lines · Harald Welte
Quoted 2 lines
If there are plans to submit the unclean match into the kernel, I think something like my port should be considered.
No, I think we're pretty sure that we don't want to have it in the kernel again.
As far as I remember, the main concern was due to the ckecking of the reserved fields, which can cause forward-incompatibility. Was something else against the match? Just asking :-)
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
Quoted 3 lines · Jozsef Kadlecsik
As far as I remember, the main concern was due to the ckecking of the reserved fields, which can cause forward-incompatibility. Was something else against the match? Just asking :-)
yes, that's basically it, IIRC.
Quoted 1 line
Jozsef
Signature · 5 lines
- Harald Welte <[email protected]> http://www.netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie
Quoted 22 lines · Jozsef Kadlecsik
Hi Harald,
Quoted 7 lines · Harald Welte
Quoted 4 lines · Oleg V. Sapon
Can you help locate unclean module for 2.6.x kernel or we must use source files from 2.6.0-test4?
Quoted 8 lines
I fear nobody did that port to recent 2.6.x and put it into patch-o-matic :(
I just did that with the old code from 2.6.0-testX. I didn't have the time to give it any runtime testing, but at least it compiled (after fixing up some includes).
Quoted 6 lines
I also ported the unclean patch to 2.6 some time ago. The main reason I did not post it was the slightly modified API.
The port I created verifies the checksums as well, relying on hardware checksums when possible.
Hm, the error API makes sure that we don't start a session in the connection tracking with unclean packets (since kernel 2.6.6). So something like:
iptables -m state INVALID -j ULOG
should be enough to log evil packets.
The checkings aren't so strict as those that the unclean module used to do but with a couple of patches I could tighten that. Actually I remember a discussion with Jozsef about this. As far as I can remember he didn't like so much the idea of putting half of the unclean module there.
--
Pablo
Quoted 7 lines · Pablo Neira
Quoted 2 lines
The port I created verifies the checksums as well, relying on hardware checksums when possible.
Hm, the error API makes sure that we don't start a session in the connection tracking with unclean packets (since kernel 2.6.6). So something like:
Quoted 8 lines
iptables -m state INVALID -j ULOG
should be enough to log evil packets.
The checkings aren't so strict as those that the unclean module used to do but with a couple of patches I could tighten that. Actually I remember a discussion with Jozsef about this. As far as I can remember he didn't like so much the idea of putting half of the unclean module there.
The routines behind the error API perform just the very minimum checkings to make sure the packets can be processed by conntrack(/NAT) sanely. But that is all they are required to do, therefore I'd oppone to move other checkings from the unclean module to the error functions. The purpose of the conntrack subsytems is to keep track of the connections as perfectly as possible and nothing more. It must not implement filtering functions , because it's the task delegated to the filter(/raw) table.
Ideally, I'd like to see setups like:
- drop malformed (unclean) packets in the raw table, as early as possible, so they don't hit conntrack at all
- keep track of connections and doing so rely on the results of the unclean macth (if exists) to avoid double checkings
- mangle/nat/filter
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