netfilter: x_tables: Use unsafe_memcpy() for 0-sized destination
authorKees Cook <keescook@chromium.org>
Fri, 16 Feb 2024 23:31:32 +0000 (15:31 -0800)
committerFlorian Westphal <fw@strlen.de>
Wed, 21 Feb 2024 11:03:22 +0000 (12:03 +0100)
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>
net/netfilter/x_tables.c

index 21624d68314f98b58c63ae44a65422e448afc023..da5d929c7c85bfd066aa783ae441149e581dbbef 100644 (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;