Skip to contentSkip to conversation

Fun for netfilter developers :)

DISCUSSION Harald Welte 2 participants 4 messages May 6, 2003 netfilter

lore
Share & tools
lore
#0 lore raw

Fun for netfilter developers :)

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

Check this thing out:

	http://lwn.net/Articles/31207/

Basically, it's a SCO "security fix" in the form of a netfilter module that blocks all TCP packets with SYN and FIN set at the same time.

I don't know whether to laugh or cry. :(

#1 lore raw
Quoted 1 line · Harald Welte

Fun for netfilter developers :)

I would love to laugh, but I cannot easily find out what to make of that 4k binary file (extension 'rpm', presumably the source) that they link to. The tools (rpm and alien) that my Debian has for dealing with RPMs, look scary to me (require superuser...)

I know I could learn a lot about RPM. I managed without, up to now.

Inertia sets in...

So, sorry, I cannot laugh. I can only step down this soapbox, again :)

Quoted 1 line
	http://lwn.net/Articles/31207/

best regards
Patrick

#2 lore raw
Quoted 7 lines · Patrick Schaaf
Quoted 1 line · Harald Welte

Fun for netfilter developers :)

I would love to laugh, but I cannot easily find out what to make of that 4k binary file (extension 'rpm', presumably the source) that they link to. The tools (rpm and alien) that my Debian has for dealing with RPMs, look scary to me (require superuser...)

A source RPM does not need superuser privilege to be installed, since 'rpm -i' will just extract the source and the SPEC file.

See the attached source file, as it is contained in that .src.rpm file.

Quoted 1 line

I know I could learn a lot about RPM. I managed without, up to now.

You've missed something. Well, but I'm a real RPM-lover. I use debian only because I want to have the same distribution on all of my systems (sparc32,sparc64,ppc,x86) and there's a dpkg for almost anything.

Please _do not_ follow up onto the list about the package manager subject, as it is totally off topic.

Quoted 1 line

So, sorry, I cannot laugh. I can only step down this soapbox, again :)

Maybe now you can laugh. At least they did care about T/TCP.

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

/*
* TCP security netfilter hook
*
* Handles following TCP security issues :
* CERT VU#464113 - tcp SYN with FIN/RST packets not discarded. *
* Co-exists with all other standard netfilter modules.
* Written by Ashish Kalra, the SCO Group ( [email protected] ) */

#include <linux/module.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4/ip_tables.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/tcp.h>

/* new tcp options ( for t/tcp ) */
#define CC_opt 11 /* connection count */
#define CCnew_opt 12 /* new connection count */
#define CCecho_opt 13 /* connection count echo */

#define EOL 0 /* End-of-TCP options list (EOL) */

nf_hookfn tcp_sec_hook;

static struct nf_hook_ops tcp_sec_ops[]
= { { { NULL, NULL }, tcp_sec_hook, PF_INET, NF_IP_LOCAL_IN, NF_IP_PRI_FILTER }, };

unsigned int
tcp_sec_hook(unsigned int hook,
struct sk_buff **pskb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))

{
	struct iphdr *iph;
	struct tcphdr *tcph;
	struct sk_buff *skb_in = *pskb;

	iph = skb_in->nh.iph;

	if (iph->protocol == IPPROTO_TCP) {
		tcph = (struct tcphdr *)((__u32 *) iph+iph->ihl );

		/*
		 * T/TCP control segments can have SYN & FIN together to
		 * reduce overall TCP segments, i.e, SYN+FIN is legal 
		 * especially for T/TCP segments. Discarding SYN+FIN packets
		 * will break T/TCP, hence checking if the packet contains
		 * new TCP - TTCP/TAO (TCP accelerated open) options, then allow
		 * the packet, if not discard it.
		 */
		if (tcph->syn && tcph->fin) { 
			unsigned int opt_offset = sizeof(struct tcphdr);
			unsigned char *optp = (unsigned char *)tcph;

			while (opt_offset < (tcph->doff << 2)) {
				/*	printk(KERN_ALERT "opt = %d\n",
							optp[opt_offset]); */
				switch (optp[opt_offset]) {
					case CC_opt: 
					case CCnew_opt:
					case CCecho_opt:
						return NF_ACCEPT;
					case EOL:
						return NF_DROP;
					default :
						;
				}

				if (optp[opt_offset] < 2) ++opt_offset;
				else opt_offset += optp[opt_offset+1]?:1;
			}
			return NF_DROP; 
		}

		if (tcph->syn && tcph->rst) {
			/* printk(KERN_ALERT "tcp syn+rst segment\n"); */
			return NF_DROP;
		}

		/* No need to check for SYN+ACK, as initial SYN to open a
		 * connection is one of the few segments that does not contain
		 * an ACK. Linux TCP will anyway discard any ACK packet it 
		 * receives in LISTEN state
		 */
	}

	return NF_ACCEPT;
}

static int tcp_sec_init(void)

{
	int ret;

	ret = nf_register_hook(tcp_sec_ops);
	if (ret < 0) {
		printk(KERN_ALERT "nf_register_hook failed\n");
		return -ENODEV;
	}
	return 0;
}

static void tcp_sec_cleanup_module (void)

{
	nf_unregister_hook(tcp_sec_ops);
}

module_init(tcp_sec_init);
module_exit(tcp_sec_cleanup_module);

#3 lore raw
Quoted 1 line

Please _do not_ [XXX]

Of course. Sorry for the outburst, and thanks JF for the rpm2cpio snippet.

Quoted 1 line

At least they did care about T/TCP.

I wonder whether they had a need, or whether it was a completely academic exercize.

In any case, I'd be wary of LOCAL_IN PRI_FILTER, as that should be prone to module load order weirdness.

And, isn't the "functionality" already in UNCLEAN (if sane)?

all the best
Patrick