Commit 20664997 authored by Florian Westphal's avatar Florian Westphal Committed by Greg Kroah-Hartman

netfilter: x_tables: check standard target size too

commit 7ed2abdd 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: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2985d199
...@@ -539,6 +539,13 @@ int xt_compat_match_to_user(const struct xt_entry_match *m, ...@@ -539,6 +539,13 @@ int xt_compat_match_to_user(const struct xt_entry_match *m,
} }
EXPORT_SYMBOL_GPL(xt_compat_match_to_user); 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, int xt_compat_check_entry_offsets(const void *base,
unsigned int target_offset, unsigned int target_offset,
unsigned int next_offset) unsigned int next_offset)
...@@ -556,6 +563,10 @@ int xt_compat_check_entry_offsets(const void *base, ...@@ -556,6 +563,10 @@ int xt_compat_check_entry_offsets(const void *base,
if (target_offset + t->u.target_size > next_offset) if (target_offset + t->u.target_size > next_offset)
return -EINVAL; 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; return 0;
} }
EXPORT_SYMBOL(xt_compat_check_entry_offsets); EXPORT_SYMBOL(xt_compat_check_entry_offsets);
...@@ -595,6 +606,10 @@ int xt_check_entry_offsets(const void *base, ...@@ -595,6 +606,10 @@ int xt_check_entry_offsets(const void *base,
if (target_offset + t->u.target_size > next_offset) if (target_offset + t->u.target_size > next_offset)
return -EINVAL; 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; return 0;
} }
EXPORT_SYMBOL(xt_check_entry_offsets); EXPORT_SYMBOL(xt_check_entry_offsets);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment