Implement ->proc_write_buf() for the files in /proc/acpi/toshiba so procfs copies in what is written before it pins the entry, and parse what was written from that copy. Commands longer than PAGE_SIZE - 1 bytes are rejected now.
Signed-off-by: Christian Brauner (Amutable) <[email protected]> --- drivers/platform/x86/toshiba_acpi.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index 560e62da05a9..895e321ada03 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -1478,7 +1478,7 @@ static int set_lcd_status(struct backlight_device *bd) return set_lcd_brightness(dev, bd->props.brightness); } -static ssize_t lcd_proc_write(struct file *file, const char __user *buf, +static ssize_t lcd_proc_write(struct file *file, char *buf, size_t count, loff_t *pos) { struct toshiba_acpi_dev *dev = pde_data(file_inode(file)); @@ -1488,8 +1488,7 @@ static ssize_t lcd_proc_write(struct file *file, const char __user *buf, int value; len = min(count, sizeof(cmd) - 1); - if (copy_from_user(cmd, buf, len)) - return -EFAULT; + memcpy(cmd, buf, len); cmd[len] = '\0'; levels = dev->backlight_dev->props.max_brightness + 1; @@ -1505,7 +1504,7 @@ static ssize_t lcd_proc_write(struct file *file, const char __user *buf, static const struct proc_ops lcd_proc_ops = { .proc_show = lcd_proc_show, - .proc_write = lcd_proc_write, + .proc_write_buf = lcd_proc_write, }; /* Video-Out */ @@ -1541,24 +1540,17 @@ static int video_proc_show(struct seq_file *m, void *v) return 0; } -static ssize_t video_proc_write(struct file *file, const char __user *buf, +static ssize_t video_proc_write(struct file *file, char *buf, size_t count, loff_t *pos) { struct toshiba_acpi_dev *dev = pde_data(file_inode(file)); - char *buffer; - char *cmd; + char *buffer = buf; int lcd_out = -1, crt_out = -1, tv_out = -1; int remain = count; int value; int ret; u32 video_out; - cmd = memdup_user_nul(buf, count); - if (IS_ERR(cmd)) - return PTR_ERR(cmd); - - buffer = cmd; - /* * Scan expression. Multiple expressions may be delimited with ; * NOTE: To keep scanning simple, invalid fields are ignored. @@ -1577,8 +1569,6 @@ static ssize_t video_proc_write(struct file *file, const char __user *buf, } while (remain && *(buffer - 1) != ';'); } - kfree(cmd); - ret = get_video_status(dev, &video_out); if (!ret) { unsigned int new_video_out = video_out; @@ -1602,7 +1592,7 @@ static ssize_t video_proc_write(struct file *file, const char __user *buf, static const struct proc_ops video_proc_ops = { .proc_show = video_proc_show, - .proc_write = video_proc_write, + .proc_write_buf = video_proc_write, }; /* Fan status */ @@ -1644,7 +1634,7 @@ static int fan_proc_show(struct seq_file *m, void *v) return 0; } -static ssize_t fan_proc_write(struct file *file, const char __user *buf, +static ssize_t fan_proc_write(struct file *file, char *buf, size_t count, loff_t *pos) { struct toshiba_acpi_dev *dev = pde_data(file_inode(file)); @@ -1653,8 +1643,7 @@ static ssize_t fan_proc_write(struct file *file, const char __user *buf, int value; len = min(count, sizeof(cmd) - 1); - if (copy_from_user(cmd, buf, len)) - return -EFAULT; + memcpy(cmd, buf, len); cmd[len] = '\0'; if (sscanf(cmd, " force_on : %i", &value) != 1 || @@ -1671,7 +1660,7 @@ static ssize_t fan_proc_write(struct file *file, const char __user *buf, static const struct proc_ops fan_proc_ops = { .proc_show = fan_proc_show, - .proc_write = fan_proc_write, + .proc_write_buf = fan_proc_write, }; /* Fan RPM */ @@ -1707,7 +1696,7 @@ static int keys_proc_show(struct seq_file *m, void *v) return 0; } -static ssize_t keys_proc_write(struct file *file, const char __user *buf, +static ssize_t keys_proc_write(struct file *file, char *buf, size_t count, loff_t *pos) { struct toshiba_acpi_dev *dev = pde_data(file_inode(file)); @@ -1716,8 +1705,7 @@ static ssize_t keys_proc_write(struct file *file, const char __user *buf, int value; len = min(count, sizeof(cmd) - 1); - if (copy_from_user(cmd, buf, len)) - return -EFAULT; + memcpy(cmd, buf, len); cmd[len] = '\0'; if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) @@ -1730,7 +1718,7 @@ static ssize_t keys_proc_write(struct file *file, const char __user *buf, static const struct proc_ops keys_proc_ops = { .proc_show = keys_proc_show, - .proc_write = keys_proc_write, + .proc_write_buf = keys_proc_write, }; static int __maybe_unused version_proc_show(struct seq_file *m, void *v) -- 2.53.0
