Skip to content

Commit 2066499

Browse files
Florian Westphalgregkh
authored andcommitted
netfilter: x_tables: check standard target size too
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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2985d19 commit 2066499

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

net/netfilter/x_tables.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,13 @@ int xt_compat_match_to_user(const struct xt_entry_match *m,
539539
}
540540
EXPORT_SYMBOL_GPL(xt_compat_match_to_user);
541541

542+
/* non-compat version may have padding after verdict */
543+
struct compat_xt_standard_target {
544+
struct compat_xt_entry_target t;
545+
compat_uint_t verdict;
546+
};
547+
548+
/* see xt_check_entry_offsets */
542549
int xt_compat_check_entry_offsets(const void *base,
543550
unsigned int target_offset,
544551
unsigned int next_offset)
@@ -556,6 +563,10 @@ int xt_compat_check_entry_offsets(const void *base,
556563
if (target_offset + t->u.target_size > next_offset)
557564
return -EINVAL;
558565

566+
if (strcmp(t->u.user.name, XT_STANDARD_TARGET) == 0 &&
567+
target_offset + sizeof(struct compat_xt_standard_target) != next_offset)
568+
return -EINVAL;
569+
559570
return 0;
560571
}
561572
EXPORT_SYMBOL(xt_compat_check_entry_offsets);
@@ -595,6 +606,10 @@ int xt_check_entry_offsets(const void *base,
595606
if (target_offset + t->u.target_size > next_offset)
596607
return -EINVAL;
597608

609+
if (strcmp(t->u.user.name, XT_STANDARD_TARGET) == 0 &&
610+
target_offset + sizeof(struct xt_standard_target) != next_offset)
611+
return -EINVAL;
612+
598613
return 0;
599614
}
600615
EXPORT_SYMBOL(xt_check_entry_offsets);

0 commit comments

Comments
 (0)