]> git.baikalelectronics.ru Git - kernel.git/commitdiff
platform/x86: thinkpad_acpi: Revert "Use strndup_user() in dispatch_proc_write()"
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Wed, 15 Jul 2020 09:40:07 +0000 (12:40 +0300)
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Wed, 15 Jul 2020 09:45:06 +0000 (12:45 +0300)
This reverts commit 852931eb8f21904ecf0ff55d22f3dece1225988b.

This broke procfs interface due to neglecting the fact that
the strings are not coming NULL terminated.

Revert the change till we will have a better clean up.

Fixes: 852931eb8f21 ("platform/x86: thinkpad_acpi: Use strndup_user() in dispatch_proc_write()")
Reported-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
drivers/platform/x86/thinkpad_acpi.c

index ff7f0a4f247563f4ebf3c9cce86da52eee1e2a37..0f6fceda5fc0b676be614b5f635111cfa59dbaa4 100644 (file)
@@ -885,11 +885,19 @@ static ssize_t dispatch_proc_write(struct file *file,
 
        if (!ibm || !ibm->write)
                return -EINVAL;
+       if (count > PAGE_SIZE - 1)
+               return -EINVAL;
+
+       kernbuf = kmalloc(count + 1, GFP_KERNEL);
+       if (!kernbuf)
+               return -ENOMEM;
 
-       kernbuf = strndup_user(userbuf, PAGE_SIZE);
-       if (IS_ERR(kernbuf))
-               return PTR_ERR(kernbuf);
+       if (copy_from_user(kernbuf, userbuf, count)) {
+               kfree(kernbuf);
+               return -EFAULT;
+       }
 
+       kernbuf[count] = 0;
        ret = ibm->write(kernbuf);
        if (ret == 0)
                ret = count;