: Fix {ip,ip6,arp}_tables hook validation
Subsystems (2)
This patch fixes a regression from the "[NETFILTER]: Missed and reordered checks in iptables" patch. I'll send a new backport to the -stable guys as well.
Please apply, thanks.
[NETFILTER]: Fix {ip,ip6,arp}_tables hook validation
Commit 590bdf7fd2292b47c428111cb1360e312eff207e introduced a regression in match/target hook validation. mark_source_chains builds a bitmask for each rule representing the hooks it can be reached from, which is then used by the matches and targets to make sure they are only called from valid hooks. The patch moved the match/target specific validation before the mark_source_chains call, at which point the mask is always zero.
This patch returns back to the old order and moves the standard checks to mark_source_chains. This allows to get rid of a special case for standard targets as a nice side-effect.
---
commit b8a25b3ee8cbef39ebfcd7028c09ed6cd76b1488
tree 927db35a9e29098e01117be2e4ebef3663f6deb2
parent 3b8b1fc76b8f4d2f491d565cb56eb482da8c5007
author Dmitry Mishin <[email protected]> Tue, 21 Nov 2006 10:59:00 +0100 committer Patrick McHardy <[email protected]> Tue, 21 Nov 2006 11:26:09 +0100
net/ipv4/netfilter/arp_tables.c | 48 ++++++++++++++-------------- net/ipv4/netfilter/ip_tables.c | 68 ++++++++++++++------------------------- net/ipv6/netfilter/ip6_tables.c | 59 +++++++++++++--------------------- 3 files changed, 72 insertions(+), 103 deletions(-)
net/ipv4/netfilter/arp_tables.c +24 -24
@@ -375,6 +375,13 @@ static int mark_source_chains(struct xt_ && unconditional(&e->arp)) {unsigned int oldpos, size; +if (t->verdict < -NF_MAX_VERDICT -1 ) { +duprintf ("mark_source_chains: bad " +"negative verdict (%i)\n" , + t->verdict); +return 0 ; + } +/* Return: backtrack through the last * big jump. */
@@ -404,6 +411,14 @@ static int mark_source_chains(struct xt_if (strcmp (t->target.u.user.name,ARPT_STANDARD_TARGET ) ==0 && newpos >=0 ) { +if (newpos > newinfo->size - +sizeof (struct arpt_entry )) { +duprintf ("mark_source_chains: " +"bad verdict (%i)\n" , + newpos); +return 0 ; + } +/* This a jump; chase it. */ duprintf ("Jump rule %u -> %u\n" , pos, newpos);
@@ -426,8 +441,6 @@ static int mark_source_chains(struct xt_static inline int standard_check (const struct arpt_entry_target *t,unsigned int max_offset) { -struct arpt_standard_target *targ = (void *)t; -/* Check standard info. */ if (t->u.target_size !=ARPT_ALIGN (sizeof (struct arpt_standard_target ))) {
@@ -437,18 +450,6 @@ static inline int standard_check(const sreturn 0 ; } -if (targ->verdict >=0 - && targ->verdict > max_offset -sizeof (struct arpt_entry )) { -duprintf ("arpt_standard_check: bad verdict (%i)\n" , - targ->verdict); -return 0 ; - } - -if (targ->verdict < -NF_MAX_VERDICT -1 ) { -duprintf ("arpt_standard_check: bad negative verdict (%i)\n" , - targ->verdict); -return 0 ; - }return 1 ; }
@@ -627,18 +628,20 @@ static int translate_table(const char *n } } +if (!mark_source_chains (newinfo, valid_hooks, entry0)) { +duprintf ("Looping hook\n" ); +return -ELOOP ; + } +/* Finally, each sanity check must pass */ i =0 ; ret =ARPT_ENTRY_ITERATE (entry0, newinfo->size, check_entry, name, size, &i); -if (ret !=0 ) - goto cleanup; - - ret = -ELOOP ; -if (!mark_source_chains (newinfo, valid_hooks, entry0)) { -duprintf ("Looping hook\n" ); - goto cleanup; +if (ret !=0 ) { +ARPT_ENTRY_ITERATE (entry0, newinfo->size, + cleanup_entry, &i); +return ret; }/* And one copy for every other CPU */
@@ -647,9 +650,6 @@ static int translate_table(const char *nmemcpy (newinfo->entries[i], entry0, newinfo->size); } -return 0 ; -cleanup: -ARPT_ENTRY_ITERATE (entry0, newinfo->size, cleanup_entry, &i);return ret; }
net/ipv4/netfilter/ip_tables.c +25 -43
120 lines not on this page · raw message
net/ipv6/netfilter/ip6_tables.c +23 -36
100 lines not on this page · raw message
From: Patrick McHardy <[email protected]>
Date: Tue, 21 Nov 2006 11:30:50 +0100
Quoted 5 lines
This patch fixes a regression from the "[NETFILTER]: Missed and reordered checks in iptables" patch. I'll send a new backport to the -stable guys as well.
Please apply, thanks.
Applied, thanks Patrick.