]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
netfilter: x_tables: add compat version of xt_check_entry_offsets
authorFlorian Westphal <fw@strlen.de>
Fri, 1 Apr 2016 12:17:26 +0000 (14:17 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 24 Jun 2016 17:18:23 +0000 (10:18 -0700)
commit fc1221b3a163d1386d1052184202d5dc50d302d1 upstream.

32bit rulesets have different layout and alignment requirements, so once
more integrity checks get added to xt_check_entry_offsets it will reject
well-formed 32bit rulesets.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/netfilter/x_tables.h
net/ipv4/netfilter/arp_tables.c
net/ipv4/netfilter/ip_tables.c
net/ipv6/netfilter/ip6_tables.c
net/netfilter/x_tables.c

index 1d2657fd29d92e3453aef5cf9eb83f080f029356..e3a3d0594742210626992d95968195f2a1552551 100644 (file)
@@ -492,6 +492,9 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr,
                                unsigned int *size);
 int xt_compat_target_to_user(const struct xt_entry_target *t,
                             void __user **dstptr, unsigned int *size);
+int xt_compat_check_entry_offsets(const void *base,
+                                 unsigned int target_offset,
+                                 unsigned int next_offset);
 
 #endif /* CONFIG_COMPAT */
 #endif /* _X_TABLES_H */
index ae7344f245c88845f6c1d90f5bf5409215dd7ec6..b05405fd9f9413c36c84322c8254e94674bd73de 100644 (file)
@@ -1253,7 +1253,8 @@ check_compat_entry_size_and_hooks(struct compat_arpt_entry *e,
        if (!arp_checkentry(&e->arp))
                return -EINVAL;
 
-       ret = xt_check_entry_offsets(e, e->target_offset, e->next_offset);
+       ret = xt_compat_check_entry_offsets(e, e->target_offset,
+                                           e->next_offset);
        if (ret)
                return ret;
 
index ddff8f7e3bcec2bee2e98c9b868ac00323b1754b..b83a3369b8a4de9b788eaaf09200fb27584772a8 100644 (file)
@@ -1512,7 +1512,8 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e,
        if (!ip_checkentry(&e->ip))
                return -EINVAL;
 
-       ret = xt_check_entry_offsets(e, e->target_offset, e->next_offset);
+       ret = xt_compat_check_entry_offsets(e,
+                                           e->target_offset, e->next_offset);
        if (ret)
                return ret;
 
index d6e3c019cf0a6612523fcd84267bc6cc091979b2..d8035191ea1a9b7f3590df3489805bd433fcdfe0 100644 (file)
@@ -1524,7 +1524,8 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
        if (!ip6_checkentry(&e->ipv6))
                return -EINVAL;
 
-       ret = xt_check_entry_offsets(e, e->target_offset, e->next_offset);
+       ret = xt_compat_check_entry_offsets(e,
+                                           e->target_offset, e->next_offset);
        if (ret)
                return ret;
 
index e3e2dd4c55bf524234af9a32b13e1e1cae44dc3b..cfdb9591cf216913c3703473c715b9fed040b6f7 100644 (file)
@@ -538,6 +538,27 @@ int xt_compat_match_to_user(const struct xt_entry_match *m,
        return 0;
 }
 EXPORT_SYMBOL_GPL(xt_compat_match_to_user);
+
+int xt_compat_check_entry_offsets(const void *base,
+                                 unsigned int target_offset,
+                                 unsigned int next_offset)
+{
+       const struct compat_xt_entry_target *t;
+       const char *e = base;
+
+       if (target_offset + sizeof(*t) > next_offset)
+               return -EINVAL;
+
+       t = (void *)(e + target_offset);
+       if (t->u.target_size < sizeof(*t))
+               return -EINVAL;
+
+       if (target_offset + t->u.target_size > next_offset)
+               return -EINVAL;
+
+       return 0;
+}
+EXPORT_SYMBOL(xt_compat_check_entry_offsets);
 #endif /* CONFIG_COMPAT */
 
 /**
@@ -548,6 +569,7 @@ EXPORT_SYMBOL_GPL(xt_compat_match_to_user);
  * @next_offset: the arp/ip/ip6_t->next_offset
  *
  * validates that target_offset and next_offset are sane.
+ * Also see xt_compat_check_entry_offsets for CONFIG_COMPAT version.
  *
  * The arp/ip/ip6t_entry structure @base must have passed following tests:
  * - it must point to a valid memory location