[PATCH RFC 05/38] platform/x86: toshiba_acpi: reject malformed brightness and fan writes
Christian Brauner
brauner at kernel.org
Mon Nov 2 06:21:20 PST 2026
When lcd_proc_write() and fan_proc_write() were refactored their checks
were inverted but the && stayed. They only fail if sscanf() didn't
parse anything and the value is out of range at the same time, and for
the brightness value < 0 && value > levels can't be true at all. So an
out of range brightness or fan setting is passed on to the hardware,
and so is the uninitialized value if nothing could be parsed.
Restore the checks as they were before the refactoring.
Fixes: e1a949c1b988 ("toshiba_acpi: Refactor *{get, set} functions return value")
Fixes: 3e07e5baa2af ("toshiba_acpi: Add set_fan_status function")
Cc: stable at vger.kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner at kernel.org>
---
drivers/platform/x86/toshiba_acpi.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
index a0b8060836d0..9eb8f1e5aeda 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1498,8 +1498,8 @@ static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
cmd[len] = '\0';
levels = dev->backlight_dev->props.max_brightness + 1;
- if (sscanf(cmd, " brightness : %i", &value) != 1 &&
- value < 0 && value > levels)
+ if (sscanf(cmd, " brightness : %i", &value) != 1 ||
+ value < 0 || value >= levels)
return -EINVAL;
if (set_lcd_brightness(dev, value))
@@ -1678,8 +1678,8 @@ static ssize_t fan_proc_write(struct file *file, const char __user *buf,
return -EFAULT;
cmd[len] = '\0';
- if (sscanf(cmd, " force_on : %i", &value) != 1 &&
- value != 0 && value != 1)
+ if (sscanf(cmd, " force_on : %i", &value) != 1 ||
+ value < 0 || value > 1)
return -EINVAL;
if (set_fan_status(dev, value))
--
2.53.0
More information about the linux-um
mailing list