Skip to content

Commit 8b3f996

Browse files
keesmstsirkin
authored andcommitted
vhost: vringh: Use matching allocation type in resize_iovec()
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@kernel.org> Message-Id: <20250426062214.work.334-kees@kernel.org> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 9ef41eb commit 8b3f996

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/vhost/vringh.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,9 @@ static int resize_iovec(struct vringh_kiov *iov, gfp_t gfp)
225225

226226
flag = (iov->max_num & VRINGH_IOV_ALLOCATED);
227227
if (flag)
228-
new = krealloc_array(iov->iov, new_num,
229-
sizeof(struct iovec), gfp);
228+
new = krealloc_array(iov->iov, new_num, sizeof(*new), gfp);
230229
else {
231-
new = kmalloc_array(new_num, sizeof(struct iovec), gfp);
230+
new = kmalloc_array(new_num, sizeof(*new), gfp);
232231
if (new) {
233232
memcpy(new, iov->iov,
234233
iov->max_num * sizeof(struct iovec));

0 commit comments

Comments
 (0)