Merge tag 'v3.10.103' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / ipv4 / netfilter / ip_tables.c
index 92c8f2727ee92492eae43944d05f6a93842070f1..8672b124e1cc8e38f84e1c963d695b6e40c713dd 100644 (file)
@@ -562,6 +562,26 @@ static void cleanup_match(struct xt_entry_match *m, struct net *net)
        module_put(par.match->me);
 }
 
+static int
+check_entry(const struct ipt_entry *e)
+{
+       const struct xt_entry_target *t;
+
+       if (!ip_checkentry(&e->ip))
+               return -EINVAL;
+
+       if (e->target_offset + sizeof(struct xt_entry_target) >
+           e->next_offset)
+               return -EINVAL;
+
+       t = ipt_get_target_c(e);
+       if (e->target_offset + t->u.target_size > e->next_offset)
+               return -EINVAL;
+
+       return 0;
+}
+
+
 static int
 check_match(struct xt_entry_match *m, struct xt_mtchk_param *par)
 {
@@ -718,11 +738,8 @@ check_entry_size_and_hooks(struct ipt_entry *e,
                return -EINVAL;
        }
 
-       if (!ip_checkentry(&e->ip))
-               return -EINVAL;
+       err = check_entry(e);
 
-       err = xt_check_entry_offsets(e, e->elems, e->target_offset,
-                                    e->next_offset);
        if (err)
                return err;
 
@@ -1447,11 +1464,9 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e,
                return -EINVAL;
        }
 
-       if (!ip_checkentry(&e->ip))
-               return -EINVAL;
+       /* For purposes of check_entry casting the compat entry is fine */
+       ret = check_entry((struct ipt_entry *)e);
 
-       ret = xt_compat_check_entry_offsets(e, e->elems,
-                                           e->target_offset, e->next_offset);
        if (ret)
                return ret;