netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Engelhardt <jengelh@medozas.de>
To: pablo@netfilter.org
Cc: kaber@trash.net, netfilter-devel@vger.kernel.org
Subject: [PATCH 07/13] ip[6]tables: only call match's parse function when option char is in range
Date: Sat,  8 Jan 2011 16:20:08 +0100	[thread overview]
Message-ID: <1294500015-10691-8-git-send-email-jengelh@medozas.de> (raw)
In-Reply-To: <1294500015-10691-1-git-send-email-jengelh@medozas.de>

Normally, extensions use a "default:" case in switch(c) to just return
if they do not handle c. Apparently, libip6t_hl does that too late and
checks for hl-specific parsing state before it has established that c
refers to one of its own options.

Also affected: libipt_ttl, libxt_ipvs, libxt_policy, libxt_statistic.

One way to fix this is to move the flags checks into case '2', '3',
'4'. Doing this replication feels bad, so as an alternative, let's
just free extensions from having to deal with other extension's
options passing thru.

References: http://marc.info/?l=netfilter-devel&m=129444759532377&w=2
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
 ip6tables.c |    3 +++
 iptables.c  |    3 +++
 xshared.h   |    4 ++++
 xtables.c   |    4 ++--
 4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/ip6tables.c b/ip6tables.c
index b8449f6..4ca4bfe 100644
--- a/ip6tables.c
+++ b/ip6tables.c
@@ -1714,6 +1714,9 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
 					if (matchp->completed ||
 					    matchp->match->parse == NULL)
 						continue;
+					if (c < matchp->match->option_offset ||
+					    c >= matchp->match->option_offset + XT_OPTION_OFFSET_SCALE)
+						continue;
 					if (matchp->match->parse(c - matchp->match->option_offset,
 						     argv, invert,
 						     &matchp->match->mflags,
diff --git a/iptables.c b/iptables.c
index e0efbf1..bcacd49 100644
--- a/iptables.c
+++ b/iptables.c
@@ -1746,6 +1746,9 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handle
 					if (matchp->completed ||
 					    matchp->match->parse == NULL)
 						continue;
+					if (c < matchp->match->option_offset ||
+					    c >= matchp->match->option_offset + XT_OPTION_OFFSET_SCALE)
+						continue;
 					if (matchp->match->parse(c - matchp->match->option_offset,
 						     argv, invert,
 						     &matchp->match->mflags,
diff --git a/xshared.h b/xshared.h
index c53b618..e5b2a02 100644
--- a/xshared.h
+++ b/xshared.h
@@ -4,6 +4,10 @@
 struct xtables_rule_match;
 struct xtables_target;
 
+enum {
+	XT_OPTION_OFFSET_SCALE = 256,
+};
+
 extern void print_extension_helps(const struct xtables_target *,
 	const struct xtables_rule_match *);
 
diff --git a/xtables.c b/xtables.c
index b630901..5b7526c 100644
--- a/xtables.c
+++ b/xtables.c
@@ -49,7 +49,7 @@
 #	define IP6T_SO_GET_REVISION_TARGET	69
 #endif
 #include <getopt.h>
-
+#include "xshared.h"
 
 #define NPROTO	255
 
@@ -111,7 +111,7 @@ struct option *xtables_merge_options(struct option *orig_opts,
 	mp = merge + num_oold;
 
 	/* Second, the new options */
-	xt_params->option_offset += 256;
+	xt_params->option_offset += XT_OPTION_OFFSET_SCALE;
 	*option_offset = xt_params->option_offset;
 	memcpy(mp, newopts, sizeof(*mp) * num_new);
 
-- 
1.7.1


  parent reply	other threads:[~2011-01-08 15:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-08 15:20 iptables: accumulated bugfixes and annotations Jan Engelhardt
2011-01-08 15:20 ` [PATCH 01/13] iptables-restore: resolve confusing policy error message Jan Engelhardt
2011-01-08 15:20 ` [PATCH 02/13] src: const annotations Jan Engelhardt
2011-01-08 15:20 ` [PATCH 03/13] xt_comment: remove redundant cast Jan Engelhardt
2011-01-08 15:20 ` [PATCH 04/13] src: use C99/POSIX types Jan Engelhardt
2011-01-08 15:20 ` [PATCH 05/13] iptables: abort on empty interface specification Jan Engelhardt
2011-01-08 15:20 ` [PATCH 06/13] xtables: reorder num_old substraction for clarity Jan Engelhardt
2011-01-08 15:20 ` Jan Engelhardt [this message]
2011-01-08 15:20 ` [PATCH 08/13] ip[6]tables: only call target's parse function when option char is in range Jan Engelhardt
2011-01-08 15:20 ` [PATCH 09/13] extensions: remove no longer necessary default: cases Jan Engelhardt
2011-01-08 15:20 ` [PATCH 10/13] libxt_sctp: fix a typo Jan Engelhardt
2011-01-08 15:20 ` [PATCH 11/13] libipt_CLUSTERIP: const annotations Jan Engelhardt
2011-01-08 15:20 ` [PATCH 12/13] libxtables: do some option structure checking Jan Engelhardt
2011-01-08 15:20 ` [PATCH 13/13] libipt_REDIRECT: avoid dereference of uninitialized pointer Jan Engelhardt
2011-01-09 19:16 ` iptables: accumulated bugfixes and annotations Pablo Neira Ayuso

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=1294500015-10691-8-git-send-email-jengelh@medozas.de \
    --to=jengelh@medozas.de \
    --cc=kaber@trash.net \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).