]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
UBUNTU: SAUCE: [nf,v2] netfilter: x_tables: don't rely on well-behaving userspace
authorFlorian Westphal <fw@strlen.de>
Thu, 10 Mar 2016 16:26:39 +0000 (17:26 +0100)
committerTim Gardner <tim.gardner@canonical.com>
Mon, 20 Feb 2017 03:57:58 +0000 (20:57 -0700)
BugLink: http://bugs.launchpad.net/bugs/1555338
Ben Hawkes says:

 In the mark_source_chains function (net/ipv4/netfilter/ip_tables.c) it
 is possible for a user-supplied ipt_entry structure to have a large
 next_offset field. This field is not bounds checked prior to writing a
 counter value at the supplied offset.

Problem is that xt_entry_foreach() macro stops iterating once e->next_offset
is out of bounds, assuming this is the last entry.

With malformed data thats not necessarily the case so we can
write outside of allocated area later as we might not have walked the
entire blob.

Fix this by simplifying mark_source_chains -- it already has to check
if nextoff is in range to catch invalid jumps, so just do the check
when we move to a next entry as well.

Also, check that the offset meets the xtables_entry alignment.

Reported-by: Ben Hawkes <hawkes@google.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Chris J. Arges <chris.j.arges@canonical.com>
Acked-by: Brad Figg <brad.figg@canonical.com>
Signed-off-by: Brad Figg <brad.figg@canonical.com>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
net/ipv4/netfilter/arp_tables.c
net/ipv4/netfilter/ip_tables.c
net/ipv6/netfilter/ip6_tables.c

index a467e1236c43ed1f3ecaa55524eb59722f1682e8..720fc81b09dd542945e79f3765b7bf37ee050876 100644 (file)
@@ -295,6 +295,17 @@ static inline bool unconditional(const struct arpt_entry *e)
               memcmp(&e->arp, &uncond, sizeof(uncond)) == 0;
 }
 
+static bool next_offset_ok(const struct xt_table_info *t, unsigned int newpos)
+{
+       if (newpos > t->size - sizeof(struct arpt_entry))
+               return false;
+
+       if (newpos % __alignof__(struct arpt_entry) != 0)
+               return false;
+
+       return true;
+}
+
 /* Figures out from what hook each rule can be called: returns 0 if
  * there are loops.  Puts hook bitmask in comefrom.
  */
@@ -360,6 +371,8 @@ static int mark_source_chains(const struct xt_table_info *newinfo,
 
                                /* Move along one */
                                size = e->next_offset;
+                               if (!next_offset_ok(newinfo, pos + size))
+                                       return 0;
                                e = (struct arpt_entry *)
                                        (entry0 + pos + size);
                                if (pos + size >= newinfo->size)
@@ -384,6 +397,10 @@ static int mark_source_chains(const struct xt_table_info *newinfo,
                                        if (newpos >= newinfo->size)
                                                return 0;
                                }
+
+                               if (!next_offset_ok(newinfo, newpos))
+                                       return 0;
+
                                e = (struct arpt_entry *)
                                        (entry0 + newpos);
                                e->counters.pcnt = pos;
index 91656a1d8fbd5b15b306383fe733751fef10f27c..a57af687374b6635318721da2eb11c181440f79d 100644 (file)
@@ -369,6 +369,17 @@ ipt_do_table(struct sk_buff *skb,
        else return verdict;
 }
 
+static bool next_offset_ok(const struct xt_table_info *t, unsigned int newpos)
+{
+       if (newpos > t->size - sizeof(struct ipt_entry))
+               return false;
+
+       if (newpos % __alignof__(struct ipt_entry) != 0)
+               return false;
+
+       return true;
+}
+
 /* Figures out from what hook each rule can be called: returns 0 if
    there are loops.  Puts hook bitmask in comefrom. */
 static int
@@ -430,6 +441,8 @@ mark_source_chains(const struct xt_table_info *newinfo,
 
                                /* Move along one */
                                size = e->next_offset;
+                               if (!next_offset_ok(newinfo, pos + size))
+                                       return 0;
                                e = (struct ipt_entry *)
                                        (entry0 + pos + size);
                                if (pos + size >= newinfo->size)
@@ -454,6 +467,10 @@ mark_source_chains(const struct xt_table_info *newinfo,
                                        if (newpos >= newinfo->size)
                                                return 0;
                                }
+
+                               if (!next_offset_ok(newinfo, newpos))
+                                       return 0;
+
                                e = (struct ipt_entry *)
                                        (entry0 + newpos);
                                e->counters.pcnt = pos;
index 25a022d41a7035f5350339b17c3cf68517496f85..b1b96c90543b3f463e333dbcfc59b53f87cc4c27 100644 (file)
@@ -398,6 +398,17 @@ ip6t_do_table(struct sk_buff *skb,
        else return verdict;
 }
 
+static bool next_offset_ok(const struct xt_table_info *t, unsigned int newpos)
+{
+       if (newpos > t->size - sizeof(struct ip6t_entry))
+               return false;
+
+       if (newpos % __alignof__(struct ip6t_entry) != 0)
+               return false;
+
+       return true;
+}
+
 /* Figures out from what hook each rule can be called: returns 0 if
    there are loops.  Puts hook bitmask in comefrom. */
 static int
@@ -459,6 +470,8 @@ mark_source_chains(const struct xt_table_info *newinfo,
 
                                /* Move along one */
                                size = e->next_offset;
+                               if (!next_offset_ok(newinfo, pos + size))
+                                       return 0;
                                e = (struct ip6t_entry *)
                                        (entry0 + pos + size);
                                if (pos + size >= newinfo->size)
@@ -483,6 +496,10 @@ mark_source_chains(const struct xt_table_info *newinfo,
                                        if (newpos >= newinfo->size)
                                                return 0;
                                }
+
+                               if (!next_offset_ok(newinfo, newpos))
+                                       return 0;
+
                                e = (struct ip6t_entry *)
                                        (entry0 + newpos);
                                e->counters.pcnt = pos;