mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: Rosen Penev <rosenp@gmail.com>
Cc: "Matthew Garrett" <mjg59@srcf.ucam.org>,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Darren Hart" <dvhart@linux.intel.com>,
	"Gabriele Mazzotta" <gabriele.mzt@gmail.com>,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] platform/x86: dell-laptop: Reject keyboard backlight timeouts that overflow
Date: Fri, 20 Nov 2026 14:18:03 +0100	[thread overview]
Message-ID: <20261120131803.dejsr2ip3djtoj2p@pali> (raw)
In-Reply-To: <1e1cc5a497ca95a0b34e45738f81a4be681675fd.1794633179.git.rosenp@gmail.com>

On Friday 13 November 2026 22:29:25 Rosen Penev wrote:
> 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.
> 
> Convert with check_mul_overflow() and return -EINVAL on overflow.
> 
> Fixes: 02b2aaaa57ab ("platform: x86: dell-laptop: Add support for keyboard backlight")
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  drivers/platform/x86/dell/dell-laptop.c | 21 +++++++++++++++------
>  1 file changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/platform/x86/dell/dell-laptop.c b/drivers/platform/x86/dell/dell-laptop.c
> index 89e85c7f7132..bee347e1d60c 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/overflow.h>
>  #include <linux/i8042.h>
>  #include <linux/debugfs.h>
>  #include <linux/seq_file.h>
> @@ -1554,6 +1555,7 @@ static ssize_t kbd_led_timeout_store(struct device *dev,
>  	struct kbd_state state;
>  	bool convert;
>  	int value;
> +	int mult;
>  	int ret;
>  	char ch;
>  	u8 unit;
> @@ -1602,16 +1604,23 @@ static ssize_t kbd_led_timeout_store(struct device *dev,
>  		/* Convert value from current units to seconds */
>  		switch (unit) {
>  		case KBD_TIMEOUT_DAYS:
> -			value *= 24;
> -			fallthrough;
> +			mult = 24 * 60 * 60;
> +			break;
>  		case KBD_TIMEOUT_HOURS:
> -			value *= 60;
> -			fallthrough;
> +			mult = 60 * 60;
> +			break;
>  		case KBD_TIMEOUT_MINUTES:
> -			value *= 60;
> -			unit = KBD_TIMEOUT_SECONDS;
> +			mult = 60;
> +			break;
> +		default:
> +			mult = 1;
> +			break;
>  		}
>  
> +		if (check_mul_overflow(value, mult, &value))
> +			return -EINVAL;
> +		unit = KBD_TIMEOUT_SECONDS;
> +
>  		if (quirks && quirks->needs_kbd_timeouts) {
>  			for (i = 0; quirks->kbd_timeouts[i] != -1; i++) {
>  				if (value <= quirks->kbd_timeouts[i]) {
> -- 
> 2.56.0
> 

This change does not work correctly. The code below the quoted change is
then dividing the value by (60 * 60 * 24) again (after being multiplied
above). So the newly adding check_mul_overflow() will reject valid
inputs, just because they do not fit into the "value" variable.

  reply	other threads:[~2026-11-20 13:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14  6:20 [PATCH 0/2] hwmon: (dell-smm) Validate pwm and fan_max values Rosen Penev
2026-11-14  6:20 ` [PATCH 1/2] hwmon: (dell-smm) Clamp the pwm value before scaling it Rosen Penev
2026-11-14 16:51   ` Guenter Roeck
2026-11-14  6:20 ` [PATCH 2/2] hwmon: (dell-smm) Reject a fan_max that the BIOS cannot take Rosen Penev
2026-11-14 16:52   ` Guenter Roeck
2026-11-14  6:29 ` [PATCH 0/3] platform/x86: dell-laptop: Fix keyboard backlight and charge threshold handling Rosen Penev
2026-11-14  6:29 ` [PATCH 1/3] platform/x86: dell-laptop: Reject keyboard backlight timeouts that overflow Rosen Penev
2026-11-20 13:18   ` Pali Rohár [this message]
2026-11-14  6:29 ` [PATCH 2/3] platform/x86: dell-laptop: Don't use an unread keyboard state at init Rosen Penev
2026-11-20 13:28   ` Pali Rohár
2026-11-14  6:29 ` [PATCH 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=20261120131803.dejsr2ip3djtoj2p@pali \
    --to=pali@kernel.org \
    --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=platform-driver-x86@vger.kernel.org \
    --cc=rosenp@gmail.com \
    /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®