Re: [PATCH] vhost: vringh: Use matching allocation type in resize_iovec()

From: Jacob Keller
Date: Wed Apr 30 2025 - 16:59:05 EST




On 4/25/2025 11:22 PM, Kees Cook wrote:
> In preparation for making the kmalloc family of allocators type aware,
> we need to make sure that the returned type from the allocation matches
> the type of the variable being assigned. (Before, the allocator would
> always return "void *", which can be implicitly cast to any pointer type.)
>
> The assigned type is "struct kvec *", but the returned type will be
> "struct iovec *". These have the same allocation size, so there is no
> bug:
>
> struct kvec {
> void *iov_base; /* and that should *never* hold a userland pointer */
> size_t iov_len;
> };
>
> struct iovec
> {
> void __user *iov_base; /* BSD uses caddr_t (1003.1g requires void *) */
> __kernel_size_t iov_len; /* Must be size_t (1003.1g) */
> };
>
> Adjust the allocation type to match the assignment.
>
> Signed-off-by: Kees Cook <kees@xxxxxxxxxx>
> ---
Reviewed-by: Jacob Keller <jacob.e.keller@xxxxxxxxx>