All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Pablo Neira <pablo@eurodev.net>
Cc: Martin Josefsson <gandalf@wlug.westbo.se>,
	Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>,
	Netfilter Development Mailinglist
	<netfilter-devel@lists.netfilter.org>
Subject: Re: [PATCH] modification in current protocol helper API to handle error/unclean packets
Date: Mon, 21 Jun 2004 02:07:39 +0200	[thread overview]
Message-ID: <40D626CB.9090102@trash.net> (raw)
In-Reply-To: <40D60A2D.2080800@eurodev.net>

[-- Attachment #1: Type: text/plain, Size: 285 bytes --]

Pablo Neira wrote:
> Would you be willing to apply the patch attached to pom-ng? It applies 
> to linux-2.6.patch_02-udp-icmp and it adds more checkings for invalid 
> icmp combinations.

You should use the defined types for better readability. Something like
this ..

Regards
Patrick

[-- Attachment #2: x --]
[-- Type: text/plain, Size: 2760 bytes --]

===== net/ipv4/netfilter/ip_conntrack_proto_icmp.c 1.8 vs edited =====
--- 1.8/net/ipv4/netfilter/ip_conntrack_proto_icmp.c	2004-06-21 01:50:41 +02:00
+++ edited/net/ipv4/netfilter/ip_conntrack_proto_icmp.c	2004-06-21 02:03:10 +02:00
@@ -27,6 +27,38 @@
 #define DEBUGP(format, args...)
 #endif
 
+#define OK 1
+#define IV 0
+
+#define ICMP_ROUTER_ADV	9
+#define ICMP_ROUTER_SEL	10
+
+/* ICMP types and codes described in RFC's:
+ * 	- 792: Internet Control Message Protocol. Most types.
+ * 	- 1256: ICMP Router Discovery Messages. Types 9 and 10.
+ * 	- 950: Internet Standard Subnetting Procedure. Types 17 and 18.
+ * 	- 1812: Requirements for IP Version 4 Routers. Type 3. Section 5.2.7.1
+ */
+static u_int8_t icmp_valid[NR_ICMP_TYPES+1][NR_ICMP_UNREACH+1] = 
+{
+	/*                          0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 */
+	[ICMP_ECHOREPLY]	= {OK,IV,IV,IV,IV,IV,IV,IV,IV,IV,IV,I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,
 			     unsigned int dataoff,
 			     struct ip_conntrack_tuple *tuple)
@@ -245,6 +277,22 @@
 		if (LOG_INVALID(IPPROTO_ICMP))
 			nf_log_packet(PF_INET, 0, skb, NULL, NULL,
 				      "ip_ct_icmp: invalid ICMP type ");
+		return -NF_ACCEPT;
+	}
+
+	/* 15 is the highest 'known' ICMP code. See RFC 1812 */
+	if (icmph.code > NR_ICMP_UNREACH) {
+		if (LOG_INVALID(IPPROTO_ICMP))
+			nf_log_packet(PF_INET, 0, skb, NULL, NULL,
+				      "ip_ct_icmp: invalid ICMP code ");
+		return -NF_ACCEPT;
+	}
+
+	/* check for invalid combinations */
+	if (!icmp_valid[icmph.type][icmph.code]) {
+		if (LOG_INVALID(IPPROTO_ICMP))
+			nf_log_packet(PF_INET, 0, skb, NULL, NULL,
+				      "ip_ct_icmp: invalid ICMP type/code ");
 		return -NF_ACCEPT;
 	}
 

  reply	other threads:[~2004-06-21  0:07 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-14  0:10 [PATCH] modification in current protocol helper API to handle error/unclean packets Pablo Neira
2004-06-14  2:22 ` Patrick McHardy
2004-06-14  3:05   ` Patrick McHardy
2004-06-14 11:37   ` Pablo Neira
2004-06-14 14:03     ` Jozsef Kadlecsik
2004-06-17 12:09       ` Pablo Neira
2004-06-17 12:46         ` Patrick McHardy
2004-06-17 13:46           ` Pablo Neira
2004-06-17 14:15             ` Patrick McHardy
2004-06-17 17:26             ` Pablo Neira
2004-06-17 13:17         ` Jozsef Kadlecsik
2004-06-20 19:17         ` Martin Josefsson
2004-06-20 22:05           ` Pablo Neira
2004-06-21  0:07             ` Patrick McHardy [this message]
2004-06-22 12:19               ` Pablo Neira
2004-06-21  8:56             ` Jozsef Kadlecsik
2004-06-21 10:14               ` Henrik Nordstrom
2004-06-21 10:51                 ` Jozsef Kadlecsik
2004-06-22  4:39                   ` Willy Tarreau
2004-06-22 11:14                     ` Pablo Neira
2004-06-22 13:17                     ` Jozsef Kadlecsik
2004-06-22 13:31                       ` Jozsef Kadlecsik
2004-06-22 16:18                       ` Willy Tarreau
2004-06-21 12:46               ` Pablo Neira
2004-06-21 13:32                 ` Jozsef Kadlecsik
2004-06-21  8:11           ` Jozsef Kadlecsik
2004-06-14  9:05 ` Jozsef Kadlecsik
2004-06-21  4:20 ` Willy Tarreau
2004-06-21 13:40   ` Jozsef Kadlecsik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=40D626CB.9090102@trash.net \
    --to=kaber@trash.net \
    --cc=gandalf@wlug.westbo.se \
    --cc=kadlec@blackhole.kfki.hu \
    --cc=netfilter-devel@lists.netfilter.org \
    --cc=pablo@eurodev.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.