From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796303193; b=AGsMgJLe8D6Gu1z5ZrZVikS0gF4JDTA7wihWLfytnYGVEPyslOXRfJoJ35gcXsK4D+pb QZHDIV6oFXODZs05bEtRqVJNqm3OGcGGZxnTeUgBTTuLQNvXaa7wZdN/fhWWWjGNOw/Fx n1V82pHfhmzLjFnfaGOFSZ06YjB5JqYrz8LzhB8pFi1t2jpAn8DTuovFBMIWbxaj21T5D +jCmSAISVrOFgZEZr7jPYXAlC3CwcSIoaPWL13HJw+rofxZLaDyRJewpIHUFOdSr79Ygl 4HkF+Zq3INQbARRLdRCaySquJGN5BVcLBBRYAGCW/0kxRV212ffxt/8CmiAxqXtbSuQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796303193; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=UngkqixcUvVqS1c1R9aBmZkR0ThqdiCiTE8mzRmESoU=; b=j1bbwHGXHNj3TbicR/34ydxP5/5QBdsHOY68HDUOnfn9KipMvDiWDjasatrAbXGqQ9+q MII/HtYJEg0C/0Y2LWUjZzr4KBPcw/ADOeDcIPrvG3b1rSdRU2lvxw6xzp496u2kljfQH is0oHlV0P7E24wqF66/3OjH8lmhcy6HQQgRwpk+4+DHb1KzgegkCvNH483o1vaw9z+3Jc +aZpt5eFIPu4Hn8sGoSxDJok9829/OVs9jk54eyz0h/Pt1JzBjitG2haKjND6ACNpBPMc LFAAEQ1/ZZ+BYMvs/vlP4cmbaxjwR/+4kxMobSZ0/LPm9nQctSm0Ek+oJKRYStwEjGw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=W1O7gL2v; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4B12606A68D for ; Thu, 3 Dec 2026 13:06:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=W1O7gL2v Received: by smtp.kernel.org (Postfix) with ESMTPSA id 385751F00898; Thu, 3 Dec 2026 13:06:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796303193; bh=UngkqixcUvVqS1c1R9aBmZkR0ThqdiCiTE8mzRmESoU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=W1O7gL2vHbSkOODt5ahGivhlb+sDjAg8h9s6npnGEm5/2CW6Dk1MlcmgRZmqcGFRQ dqos1RRicaPESNWAy6e0P1CATB0odo0eidd6CsjDiuzVIwurS2xfL9ymSb3ZpKIFxm K3gN3bu6wbth9/gtdEn1PL4zJ2+XpiORxm2Cz4hDeqlEyPvYzyCanM+m6/NliG3JsW Fu64v8YK9mqfU/2uVvToJYbdfY7aqkjgSk0gv4TpxjBiBvTV53fLYSCpd3jq5GpI8U w/wNaFw+I4XsZ/3J8mQovKRN4x90ql1AauEvp5K+aou7jcCC7VLDjQuR0NehUnN6NX Tv3cZ9KZrq/WA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 1/2] Input: synaptics-rmi4 - support the LEDs of function $30 Reply-To: sashiko-reviews@lists.linux.dev To: "ahmad baghereslami" Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com In-Reply-To: <1fa0ea288e9a119c8a1add0e46885d92deff2574.1796302238.git.ahmad.b1995@gmail.com> References: <1fa0ea288e9a119c8a1add0e46885d92deff2574.1796302238.git.ahmad.b1995@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 13:06:32 +0000 X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 *f= n, struct f30_data *f30) > return 0; > } > =20 > +/* > + * 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 a= re > + * 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 =3D container_of(cdev, struct rmi_f30_led, cdev= ); > + struct rmi_device *rmi_dev =3D led->fn->rmi_dev; > + struct rmi_f30_ctrl_data *on =3D &led->f30->ctrl[4]; > + struct rmi_f30_ctrl_data *level =3D &led->f30->ctrl[6]; > + unsigned int reg =3D led->pin >> 3; > + u8 mask =3D BIT(led->pin & 0x07); > + int error; > + > + guard(mutex)(&led->f30->ctrl_mutex); > + > + if (value) { > + error =3D rmi_write(rmi_dev, level->address + led->pin, value); > + if (error) > + return error; > + > + level->regs[led->pin] =3D value; > + on->regs[reg] |=3D mask; > + } else { > + on->regs[reg] &=3D ~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_dat= a *f30) > +{ > + struct rmi_f30_led *led; > + unsigned int pin; > + int error; > + > + if (!IS_REACHABLE(CONFIG_LEDS_CLASS) || !f30->has_led) > + return 0; > + > + for (pin =3D 0; pin < f30->gpioled_count; pin++) { > + if (!rmi_f30_is_led(f30, pin)) > + continue; > + > + led =3D devm_kzalloc(&fn->dev, sizeof(*led), GFP_KERNEL); > + if (!led) > + return -ENOMEM; > + > + led->fn =3D fn; > + led->f30 =3D f30; > + led->pin =3D pin; > + led->cdev.name =3D 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 =3D U8_MAX; > + led->cdev.brightness_set_blocking =3D 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 =3D 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 =3D 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) > =20 > f30->input =3D drv_data->input; > =20 > + error =3D devm_mutex_init(&fn->dev, &f30->ctrl_mutex); > + if (error) > + return error; > + > error =3D rmi_f30_initialize(fn, f30); > if (error) > return error; > =20 > 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 =3D f30->gpioled_key_map; input->keycodesize =3D sizeof(f30->gpioled_key_map[0]); input->keycodemax =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796302238.gi= t.ahmad.b1995@gmail.com?part=3D1