[PATCH v2 1/3] platform/x86: dell-laptop: Fix keyboard backlight timeout overflow
From: Rosen Penev
Date: Fri Nov 20 2026 - 19:10:29 EST
kbd_led_timeout_store() converts a timeout that is too large for its
unit to seconds with plain int multiplication. A large enough value
wraps, and if the wrapped number happens to be a valid timeout it is
accepted. On a Precision M4800, writing "4424214d" (over 12000 years)
to stop_timeout sets the timeout to 4 minutes, and "18989323d" sets it
to 2 minutes.
Do the conversion and the following unit selection on a u64 seconds
value instead. With value <= INT_MAX this cannot overflow, so such
inputs are now rejected with -EINVAL like any other timeout that is too
large for the hardware, and nothing that was valid before is rejected.
Fixes: 02b2aaaa57ab ("platform: x86: dell-laptop: Add support for keyboard backlight")
Signed-off-by: Rosen Penev <rosenp@xxxxxxxxx>
---
v2: use a u64 seconds value instead of check_mul_overflow() on the int
drivers/platform/x86/dell/dell-laptop.c | 34 +++++++++++++++----------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/drivers/platform/x86/dell/dell-laptop.c b/drivers/platform/x86/dell/dell-laptop.c
index cad2bd06f28a..c1a51bf95c25 100644
--- a/drivers/platform/x86/dell/dell-laptop.c
+++ b/drivers/platform/x86/dell/dell-laptop.c
@@ -25,6 +25,7 @@
#include <linux/sysfs.h>
#include <linux/acpi.h>
#include <linux/mm.h>
+#include <linux/math64.h>
#include <linux/i8042.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
@@ -1553,6 +1554,7 @@ static ssize_t kbd_led_timeout_store(struct device *dev,
struct kbd_state new_state;
struct kbd_state state;
bool convert;
+ u64 seconds;
int value;
int ret;
char ch;
@@ -1599,38 +1601,42 @@ static ssize_t kbd_led_timeout_store(struct device *dev,
convert = true;
if (convert) {
- /* Convert value from current units to seconds */
+ /*
+ * Convert value from current units to seconds. This is done in
+ * 64 bits so that it cannot overflow: value <= INT_MAX.
+ */
+ seconds = value;
switch (unit) {
case KBD_TIMEOUT_DAYS:
- value *= 24;
+ seconds *= 24;
fallthrough;
case KBD_TIMEOUT_HOURS:
- value *= 60;
+ seconds *= 60;
fallthrough;
case KBD_TIMEOUT_MINUTES:
- value *= 60;
- unit = KBD_TIMEOUT_SECONDS;
+ seconds *= 60;
}
if (quirks && quirks->needs_kbd_timeouts) {
for (i = 0; quirks->kbd_timeouts[i] != -1; i++) {
- if (value <= quirks->kbd_timeouts[i]) {
- value = quirks->kbd_timeouts[i];
+ if (seconds <= quirks->kbd_timeouts[i]) {
+ seconds = quirks->kbd_timeouts[i];
break;
}
}
}
- if (value <= kbd_info.seconds && kbd_info.seconds) {
+ if (seconds <= kbd_info.seconds && kbd_info.seconds) {
+ value = seconds;
unit = KBD_TIMEOUT_SECONDS;
- } else if (value / 60 <= kbd_info.minutes && kbd_info.minutes) {
- value /= 60;
+ } else if (div_u64(seconds, 60) <= kbd_info.minutes && kbd_info.minutes) {
+ value = div_u64(seconds, 60);
unit = KBD_TIMEOUT_MINUTES;
- } else if (value / (60 * 60) <= kbd_info.hours && kbd_info.hours) {
- value /= (60 * 60);
+ } else if (div_u64(seconds, 60 * 60) <= kbd_info.hours && kbd_info.hours) {
+ value = div_u64(seconds, 60 * 60);
unit = KBD_TIMEOUT_HOURS;
- } else if (value / (60 * 60 * 24) <= kbd_info.days && kbd_info.days) {
- value /= (60 * 60 * 24);
+ } else if (div_u64(seconds, 60 * 60 * 24) <= kbd_info.days && kbd_info.days) {
+ value = div_u64(seconds, 60 * 60 * 24);
unit = KBD_TIMEOUT_DAYS;
} else {
return -EINVAL;
--
2.56.1