Re: [PATCH 4/4] mic: vop: copy data to kernel space then write to io memory

From: Arnd Bergmann
Date: Fri Sep 25 2020 - 03:32:35 EST


On Fri, Sep 25, 2020 at 9:22 AM Sherry Sun <sherry.sun@xxxxxxx> wrote:
>

> @@ -655,12 +656,15 @@ static int vop_virtio_copy_from_user(struct vop_vdev *vdev, void __user *ubuf,
> * We are copying to IO below and should ideally use something
> * like copy_from_user_toio(..) if it existed.
> */
> - if (copy_from_user((void __force *)dbuf, ubuf, len)) {
> + temp = kmalloc(len, GFP_KERNEL);
> + if (copy_from_user(temp, ubuf, len))

This needs to have error handling for a kmalloc() failure. As the length
appears to be user-provided, you might also want to limit the size of
the allocation and instead do a loop with multiple copies if there is
more data than fits into the allocation.

Arnd