]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
ACPI / EC: access user space with get_user()/put_user()
authorVasiliy Kulikov <segooon@gmail.com>
Wed, 22 May 2013 12:59:11 +0000 (14:59 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 19 Jun 2013 21:29:20 +0000 (23:29 +0200)
User space pointer may not be dereferenced. Use get_user()/put_user()
instead and check their return codes.

Signed-off-by: Vasiliy Kulikov <segooon@gmail.com>
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/ec_sys.c

index 7586544fddb41b9cc1761a294dc57f79245d6286..4e7b798900f21df7bf60c75d2132e2ad86e89e38 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/acpi.h>
 #include <linux/debugfs.h>
 #include <linux/module.h>
+#include <linux/uaccess.h>
 #include "internal.h"
 
 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
@@ -34,7 +35,6 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
         * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
         */
        unsigned int size = EC_SPACE_SIZE;
-       u8 *data = (u8 *) buf;
        loff_t init_off = *off;
        int err = 0;
 
@@ -47,9 +47,15 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
                size = count;
 
        while (size) {
-               err = ec_read(*off, &data[*off - init_off]);
+               u8 byte_read;
+               err = ec_read(*off, &byte_read);
                if (err)
                        return err;
+               if (put_user(byte_read, buf + *off - init_off)) {
+                       if (*off - init_off)
+                               return *off - init_off; /* partial read */
+                       return -EFAULT;
+               }
                *off += 1;
                size--;
        }
@@ -65,7 +71,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
 
        unsigned int size = count;
        loff_t init_off = *off;
-       u8 *data = (u8 *) buf;
        int err = 0;
 
        if (*off >= EC_SPACE_SIZE)
@@ -76,7 +81,12 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
        }
 
        while (size) {
-               u8 byte_write = data[*off - init_off];
+               u8 byte_write;
+               if (get_user(byte_write, buf + *off - init_off)) {
+                       if (*off - init_off)
+                               return *off - init_off; /* partial write */
+                       return -EFAULT;
+               }
                err = ec_write(*off, byte_write);
                if (err)
                        return err;