Skip to content

Commit 7ed2abd

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: x_tables: check standard target size too
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>
1 parent fc1221b commit 7ed2abd

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
@@ -540,6 +540,13 @@ int xt_compat_match_to_user(const struct xt_entry_match *m,
540540
}
541541
EXPORT_SYMBOL_GPL(xt_compat_match_to_user);
542542

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

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

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

0 commit comments

Comments
 (0)