kni: fix copy_from_user failure handling
authorStephen Hemminger <stephen@networkplumber.org>
Mon, 24 Jun 2019 16:47:11 +0000 (09:47 -0700)
committerThomas Monjalon <thomas@monjalon.net>
Mon, 15 Jul 2019 17:13:59 +0000 (19:13 +0200)
The correct thing to return if user gives a bad data
is to return -EFAULT. Logging is also discouraged because
it could be used as a DoS attack.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
kernel/linux/kni/kni_misc.c

index b59cf24..be45f82 100644 (file)
@@ -301,11 +301,8 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
                return -EINVAL;
 
        /* Copy kni info from user space */
-       ret = copy_from_user(&dev_info, (void *)ioctl_param, sizeof(dev_info));
-       if (ret) {
-               pr_err("copy_from_user in kni_ioctl_create");
-               return -EIO;
-       }
+       if (copy_from_user(&dev_info, (void *)ioctl_param, sizeof(dev_info)))
+               return -EFAULT;
 
        /* Check if name is zero-ended */
        if (strnlen(dev_info.name, sizeof(dev_info.name)) == sizeof(dev_info.name)) {
@@ -427,15 +424,12 @@ kni_ioctl_release(struct net *net, uint32_t ioctl_num,
        if (_IOC_SIZE(ioctl_num) > sizeof(dev_info))
                return -EINVAL;
 
-       ret = copy_from_user(&dev_info, (void *)ioctl_param, sizeof(dev_info));
-       if (ret) {
-               pr_err("copy_from_user in kni_ioctl_release");
-               return -EIO;
-       }
+       if (copy_from_user(&dev_info, (void *)ioctl_param, sizeof(dev_info)))
+               return -EFAULT;
 
        /* Release the network device according to its name */
        if (strlen(dev_info.name) == 0)
-               return ret;
+               return -EINVAL;
 
        down_write(&knet->kni_list_lock);
        list_for_each_entry_safe(dev, n, &knet->kni_list_head, list) {