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)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 13 Apr 2016 22:30:36 +0000 (00:30 +0200)
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>
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 0de0862897a4f58325837cc359948d1d04460daa..08de48bbe92e361cf9922f1efc35dd834bcb39fb 100644 (file)
@@ -494,6 +494,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 24ad92a60b7ad86f57b77db36d437e0037278200..ab8952a49bfadd9de334370352b2a4e142ed5ab4 100644 (file)
@@ -1254,7 +1254,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 cdf18502a0475c837e916c6e80177b289057e4a6..7d24c872723fd2d6242dbd83f068754827abef9f 100644 (file)
@@ -1513,7 +1513,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 e3783116ed48ef8b77e5e0d650dd1483df5ff676..73eee7b5fd60e13e99958fafc0f1830236893286 100644 (file)
@@ -1525,7 +1525,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 ec1b7183fff964ca74d3051c07ca8685b90aa634..fa206ceb269ffe470a874c969fcfd773160f1d45 100644 (file)
@@ -539,6 +539,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 */
 
 /**
@@ -549,6 +570,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