Skip to contentSkip to conversation

OSF: pom-ng - linux-2.6.

PATCH Applied Evgeniy Polyakov 3 participants 8 messages Dec 8, 2004 – Jan 2, 2005 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 OSF: pom-ng - linux-2.6.

Since OSF originally was created in 2.5 environment it is strange not to have 2.6 support for OSF. This(similar) patch was sent some time ago but was lost. Please apply.

Signature · 3 lines
        Evgeniy Polyakov

Crash is better than data corruption -- Arthur Grabowski
home/s0mbre/aWork/tmp/osf/ipt_osf.c renamed from tmp/osf/ipt_osf.c +24 -13
@@ -52,14 +52,15 @@
 
 #include "ipt_osf.h"
 
-#define OSF_DEBUG
+//#define OSF_DEBUG
+#undef OSF_DEBUG
 
 #ifdef OSF_DEBUG
 #define log(x...) 		printk(KERN_INFO "ipt_osf: " x)
 #define loga(x...) 		printk(x)
 #else
-#define log(x...) 		do {} while(0)
-#define loga(x...) 		do {} while(0)
+#define log(x...)
+#define loga(x...)
 #endif
 
 #define FMATCH_WRONG		0
@@ -76,7 +77,7 @@
 static struct list_head	finger_list;	
 static int match(const struct sk_buff *, const struct net_device *, const struct net_device *,
 		      const void *, int, 
-		      const void *, u_int16_t, 
+		      //const void *, u_int16_t, 
 		      int *);
 static int checkentry(const char *, const struct ipt_ip *, void *,
 		           unsigned int, unsigned int);
@@ -153,7 +154,7 @@
 static int
 match(const struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
       const void *matchinfo, int offset,
-      const void *hdr, u_int16_t datalen,
+      //const void *hdr, u_int16_t datalen,
       int *hotdrop)
 {
 	struct ipt_osf_info *info = (struct ipt_osf_info *)matchinfo;
@@ -184,7 +185,6 @@
 		optsize = tcp->doff*4 - sizeof(struct tcphdr);
 	}
 
-	
 	/* Actually we can create hash/table of all genres and search
 	 * only in appropriate part, but here is initial variant,
 	 * so will use slow path.
@@ -414,7 +414,10 @@
 	}
 
 	read_unlock(&osf_lock);
-
+	
+	if (fcount)
+		fmatch = FMATCH_OK;
+	
 	return (fmatch == FMATCH_OK)?1:0;
 }
 
@@ -600,9 +603,10 @@
 {
 	struct list_head *ent;
 	struct osf_finger *f = NULL;
-	int i;
+	int i, __count, err;
 	
 	*eof = 1;
+	__count = count;
 	count = 0;
 
 	read_lock_bh(&osf_lock);
@@ -612,10 +616,13 @@
 
 		log("%s [%s]", f->genre, f->details);
 		
-		count += sprintf(buf+count, "%s - %s[%s] : %s", 
+		err = snprintf(buf+count, __count-count, "%s - %s[%s] : %s", 
 					f->genre, f->version,
 					f->subtype, f->details);
-		
+		if (err == 0 || __count <= count + err)
+			break;
+		else
+			count += err;
 		if (f->opt_num)
 		{
 			loga(" OPT: ");
@@ -629,7 +636,11 @@
 			}
 		}
 		loga("\n");
-		count += sprintf(buf+count, "\n");
+		err = snprintf(buf+count, __count-count, "\n");
+		if (err == 0 || __count <= count + err)
+			break;
+		else
+			count += err;
 	}
 	read_unlock_bh(&osf_lock);
 
@@ -844,8 +855,8 @@
 	
 	remove_proc_entry("sys/net/ipv4/osf", NULL);
 	ipt_unregister_match(&osf_match);
-	if (nts && nts->socket)
-		sock_release(nts->socket);
+	if (nts && nts->sk_socket)
+		sock_release(nts->sk_socket);
 
 	list_for_each_safe(ent, n, &finger_list)
 	{
#1 lore raw
Quoted 6 lines · Evgeniy Polyakov

Since OSF originally was created in 2.5 environment it is strange not to have 2.6 support for OSF. This(similar) patch was sent some time ago but was lost. Please apply.

My dear hands, please contact my brain before doing anything. Thanks.

Proper patch attached.

Signature · 3 lines
        Evgeniy Polyakov

Crash is better than data corruption -- Arthur Grabowski
osf/info +0 -1
diff -Nru patch-o-matic-ng-20040621-orig/osf/info patch-o-matic-ng-20040621/osf/info
@@ -1,3 +1,2 @@
 Author: Evgeniy Polyakov <[email protected]>
 Repository: base
-Requires: linux < 2.6.0
osf/linux-2.6/include/linux/netfilter_ipv4/ipt_osf.h +148 -0

148 lines not on this page · raw message

osf/linux-2.6/net/ipv4/netfilter/ipt_osf.c +863 -0

863 lines not on this page · raw message

osf/linux-2.6/net/ipv4/netfilter/Kconfig.ladd +21 -0
diff -Nru patch-o-matic-ng-20040621-orig/osf/linux-2.6/net/ipv4/netfilter/Kconfig.ladd patch-o-matic-ng-20040621/osf/linux-2.6/net/ipv4/netfilter/Kconfig.ladd
@@ -0,0 +1,21 @@
+config IP_NF_MATCH_OSF
+	tristate  'OSF match support'
+	depends on IP_NF_IPTABLES
+	help
+	
+	  The idea of passive OS fingerprint matching exists for quite a long time,
+	  but was created as extension fo OpenBSD pf only some weeks ago.
+	  Original idea was lurked in some OpenBSD mailing list (thanks
+	  grange@open...) and than adopted for Linux netfilter in form of this code.
+	
+	  Original table was created by Michal Zalewski <[email protected]> for
+	  his excellent p0f and than changed a bit for more convenience.
+	
+	  This module compares some data(WS, MSS, options and it's order, ttl,
+	  df and others) from first SYN packet (actually from packets with SYN
+	  bit set) with hardcoded in fingers[] table ones.
+	
+	  If you say Y here, try iptables -m osf --help for more information.
+	 
+	  If you want to compile it as a module, say M here and read
+	  Documentation/modules.txt.  If unsure, say `N'.
osf/linux-2.6/net/ipv4/netfilter/Makefile.ladd +4 -0
diff -Nru patch-o-matic-ng-20040621-orig/osf/linux-2.6/net/ipv4/netfilter/Makefile.ladd patch-o-matic-ng-20040621/osf/linux-2.6/net/ipv4/netfilter/Makefile.ladd
@@ -0,0 +1,4 @@
+obj-$(CONFIG_IP_NF_MATCH_TOS) += ipt_tos.o
+
+obj-$(CONFIG_IP_NF_MATCH_OSF) += ipt_osf.o
+
#5 lore raw
In reply to Evgeniy Polyakov

i got you doing the same.

Quoted 1 line · Evgeniy Polyakov

+ nts = netlink_kernel_create(NETLINK_NFLOG, NULL);

drivers/w1/w1_int.c: dev->nls = netlink_kernel_create(NETLINK_NFLOG, NULL);

NETLINK_NFLOG is used by ipt_ULOG, you can't use that socket because you are breaking compatibility. You have to use different sockets, call davem and request new ones.

kind regards,
Pavel

#6 lore raw
Quoted 11 lines · Pavel A. Nekrasov

i got you doing the same.

Quoted 1 line · Evgeniy Polyakov

+ nts = netlink_kernel_create(NETLINK_NFLOG, NULL);

drivers/w1/w1_int.c: dev->nls = netlink_kernel_create(NETLINK_NFLOG, NULL);

NETLINK_NFLOG is used by ipt_ULOG, you can't use that socket because you are breaking compatibility. You have to use different sockets, call davem and request new ones.

No, ipt_osf used this number forever.
And it was discussed with Harald some time ago.

Allocating new socket number for any new driver that want to communicate over netlink is badly broken idea.
I've created so called "kernel connector" aka ioctl-ng to solve this problem, and this patch is flying around for some time, but until it is
committed we should not break old compatibility issues.

Quoted 2 lines

kind regards,
Pavel

Signature · 3 lines
        Evgeniy Polyakov

Crash is better than data corruption -- Arthur Grabowski
#7 lore raw
In reply to Evgeniy Polyakov
Quoted 5 lines · Evgeniy Polyakov

Since OSF originally was created in 2.5 environment it is strange not to have 2.6 support for OSF. This(similar) patch was sent some time ago but was lost.
Please apply.

Please send patches that apply -p1 in the patch-o-matic-ng directory in the future. Your patch doesn't apply at all:

~/src/nf/svn/netfilter/trunk/patch-o-matic-ng/osf/linux-2.6/net/ipv4/netfilter$ patch -p6 </tmp/ipt_osf --dry-run missing header for unified diff at line 3 of patch
(Stripping trailing CRs from patch.)
patching file ipt_osf.c
Hunk #1 succeeded at 52 with fuzz 2.
Hunk #2 FAILED at 77.
Hunk #3 FAILED at 154.
Hunk #4 FAILED at 185.
Hunk #5 FAILED at 414.
Hunk #6 FAILED at 603.
Hunk #7 FAILED at 616.
Hunk #8 FAILED at 636.
Hunk #9 FAILED at 855.
8 out of 9 hunks FAILED -- saving rejects to file ipt_osf.c.rej

To make osf fit for 2.6, you also need to handle non-linear skbs.

Regards
Patrick

#2 lore raw
In reply to Evgeniy Polyakov
Quoted 7 lines · Evgeniy Polyakov
Quoted 4 lines · Evgeniy Polyakov

Since OSF originally was created in 2.5 environment it is strange not to have 2.6 support for OSF. This(similar) patch was sent some time ago but was lost.
Please apply.

Quoted 8 lines
Quoted 3 lines

My dear hands, please contact my brain before doing anything. Thanks.

And I need to read first before complaining :)

Quoted 3 lines

Proper patch attached.

Still doesn't apply, it seems to be present already. The latest change was two month ago.

~/src/nf/svn/netfilter/trunk/patch-o-matic-ng$ patch -p1 </tmp/pom.diff --dry-run (Stripping trailing CRs from patch.)
patching file osf/info
Reversed (or previously applied) patch detected! Assume -R? [n]
Apply anyway? [n]
Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file osf/info.rej
The next patch would create the file osf/linux-2.6/include/linux/netfilter_ipv4/ipt_osf.h, which already exists! Assume -R? [n]
Apply anyway? [n]
Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file osf/linux-2.6/include/linux/netfilter_ipv4/ipt_osf.h.rej The next patch would create the file osf/linux-2.6/net/ipv4/netfilter/ipt_osf.c,
which already exists! Assume -R? [n]
Apply anyway? [n]
Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file osf/linux-2.6/net/ipv4/netfilter/ipt_osf.c.rej The next patch would create the file osf/linux-2.6/net/ipv4/netfilter/Kconfig.ladd,
which already exists! Assume -R? [n]
Apply anyway? [n]
Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file osf/linux-2.6/net/ipv4/netfilter/Kconfig.ladd.rej The next patch would create the file osf/linux-2.6/net/ipv4/netfilter/Makefile.ladd, which already exists! Assume -R? [n]
Apply anyway? [n]
Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file osf/linux-2.6/net/ipv4/netfilter/Makefile.ladd.rej

Anyhow, it still needs to handle non-linear skbs. Have a look at the other matches and their use of skb_header_pointer.

Regards
Patrick

#3 lore raw
Quoted 18 lines · On Wed, 08 Dec 2004 19:48:44 +0100 Patrick McHardy <[email protected]> wrote:
Quoted 8 lines · Evgeniy Polyakov
Quoted 5 lines · Evgeniy Polyakov

Since OSF originally was created in 2.5 environment it is strange not to have 2.6 support for OSF. This(similar) patch was sent some time ago but was lost. Please apply.

Quoted 8 lines
Quoted 3 lines

My dear hands, please contact my brain before doing anything. Thanks.

Quoted 7 lines

And I need to read first before complaining :)

Quoted 3 lines

Proper patch attached.

Still doesn't apply, it seems to be present already. The latest change was two month ago.

Yep, my fault, I saw into the latest pom-ng.

...

Quoted 2 lines

Anyhow, it still needs to handle non-linear skbs. Have a look at the other matches and their use of skb_header_pointer.

Sure.
Patch attached, although I do not quite understand what should be done with a poor skb to move IP and TCP headers into the fragments...

P.S. patch was done against my own tree, but should be applied against CVS, probably with some fuzz. I can not test it with the latest CVS since pserver.netfilter.org:2401 is not accessible.

P.P.S. I do not have 2.4 sources but if 2.4 has skb_header_pointer (as long as it has skb_copy_bits()) patch can be applied against it as well, but path in diff should be changed. If needed it is attached as well.

Quoted 2 lines

Regards
Patrick

Evgeniy Polyakov

Only failure makes us experts. -- Theo de Raadt

osf/linux/net/ipv4/netfilter/ipt_osf.c +25 -7
@@ -158,20 +158,30 @@
       int *hotdrop)
 {
 	struct ipt_osf_info *info = (struct ipt_osf_info *)matchinfo;
-	struct iphdr *ip = skb->nh.iph;
-	struct tcphdr *tcp;
+	struct iphdr _iph, *ip;
+	struct tcphdr _tcph, *tcp;
 	int fmatch = FMATCH_WRONG, fcount = 0;
 	unsigned long totlen, optsize = 0, window;
 	unsigned char df, *optp = NULL, *_optp = NULL;
+	unsigned char opts[MAX_IPOPTLEN];
 	char check_WSS = 0;
 	struct list_head *ent;
 	struct osf_finger *f;
+	int off;
 
-	if (!ip || !info)
+	if (!info)
+		return 0;
+	
+	off = 0;
+	
+	ip = skb_header_pointer(skb, off, sizeof(_iph), &_iph);
+	if (!ip)
 		return 0;
 				
-	tcp = (struct tcphdr *)((u_int32_t *)ip + ip->ihl);
-
+	tcp = skb_header_pointer(skb, off + ip->ihl * 4, sizeof(_tcph), &_tcph);
+	if (!tcp)
+		return 0;
+	
 	if (!tcp->syn)
 		return 0;
 	
@@ -181,8 +191,16 @@
 	
 	if (tcp->doff*4 > sizeof(struct tcphdr))
 	{
-		_optp = optp = (char *)(tcp+1);
 		optsize = tcp->doff*4 - sizeof(struct tcphdr);
+
+		if (optsize > sizeof(opts))
+		{
+			log("%s: BUG: too big options size: optsize=%lu, max=%d.\n",
+					__func__, optsize, sizeof(opts));
+			optsize = sizeof(opts);
+		}
+		
+		_optp = optp = skb_header_pointer(skb, off + ip->ihl*4 + sizeof(_tcph), optsize, opts);
 	}
 
 	/* Actually we can create hash/table of all genres and search
@@ -375,7 +393,7 @@
 		if (optp)
 		{
 			optsize = tcp->doff * 4 - sizeof(struct tcphdr);
-			if (skb_copy_bits(skb, ip->ihl*4 + sizeof(struct tcphdr),
+			if (skb_copy_bits(skb, off + ip->ihl*4 + sizeof(struct tcphdr),
 					  opt, optsize) < 0)
 			{
 				if (info->flags & IPT_OSF_LOG)
#4 lore raw
Quoted 10 lines · Evgeniy Polyakov
Quoted 3 lines · On Wed, 08 Dec 2004 19:48:44 +0100 Patrick McHardy <[email protected]> wrote:

Anyhow, it still needs to handle non-linear skbs. Have a look at the other matches and their use of skb_header_pointer.

Sure.
Patch attached, although I do not quite understand what should be done with a poor skb to move IP and TCP headers into the fragments...

Applied, sorry for the delay. Copying the ip-header is not necessary, but the TCP header may be nonlinear because of defragmentation.

Quoted 5 lines

P.P.S. I do not have 2.4 sources but if 2.4 has skb_header_pointer (as long as it has skb_copy_bits()) patch can be applied against it as well, but path in diff should be changed. If needed it is attached as well.

2.4 doesn't need this change, netfilter always gets linearized skbs.

Regards
Patrick