From: Rosen Penev <rosenp@gmail.com>
To: "Matthew Garrett" <mjg59@srcf.ucam.org>,
"Pali Rohár" <pali@kernel.org>,
"Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Gabriele Mazzotta" <gabriele.mzt@gmail.com>,
"Darren Hart" <dvhart@linux.intel.com>
Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/3] platform/x86: dell-laptop: Fix keyboard backlight timeout overflow
Date: Fri, 20 Nov 2026 16:09:29 -0800 [thread overview]
Message-ID: <ee9e976209ac07dd390676c4cf9d0643719ff2af.1795219225.git.rosenp@gmail.com> (raw)
In-Reply-To: <cover.1795219225.git.rosenp@gmail.com>
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@gmail.com>
---
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
next prev parent reply other threads:[~2026-11-21 0:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 0:09 [PATCH v2 0/3] platform/x86: dell-laptop: Fix keyboard backlight and charge threshold handling Rosen Penev
2026-11-21 0:09 ` Rosen Penev [this message]
2026-11-21 0:09 ` [PATCH v2 2/3] platform/x86: dell-laptop: Don't use an unread keyboard state at init Rosen Penev
2026-11-21 0:09 ` [PATCH v2 3/3] platform/x86: dell-laptop: Parse the charge end threshold as an int Rosen Penev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ee9e976209ac07dd390676c4cf9d0643719ff2af.1795219225.git.rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=dvhart@linux.intel.com \
--cc=gabriele.mzt@gmail.com \
--cc=hansg@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mjg59@srcf.ucam.org \
--cc=pali@kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®