]> git.hungrycats.org Git - linux/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)
committerSasha Levin <sasha.levin@oracle.com>
Tue, 12 Jul 2016 12:48:32 +0000 (08:48 -0400)
[ Upstream commit fc1221b3a163d1386d1052184202d5dc50d302d1 ]

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: Sasha Levin <sasha.levin@oracle.com>
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 a2d15087372118f496d21e030b1385e06f3cb610..81843aa42a15f0b72a2fedbe288a74fc9114f2de 100644 (file)
@@ -435,6 +435,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 dc5bd7a104577448ec2d98fa97b8fa3a5035faa0..6924de43808e02382bc21501d9e59e3fdc75e4fa 100644 (file)
@@ -1244,7 +1244,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 eaf84eeaf1261c759a7a0b074c2a1ab21cffe251..9488131b2b8446cf97704ffd801e66b4ca60da1a 100644 (file)
@@ -1509,7 +1509,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 0822d538361f5b68cad24ad9da8cf80bc0320997..a23bf5386aeac0665621cbb4c91dac406cdef3b2 100644 (file)
@@ -1521,7 +1521,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 f432ee7e4d6dafbb6b3ae884af3d19d867a85aa8..242245330ec3cda2f793f2a9181a4f038d7e2526 100644 (file)
@@ -541,6 +541,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 */
 
 /**
@@ -551,6 +572,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