Drivers: hv: utils: use memdup_user in hvt_op_write
authorOlaf Hering <olaf@aepfle.de>
Tue, 15 Dec 2015 00:01:37 +0000 (16:01 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 15 Dec 2015 03:12:21 +0000 (19:12 -0800)
Use memdup_user to handle OOM.

Fixes: 14b50f80c32d ('Drivers: hv: util: introduce hv_utils_transport abstraction')
Signed-off-by: Olaf Hering <olaf@aepfle.de>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hv/hv_utils_transport.c

index 1505ee6e6605e0b646cdeeae531dedb9fc8dbd11..24b2766a6d345baafd2419eec2467d45b3bd806e 100644 (file)
@@ -80,11 +80,10 @@ static ssize_t hvt_op_write(struct file *file, const char __user *buf,
 
        hvt = container_of(file->f_op, struct hvutil_transport, fops);
 
-       inmsg = kzalloc(count, GFP_KERNEL);
-       if (copy_from_user(inmsg, buf, count)) {
-               kfree(inmsg);
-               return -EFAULT;
-       }
+       inmsg = memdup_user(buf, count);
+       if (IS_ERR(inmsg))
+               return PTR_ERR(inmsg);
+
        if (hvt->on_msg(inmsg, count))
                return -EFAULT;
        kfree(inmsg);