Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "ahmad baghereslami" <ahmad.b1995@gmail.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH 1/2] Input: synaptics-rmi4 - support the LEDs of function $30
Date: Thu, 03 Dec 2026 13:06:32 +0000	[thread overview]
Message-ID: <sashiko-outbox-247823@kernel.org> (raw)
In-Reply-To: <1fa0ea288e9a119c8a1add0e46885d92deff2574.1796302238.git.ahmad.b1995@gmail.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] input: rmi4: dangling input->keycode UAF when
  rmi_f30_register_leds() fails
- [Medium] input: rmi4: missing LED_CORE_SUSPENDRESUME allows LED writes
  while suspended
- [Medium] input: rmi4: rmi_f30_led_set() mutates ctrl[4] cache before
  rmi_write()
- [Low] input: rmi4: unlocked read of ctrl[4] byte in
  rmi_f30_register_leds()
- [Low] input: rmi4: non-standard sysfs LED naming format in
  rmi_f30_register_leds()
--

commit f9ec26fc6f5ccca7c6290c03ae86094eeccdb79b
Author: ahmad baghereslami <ahmad.b1995@gmail.com>

Input: synaptics-rmi4 - support the LEDs of function $30

This patch registers an LED class device for each LED pin of Synaptics RMI4
function $30 and serializes LED control register updates with
rmi_f30_config() using a mutex.

> diff --git a/drivers/input/rmi4/rmi_f30.c b/drivers/input/rmi4/rmi_f30.c
> index 2fd009be774c7..724c820f7dbe9 100644
> --- a/drivers/input/rmi4/rmi_f30.c
> +++ b/drivers/input/rmi4/rmi_f30.c

[ ... ]

> @@ -362,6 +378,92 @@ static int rmi_f30_initialize(struct rmi_function *fn, struct f30_data *f30)
>  	return 0;
>  }
>  
> +/*
> + * Control 4 has a bit per pin that turns the LED on that pin on, and
> + * control 6 a byte per pin with the brightness of its LED. The values are
> + * kept in ctrl_regs, which rmi_f30_config() writes back after a reset.
> + */
> +static int rmi_f30_led_set(struct led_classdev *cdev,
> +			   enum led_brightness value)
> +{
> +	struct rmi_f30_led *led = container_of(cdev, struct rmi_f30_led, cdev);
> +	struct rmi_device *rmi_dev = led->fn->rmi_dev;
> +	struct rmi_f30_ctrl_data *on = &led->f30->ctrl[4];
> +	struct rmi_f30_ctrl_data *level = &led->f30->ctrl[6];
> +	unsigned int reg = led->pin >> 3;
> +	u8 mask = BIT(led->pin & 0x07);
> +	int error;
> +
> +	guard(mutex)(&led->f30->ctrl_mutex);
> +
> +	if (value) {
> +		error = rmi_write(rmi_dev, level->address + led->pin, value);
> +		if (error)
> +			return error;
> +
> +		level->regs[led->pin] = value;
> +		on->regs[reg] |= mask;
> +	} else {
> +		on->regs[reg] &= ~mask;
> +	}
> +
> +	return rmi_write(rmi_dev, on->address + reg, on->regs[reg]);
> +}

[Severity: Medium]
Should on->regs[reg] only be updated after rmi_write() succeeds, as is
done for level->regs[led->pin]?

If the control 4 write fails, on->regs[reg] is left modified in
f30->ctrl_regs, so a later rmi_f30_config() or an update to another LED in
the same 8-pin bank will silently push the failed pin's uncommitted state
to hardware.  Computing the new byte in a local variable and storing it
into on->regs[reg] only after rmi_write() returns 0 keeps the cache
consistent.

[ ... ]

> +static int rmi_f30_register_leds(struct rmi_function *fn, struct f30_data *f30)
> +{
> +	struct rmi_f30_led *led;
> +	unsigned int pin;
> +	int error;
> +
> +	if (!IS_REACHABLE(CONFIG_LEDS_CLASS) || !f30->has_led)
> +		return 0;
> +
> +	for (pin = 0; pin < f30->gpioled_count; pin++) {
> +		if (!rmi_f30_is_led(f30, pin))
> +			continue;
> +
> +		led = devm_kzalloc(&fn->dev, sizeof(*led), GFP_KERNEL);
> +		if (!led)
> +			return -ENOMEM;
> +
> +		led->fn = fn;
> +		led->f30 = f30;
> +		led->pin = pin;
> +		led->cdev.name = devm_kasprintf(&fn->dev, GFP_KERNEL, "%s::led%u",
> +						dev_name(&fn->dev), pin);

[Severity: Low]
Should the LED name use a standard LED_FUNCTION_* constant with a "-%u"
suffix instead of "led%u"?

Documentation/leds/leds-class.rst specifies the devicename:color:function
format using LED_FUNCTION_* definitions from
include/dt-bindings/leds/common.h (such as LED_FUNCTION_INDICATOR with
"-%u" for multiple LEDs).  Since sysfs LED names become userspace ABI,
aligning the name before merge avoids exposing a non-standard "::ledN"
interface.

> +		if (!led->cdev.name)
> +			return -ENOMEM;
> +
> +		led->cdev.max_brightness = U8_MAX;
> +		led->cdev.brightness_set_blocking = rmi_f30_led_set;

[Severity: Medium]
Should led->cdev.flags set LED_CORE_SUSPENDRESUME?

Without LED_CORE_SUSPENDRESUME, led_suspend() neither sets LED_SUSPENDED
nor flushes set_brightness_work before the parent RMI4 transport suspends.
Because brightness_set_blocking queues work on the non-freezable leds_wq,
an active trigger or software blink can still run rmi_f30_led_set() ->
rmi_write() after rmi_i2c_suspend() disables sensor regulators or after
the I2C/SMBus adapter suspends (triggering "Transfer while suspended"
warnings and -ESHUTDOWN), or race with rmi_smb_reset() during resume.

> +		if (f30->ctrl[4].regs[pin >> 3] & BIT(pin & 0x07))
> +			led->cdev.brightness = f30->ctrl[6].regs[pin];
> +
> +		rmi_dbg(RMI_DEBUG_FN, &fn->dev,
> +			"%s: LED on pin %u, on %#x, brightness %#x\n", __func__,
> +			pin, f30->ctrl[4].regs[pin >> 3], f30->ctrl[6].regs[pin]);
> +
> +		error = devm_led_classdev_register(&fn->dev, &led->cdev);

[Severity: Low]
Can reading f30->ctrl[4].regs[pin >> 3] here race with rmi_f30_led_set()
on multi-LED devices?

Once an earlier loop iteration registers a pin via
devm_led_classdev_register(), a sysfs write or trigger can run
rmi_f30_led_set() under f30->ctrl_mutex and modify that same control 4
byte while a later iteration reads it unlocked.  Reading the initial
control 4 and control 6 values under f30->ctrl_mutex avoids the data race.

[ ... ]

> @@ -385,12 +487,17 @@ static int rmi_f30_probe(struct rmi_function *fn)
>  
>  	f30->input = drv_data->input;
>  
> +	error = devm_mutex_init(&fn->dev, &f30->ctrl_mutex);
> +	if (error)
> +		return error;
> +
>  	error = rmi_f30_initialize(fn, f30);
>  	if (error)
>  		return error;
>  
>  	dev_set_drvdata(&fn->dev, f30);
> -	return 0;
> +
> +	return rmi_f30_register_leds(fn, f30);
>  }

[Severity: High]
Does returning an error from rmi_f30_register_leds() leave a dangling
input->keycode pointer and cause a use-after-free?

rmi_f30_initialize() -> rmi_f30_map_gpios() allocates f30->gpioled_key_map
with devm on &fn->dev and installs it into the longer-lived parent input
device:

drivers/input/rmi4/rmi_f30.c:rmi_f30_map_gpios() {
	...
	input->keycode = f30->gpioled_key_map;
	input->keycodesize = sizeof(f30->gpioled_key_map[0]);
	input->keycodemax = f30->gpioled_count;
	...
}

If rmi_f30_register_leds() fails, driver core unwinds &fn->dev devres and
frees f30->gpioled_key_map, but device_add(&fn->dev) still returns 0 so
rmi_driver_probe() registers data->input with the freed keycode pointer.
Any local user able to open the evdev device can then trigger a heap
use-after-free read or 16-bit write via EVIOCGKEYCODE / EVIOCSKEYCODE
(input_default_setkeycode()), and aborting probe also loses all F30
touchpad and trackstick buttons when optional LED registration fails.

Clearing input->keycode, input->keycodesize, and input->keycodemax on
error (or treating LED registration failure as non-fatal with a warning)
would avoid both.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796302238.git.ahmad.b1995@gmail.com?part=1

  reply	other threads:[~2026-12-03 13:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 12:50 [PATCH 0/2] Input: drive the HP ZBook 17 G3 touchpad LED through RMI4 ahmad baghereslami
2026-12-03 12:50 ` [PATCH 1/2] Input: synaptics-rmi4 - support the LEDs of function $30 ahmad baghereslami
2026-12-03 13:06   ` sashiko-bot [this message]
2026-12-03 12:50 ` [PATCH 2/2] Input: synaptics - enable SMBus for HP ZBook 17 G3 ahmad baghereslami

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=sashiko-outbox-247823@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ahmad.b1995@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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