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)
committerWilly Tarreau <w@1wt.eu>
Sun, 21 Aug 2016 21:22:28 +0000 (23:22 +0200)
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: Willy Tarreau <w@1wt.eu>
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 6da5c8275e942228ab410ee007104c759731d26a..8dfd3dddd1e008148b3aecb15bdc2015b303841c 100644 (file)
@@ -437,6 +437,9 @@ extern void xt_compat_target_from_user(struct xt_entry_target *t,
                                       void **dstptr, unsigned int *size);
 extern 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 fdfab33715624d39e19aaea954861e4134b4564a..e4084c00bf2933de053e13c79df1f5a05c444602 100644 (file)
@@ -1223,7 +1223,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 a003c753f7aa291295557c35bd924e314cbd6bf4..fba8929d11170172dd955153cc875a5ca2fbc425 100644 (file)
@@ -1488,7 +1488,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 f5b5cb0fcea318bf5caf84941338b6551a4f9c16..1949305e2613b290e6c4c942c70dcc6a5eba30bd 100644 (file)
@@ -1500,7 +1500,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 cc34bb38c81492c373658ac8352a021e080de0f5..eeb4edc750cdfaa6528a67e5c9ca612e8bb5a0b8 100644 (file)
@@ -558,6 +558,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 */
 
 /**
@@ -568,6 +589,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