netfilter: x_tables: Use unsafe_memcpy() for 0-sized destination

The struct xt_entry_target fake flexible array has not be converted to a
true flexible array, which is mainly blocked by it being both UAPI and
used in the middle of other structures. In order to properly check for
0-sized destinations in memcpy(), an exception must be made for the one
place where it is still a destination. Since memcpy() was already
skipping checks for 0-sized destinations, using unsafe_memcpy() is no
change in behavior.

Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
This commit is contained in:
Kees Cook 2024-02-16 15:31:32 -08:00 committed by Florian Westphal
parent 3f80196888
commit 26f4dac117
1 changed files with 2 additions and 1 deletions

View File

@ -1142,7 +1142,8 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr,
if (target->compat_from_user)
target->compat_from_user(t->data, ct->data);
else
memcpy(t->data, ct->data, tsize - sizeof(*ct));
unsafe_memcpy(t->data, ct->data, tsize - sizeof(*ct),
/* UAPI 0-sized destination */);
tsize += off;
t->u.user.target_size = tsize;