netfilter: x_tables: check standard target size too 18/154918/1
authorFlorian Westphal <fw@strlen.de>
Fri, 1 Apr 2016 12:17:27 +0000 (14:17 +0200)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 11 Oct 2017 11:17:26 +0000 (20:17 +0900)
commit 7ed2abddd20cf8f6bd27f65bd218f26fa5bf7f44 upstream.

We have targets and standard targets -- the latter carries a verdict.

The ip/ip6tables validation functions will access t->verdict for the
standard targets to fetch the jump offset or verdict for chainloop
detection, but this happens before the targets get checked/validated.

Thus we also need to check for verdict presence here, else t->verdict
can point right after a blob.

Spotted with UBSAN while testing malformed blobs.

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>
[sw0312.kim: cherry-pick from linux-3.10.y to apply CVE]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I8e2a37fc8313fd819fee9181bbbdee32cd2b4b95

net/netfilter/x_tables.c

index eeb4edc..37f7eda 100644 (file)
@@ -559,6 +559,13 @@ int xt_compat_match_to_user(const struct xt_entry_match *m,
 }
 EXPORT_SYMBOL_GPL(xt_compat_match_to_user);
 
+/* non-compat version may have padding after verdict */
+struct compat_xt_standard_target {
+       struct compat_xt_entry_target t;
+       compat_uint_t verdict;
+};
+
+/* see xt_check_entry_offsets */
 int xt_compat_check_entry_offsets(const void *base,
                                  unsigned int target_offset,
                                  unsigned int next_offset)
@@ -576,6 +583,10 @@ int xt_compat_check_entry_offsets(const void *base,
        if (target_offset + t->u.target_size > next_offset)
                return -EINVAL;
 
+       if (strcmp(t->u.user.name, XT_STANDARD_TARGET) == 0 &&
+           target_offset + sizeof(struct compat_xt_standard_target) != next_offset)
+               return -EINVAL;
+
        return 0;
 }
 EXPORT_SYMBOL(xt_compat_check_entry_offsets);
@@ -615,6 +626,10 @@ int xt_check_entry_offsets(const void *base,
        if (target_offset + t->u.target_size > next_offset)
                return -EINVAL;
 
+       if (strcmp(t->u.user.name, XT_STANDARD_TARGET) == 0 &&
+           target_offset + sizeof(struct xt_standard_target) != next_offset)
+               return -EINVAL;
+
        return 0;
 }
 EXPORT_SYMBOL(xt_check_entry_offsets);