Skip to contentSkip to conversation

Input: assorted bug fixes across input drivers

PATCH Applied Lee Jones 3 participants 21 messages Nov 23 – Nov 24

Subsystems (7)
lore
Share & tools
lore

Lee Jones

author
#0 lore raw

cover Input: assorted bug fixes across input drivers

These issues were reported by Sashiko.

None of these changes have been tested on physical hardware.

Cc "Cheng, Wacom" <[email protected]>
Cc "Ronald Tschalär" <[email protected]>
Cc "Uwe Kleine-König (The Capable Hub)" <[email protected]>
Cc Andrew Duggan <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc AngeloGioacchino Del Regno <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Benjamin Tissoires <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Carlo Caione <[email protected]>
Cc Chen-Yu Tsai <[email protected]>
Cc Danilo Krummrich <[email protected]>
Cc Dmitry Torokhov <[email protected]>
Cc Dudley Du <[email protected]>
Cc Fengping Yu <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Ian Bridges <[email protected]>
Cc Jaya Kumar <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Marco Felsch <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc Mattijs Korpershoek <[email protected]>
Cc Pawel Zalewski <[email protected]>
Cc Sakari Ailus <[email protected]>
Cc Samuel Holland <[email protected]>
Cc Takashi Sakamoto <[email protected]>
Cc Vojtech Pavlik <[email protected]>

Lee Jones (10):
Input: matrix_keypad - validate GPIO counts against matrix limits
Input: cyapa - validate firmware image size in cyapa_pip_check_fw()
Input: applespi - cancel touchpad registration work on removal
Input: matrix_keypad - only stop and start active device across sleep
Input: stinger - zero-initialise driver state in stinger_connect()
Input: synaptics-rmi4 - check for NULL drvdata in rmi_set_attn_data()
Input: axp20x-pek - skip IRQ handling during sleep without input
device
Input: mt6779-keypad - enable keypad clock before programming
registers
Input: pinephone-keyboard - request IRQ before registering input
device
Input: wacom_w8001 - use reinit_completion() in w8001_command()

 drivers/input/joystick/stinger.c            |  2 +-
 drivers/input/keyboard/applespi.c           |  1 +
 drivers/input/keyboard/matrix_keypad.c      | 19 +++++++++++++++----
 drivers/input/keyboard/mt6779-keypad.c      |  8 ++++----
 drivers/input/keyboard/pinephone-keyboard.c | 12 ++++++------
 drivers/input/misc/axp20x-pek.c             |  6 ++++++
 drivers/input/mouse/cyapa_gen5.c            | 15 +++++++++++++++
 drivers/input/rmi4/rmi_driver.c             |  2 +-
 drivers/input/touchscreen/wacom_w8001.c     |  2 +-
 9 files changed, 50 insertions(+), 17 deletions(-)
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
author
#1 lore raw

PATCH 1/10 Input: matrix_keypad - validate GPIO counts against matrix limits

matrix_keypad_init_gpio() obtains the row and column GPIO counts via gpiod_count() and only checks for negative error codes before storing them in keypad->num_row_gpios and keypad->num_col_gpios.

If firmware supplies more than MATRIX_MAX_ROWS (32) row GPIOs or MATRIX_MAX_COLS (32) column GPIOs, the setup loops write past the fixed row_gpios, col_gpios, and row_irqs arrays inside struct matrix_keypad, and matrix_keypad_scan() overflows the stack-allocated new_state array. Conversely, a zero count causes get_count_order() to return -1, leading to an undefined shift when computing row_shift.

Reject non-positive GPIO counts as well as counts exceeding MATRIX_MAX_ROWS or MATRIX_MAX_COLS, and size col_gpios with MATRIX_MAX_COLS for consistency.

Fixes 584bf366f8fa ("Input: matrix_keypad - switch to gpiod API and generic device properties")
---
 drivers/input/keyboard/matrix_keypad.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/input/keyboard/matrix_keypad.c +7 -2
index 11018382e84e..c2f839a3de90 100644
@@ -33,7 +33,7 @@ struct matrix_keypad {
 	struct gpio_desc *row_gpios[MATRIX_MAX_ROWS];
 	unsigned int num_row_gpios;
 
-	struct gpio_desc *col_gpios[MATRIX_MAX_ROWS];
+	struct gpio_desc *col_gpios[MATRIX_MAX_COLS];
 	unsigned int num_col_gpios;
 
 	unsigned int row_irqs[MATRIX_MAX_ROWS];
@@ -302,11 +302,16 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev,
 
 	nrow = gpiod_count(&pdev->dev, "row");
 	ncol = gpiod_count(&pdev->dev, "col");
-	if (nrow < 0 || ncol < 0) {
+	if (nrow <= 0 || ncol <= 0) {
 		dev_err(&pdev->dev, "missing row or column GPIOs\n");
 		return -EINVAL;
 	}
 
+	if (nrow > MATRIX_MAX_ROWS || ncol > MATRIX_MAX_COLS) {
+		dev_err(&pdev->dev, "too many row or column GPIOs\n");
+		return -EINVAL;
+	}
+
 	keypad->num_row_gpios = nrow;
 	keypad->num_col_gpios = ncol;
 
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
author
#3 lore raw

PATCH 2/10 Input: cyapa - validate firmware image size in cyapa_pip_check_fw()

In reply to Lee Jones

cyapa_pip_check_fw() parses the firmware header, the trailing application integrity record, and the application rows without verifying that the supplied firmware buffer is large enough to hold them.

A truncated firmware image smaller than struct cyapa_tsg_bin_image_head causes an out-of-bounds read in cyapa_pip_fw_head_check() and can underflow the unsigned size subtraction in cyapa_get_image_record_data_num(). An image containing a valid header but zero complete flash records causes image_records[flash_records_count
- 1] to read before the start of fw->data. Finally, an image whose metadata specifies an app_len exceeding the available application records reads past the end of fw->data while computing app_crc.

Validate the header size, ensure at least one flash record is present, and bound the application row count against the non-integrity record count before dereferencing image_records.

Fixes 5812d3067294 ("Input: cyapa - add gen5 trackpad firmware update support")
---
 drivers/input/mouse/cyapa_gen5.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/input/mouse/cyapa_gen5.c +15 -0
index 59f6e97d5482..bce8104f4149 100644
@@ -1249,6 +1249,11 @@ int cyapa_pip_check_fw(struct cyapa *cyapa, const struct firmware *fw)
 	u16 app_integrity_crc;
 	int i;
 
+	if (fw->size < sizeof(struct cyapa_tsg_bin_image_head)) {
+		dev_err(dev, "%s: firmware image is too small.\n", __func__);
+		return -EINVAL;
+	}
+
 	/* Verify the firmware image not miss-used for Gen5 and Gen6. */
 	if (cyapa_pip_fw_head_check(cyapa,
 		(struct cyapa_tsg_bin_image_head *)fw->data)) {
@@ -1259,6 +1264,11 @@ int cyapa_pip_check_fw(struct cyapa *cyapa, const struct firmware *fw)
 
 	image_records =
 		cyapa_get_image_record_data_num(fw, &flash_records_count);
+	if (flash_records_count <= 0) {
+		dev_err(dev, "%s: firmware image has no flash records.\n",
+			__func__);
+		return -EINVAL;
+	}
 
 	/*
 	 * APP_INTEGRITY row is always the last row block,
@@ -1295,6 +1305,11 @@ int cyapa_pip_check_fw(struct cyapa *cyapa, const struct firmware *fw)
 		return -EINVAL;
 	}
 
+	if (fw_app_len / CYAPA_TSG_FW_ROW_SIZE > flash_records_count - 1) {
+		dev_err(dev, "%s: invalid firmware app length.\n", __func__);
+		return -EINVAL;
+	}
+
 	/* Verify application image CRC. */
 	app_crc = 0xffffU;
 	for (i = 0; i < fw_app_len / CYAPA_TSG_FW_ROW_SIZE; i++) {
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
author
#5 lore raw

PATCH 3/10 Input: applespi - cancel touchpad registration work on removal

In reply to Lee Jones

applespi_probe() allocates its driver state with devm_kzalloc_obj() and initiates an asynchronous touchpad information query whose completion schedules applespi->work to allocate and register the managed touchpad input device in applespi_worker().

applespi_remove() disables the ACPI GPE and drains in-flight SPI writes and reads, but never cancels applespi->work. If a touchpad info response scheduled applespi->work just before applespi_drain_reads() completed, applespi_worker() can run during or after devres teardown, corrupting the device resource list via devm_input_allocate_device() and dereferencing freed driver data.

Cancel applespi->work synchronously after applespi_drain_reads(), once no further SPI responses can schedule it.

Fixes 038b1a05eae6 ("Input: add Apple SPI keyboard and trackpad driver")
---
 drivers/input/keyboard/applespi.c | 1 +
 1 file changed, 1 insertion(+)
drivers/input/keyboard/applespi.c +1 -0
index 96c504f28495..d964cd3ee5af 100644
@@ -1819,6 +1819,7 @@ static void applespi_remove(struct spi_device *spi)
 	device_wakeup_disable(&spi->dev);
 
 	applespi_drain_reads(applespi);
+	cancel_work_sync(&applespi->work);
 
 	debugfs_remove_recursive(applespi->debugfs_root);
 }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
author
#7 lore raw

PATCH 4/10 Input: matrix_keypad - only stop and start active device across sleep

In reply to Lee Jones

matrix_keypad_suspend() and matrix_keypad_resume() unconditionally call matrix_keypad_stop() and matrix_keypad_start() without holding input_dev->mutex or checking whether the input device is active.

When the keypad has no open users (or is inhibited), row interrupts are already disabled and keypad->stopped is true. Suspending calls disable_row_irqs() a second time, unbalancing the IRQ disable depth, and resuming clears keypad->stopped and schedules keypad->work. If the device is subsequently unbound while still unopened, Input core skips the close callback (matrix_keypad_stop()) during unregistration, leaving keypad->work pending or running after devres frees struct matrix_keypad.

Acquire input_dev->mutex in both sleep callbacks and only stop or start scanning when input_device_enabled() is true.

Fixes 7d0f351da460 ("Input: matrix_keypad - switch to using managed resources")
---
 drivers/input/keyboard/matrix_keypad.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/input/keyboard/matrix_keypad.c +8 -2
index c2f839a3de90..81507e2a6126 100644
@@ -268,7 +268,10 @@ static int matrix_keypad_suspend(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct matrix_keypad *keypad = platform_get_drvdata(pdev);
 
-	matrix_keypad_stop(keypad->input_dev);
+	guard(mutex)(&keypad->input_dev->mutex);
+
+	if (input_device_enabled(keypad->input_dev))
+		matrix_keypad_stop(keypad->input_dev);
 
 	if (device_may_wakeup(&pdev->dev))
 		matrix_keypad_enable_wakeup(keypad);
@@ -281,10 +284,13 @@ static int matrix_keypad_resume(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct matrix_keypad *keypad = platform_get_drvdata(pdev);
 
+	guard(mutex)(&keypad->input_dev->mutex);
+
 	if (device_may_wakeup(&pdev->dev))
 		matrix_keypad_disable_wakeup(keypad);
 
-	matrix_keypad_start(keypad->input_dev);
+	if (input_device_enabled(keypad->input_dev))
+		matrix_keypad_start(keypad->input_dev);
 
 	return 0;
 }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
author
#9 lore raw

PATCH 5/10 Input: stinger - zero-initialise driver state in stinger_connect()

In reply to Lee Jones

stinger_connect() allocates struct stinger with kmalloc_obj() without initialising the signed packet index stinger->idx.

When serial bytes arrive in stinger_interrupt(), negative values of stinger->idx pass the stinger->idx < STINGER_MAX_LENGTH check and cause stinger->data[stinger->idx++] to write before the start of stinger->data on the heap, corrupting stinger->dev or adjacent slab memory. Initial values of 4 or greater never match the stinger->idx == 4 reset check and permanently wedge packet assembly.

Allocate struct stinger with kzalloc_obj() so stinger->idx and the packet buffer start zeroed.

Fixes 17dd3f0f7aa7 ("[PATCH] drivers/input/joystick: convert to dynamic input_dev allocation")
---
 drivers/input/joystick/stinger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/joystick/stinger.c +1 -1
index 011f9b137dca..021216f811c0 100644
@@ -118,7 +118,7 @@ static int stinger_connect(struct serio *serio, struct serio_driver *drv)
 	struct input_dev *input_dev;
 	int err = -ENOMEM;
 
-	stinger = kmalloc_obj(*stinger);
+	stinger = kzalloc_obj(*stinger);
 	input_dev = input_allocate_device();
 	if (!stinger || !input_dev)
 		goto fail1;
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
author
#11 lore raw

PATCH 6/10 Input: synaptics-rmi4 - check for NULL drvdata in rmi_set_attn_data()

In reply to Lee Jones

Transport drivers such as hid-rmi remain registered and continue delivering attention reports via rmi_set_attn_data() even if the physical RMI driver failed to probe rmi_dev or was unbound via sysfs.

When rmi_dev is unbound, dev_get_drvdata(&rmi_dev->dev) returns NULL and rmi_set_attn_data() dereferences drvdata->enabled in interrupt context.

Check that drvdata is non-NULL before accessing drvdata->enabled, matching rmi_process_interrupt_requests(), rmi_driver_suspend(), and rmi_driver_resume().

Fixes b908d3cd812a ("Input: synaptics-rmi4 - allow to add attention data")
---
 drivers/input/rmi4/rmi_driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/rmi4/rmi_driver.c +1 -1
index 7bbe9e801c35..5053c1edad6f 100644
@@ -172,7 +172,7 @@ void rmi_set_attn_data(struct rmi_device *rmi_dev, unsigned long irq_status,
 	struct rmi4_attn_data attn_data;
 	void *fifo_data;
 
-	if (!drvdata->enabled)
+	if (!drvdata || !drvdata->enabled)
 		return;
 
 	fifo_data = kmemdup(data, size, GFP_ATOMIC);
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
author
#13 lore raw

PATCH 7/10 Input: axp20x-pek - skip IRQ handling during sleep without input device

In reply to Lee Jones

On Cherry Trail systems where an ACPI GPIO button device already handles the power button, axp20x_pek_should_register_input() returns false and axp20x_pek_probe() skips axp20x_pek_probe_input_device(). This leaves axp20x_pek->input NULL and both irq_dbr and irq_dbf zero-initialised.

axp20x_pek_suspend() and axp20x_pek_resume() nevertheless pass irq_dbf and irq_dbr unconditionally to disable_irq(), enable_irq(), and their wakeup counterparts, manipulating IRQ 0 (the legacy x86 system timer) across suspend and resume.

Skip interrupt management in axp20x_pek_suspend() and axp20x_pek_resume() when no input device was registered.

Fixes 8a78050ee257 ("Input: axp20x-pek - revert "always register interrupt handlers" change")
---
 drivers/input/misc/axp20x-pek.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/input/misc/axp20x-pek.c +6 -0
index cbbc9db33ad2..a02cdabcf22b 100644
@@ -329,6 +329,9 @@ static int axp20x_pek_suspend(struct device *dev)
 {
 	struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
 
+	if (!axp20x_pek->input)
+		return 0;
+
 	/*
 	 * As nested threaded IRQs are not automatically disabled during
 	 * suspend, we must explicitly disable non-wakeup IRQs.
@@ -348,6 +351,9 @@ static int axp20x_pek_resume(struct device *dev)
 {
 	struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
 
+	if (!axp20x_pek->input)
+		return 0;
+
 	if (device_may_wakeup(dev)) {
 		disable_irq_wake(axp20x_pek->irq_dbf);
 		disable_irq_wake(axp20x_pek->irq_dbr);
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
author
#15 lore raw

PATCH 8/10 Input: mt6779-keypad - enable keypad clock before programming registers

In reply to Lee Jones

mt6779_keypad_pdrv_probe() writes the debounce and matrix selection registers over MMIO before acquiring and enabling the "kpd" clock via devm_clk_get_enabled().

When the keypad clock is gated off at boot or its clock provider defers probe, accessing unclocked keypad MMIO registers can trigger a bus abort or silently drop the configuration writes.

Acquire and enable the "kpd" clock before accessing the keypad registers.

Fixes f28af984e771 ("Input: mt6779-keypad - add MediaTek keypad driver")
---
 drivers/input/keyboard/mt6779-keypad.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/input/keyboard/mt6779-keypad.c +4 -4
index 60e6ad97cf59..a9f62f02439e 100644
@@ -195,6 +195,10 @@ static int mt6779_keypad_pdrv_probe(struct platform_device *pdev)
 
 	input_set_capability(keypad->input_dev, EV_MSC, MSC_SCAN);
 
+	keypad->clk = devm_clk_get_enabled(&pdev->dev, "kpd");
+	if (IS_ERR(keypad->clk))
+		return PTR_ERR(keypad->clk);
+
 	regmap_write(keypad->regmap, MTK_KPD_DEBOUNCE,
 		     (debounce * (1 << 5)) & MTK_KPD_DEBOUNCE_MASK);
 
@@ -208,10 +212,6 @@ static int mt6779_keypad_pdrv_probe(struct platform_device *pdev)
 	regmap_update_bits(keypad->regmap, MTK_KPD_SEL, MTK_KPD_SEL_COL,
 			   MTK_KPD_SEL_COLMASK(keypad->n_cols));
 
-	keypad->clk = devm_clk_get_enabled(&pdev->dev, "kpd");
-	if (IS_ERR(keypad->clk))
-		return PTR_ERR(keypad->clk);
-
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
 		return irq;
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
author
#17 lore raw

PATCH 9/10 Input: pinephone-keyboard - request IRQ before registering input device

In reply to Lee Jones

ppkb_probe() registers ppkb->input before installing its threaded interrupt handler with devm_request_threaded_irq().

As soon as input_register_device() exposes the keyboard (including synchronous open by the console keyboard handler), ppkb_open() enables matrix scanning. If a key is held during this window, the controller asserts its level-triggered interrupt line before the handler is registered, causing the kernel to disable the unhandled IRQ. In addition, devres unwinds in reverse order on unbind, freeing the IRQ handler before input unregistration invokes ppkb_close() to disable scanning.

Request the threaded IRQ before calling input_register_device() so the handler is in place before scanning can be enabled and outlives input unregistration on teardown.

Fixes 17406967ec0f ("Input: pinephone-keyboard - add PinePhone keyboard driver")
---
 drivers/input/keyboard/pinephone-keyboard.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/input/keyboard/pinephone-keyboard.c +6 -6
index b4a02ade3a80..fdf2c270bacd 100644
@@ -412,12 +412,6 @@ static int ppkb_probe(struct i2c_client *client)
 		return error;
 	}
 
-	error = input_register_device(ppkb->input);
-	if (error) {
-		dev_err(dev, "Failed to register input: %d\n", error);
-		return error;
-	}
-
 	error = devm_request_threaded_irq(dev, client->irq,
 					  NULL, ppkb_irq_thread,
 					  IRQF_ONESHOT, client->name, client);
@@ -426,6 +420,12 @@ static int ppkb_probe(struct i2c_client *client)
 		return error;
 	}
 
+	error = input_register_device(ppkb->input);
+	if (error) {
+		dev_err(dev, "Failed to register input: %d\n", error);
+		return error;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
author
#19 lore raw

PATCH 10/10 Input: wacom_w8001 - use reinit_completion() in w8001_command()

In reply to Lee Jones

w8001->cmd_done is already initialised in w8001_connect() before opening the serio port, yet w8001_command() calls init_completion() again for each command.

Calling init_completion() on an active completion reinitialises its internal waitqueue spinlock, triggering lockdep warnings and racing with complete() in w8001_interrupt() if a late response to a previously timed-out command arrives concurrently.

Use reinit_completion() in w8001_command() instead.

Fixes 3eb1aa43ef5c ("Input: add support for Wacom W8001 penabled serial touchscreen")
---
 drivers/input/touchscreen/wacom_w8001.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/touchscreen/wacom_w8001.c +1 -1
index d8d1cdc3f09e..a85ef93bdd29 100644
@@ -362,7 +362,7 @@ static int w8001_command(struct w8001 *w8001, unsigned char command,
 	int rc;
 
 	w8001->response_type = 0;
-	init_completion(&w8001->cmd_done);
+	reinit_completion(&w8001->cmd_done);
 
 	rc = serio_write(w8001->serio, command);
 	if (rc == 0 && wait_response) {
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
#8 lore raw

Re: [PATCH 04/10] Input: matrix_keypad - only stop and start active device across sleep

In reply to Lee Jones
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] Input: matrix_keypad - Fixes trailer cites 7d0f351da460 instead of bab7614d6d1b --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] Input: matrix_keypad - Fixes trailer cites 7d0f351da460 instead of bab7614d6d1b
--

commit 6307b7026ba23f150e88470188dcf8ceefd4969d
Author: Lee Jones <[email protected]>

Quoted 14 lines

Input: matrix_keypad - only stop and start active device across sleep

matrix_keypad_suspend() and matrix_keypad_resume() unconditionally call matrix_keypad_stop() and matrix_keypad_start() without holding input_dev->mutex or checking whether the input device is active.

When the keypad has no open users (or is inhibited), row interrupts are already disabled and keypad->stopped is true. Suspending calls disable_row_irqs() a second time, unbalancing the IRQ disable depth, and resuming clears keypad->stopped and schedules keypad->work. If the device is subsequently unbound while still unopened, Input core skips the close callback (matrix_keypad_stop()) during unregistration, leaving keypad->work pending or running after devres frees struct matrix_keypad.

Quoted 7 lines

Acquire input_dev->mutex in both sleep callbacks and only stop or start scanning when input_device_enabled() is true.

Fixes 7d0f351da460 ("Input: matrix_keypad - switch to using managed resources")

[Severity: Low]
Should the Fixes tag reference bab7614d6d1b ("Input: add support for generic GPIO-based matrix keypad") instead?

7d0f351da460 ("Input: matrix_keypad - switch to using managed resources") only converted allocations to devm_* and removed matrix_keypad_remove(), which never stopped or flushed keypad->work for an unopened device anyway. The unconditional matrix_keypad_stop() and matrix_keypad_start() calls in the suspend and resume paths have been present since the driver was added in bab7614d6d1b ("Input: add support for generic GPIO-based matrix keypad").

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
maintainer
#2 lore raw

Re: [PATCH 01/10] Input: matrix_keypad - validate GPIO counts against matrix limits

In reply to Lee Jones
Quoted 11 lines · Lee Jones

matrix_keypad_init_gpio() obtains the row and column GPIO counts via gpiod_count() and only checks for negative error codes before storing them in keypad->num_row_gpios and keypad->num_col_gpios.

If firmware supplies more than MATRIX_MAX_ROWS (32) row GPIOs or MATRIX_MAX_COLS (32) column GPIOs, the setup loops write past the fixed row_gpios, col_gpios, and row_irqs arrays inside struct matrix_keypad, and matrix_keypad_scan() overflows the stack-allocated new_state array. Conversely, a zero count causes get_count_order() to return -1, leading to an undefined shift when computing row_shift.

Quoted 7 lines

Reject non-positive GPIO counts as well as counts exceeding MATRIX_MAX_ROWS or MATRIX_MAX_COLS, and size col_gpios with MATRIX_MAX_COLS for consistency.

Fixes 584bf366f8fa ("Input: matrix_keypad - switch to gpiod API and generic device properties")

We trust DT somewhat so I do not think this needs to be in stable.

Quoted 10 lines
---
 drivers/input/keyboard/matrix_keypad.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/input/keyboard/matrix_keypad.c +0 -0
index 11018382e84e..c2f839a3de90 100644

drivers/input/keyboard/matrix_keypad.c struct matrix_keypad { · line 36

Quoted 5 lines
drivers/input/keyboard/matrix_keypad.c +1 -1
@@ -33,7 +33,7 @@ struct matrix_keypad {
 	struct gpio_desc *row_gpios[MATRIX_MAX_ROWS];
 	unsigned int num_row_gpios;
 
-	struct gpio_desc *col_gpios[MATRIX_MAX_ROWS];
+	struct gpio_desc *col_gpios[MATRIX_MAX_COLS];

Luckily they are the same...

drivers/input/keyboard/matrix_keypad.c static int matrix_keypad_init_gpio(struct platform_device *pdev, · line 305

Quoted 9 lines
drivers/input/keyboard/matrix_keypad.c +1 -1
 	unsigned int num_col_gpios;
 
 	unsigned int row_irqs[MATRIX_MAX_ROWS];
@@ -302,11 +302,16 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev,
 
 	nrow = gpiod_count(&pdev->dev, "row");
 	ncol = gpiod_count(&pdev->dev, "col");
-	if (nrow < 0 || ncol < 0) {
+	if (nrow <= 0 || ncol <= 0) {

gpiod_count() never returns 0. It's either positive, or -ENOENT.

drivers/input/keyboard/matrix_keypad.c static int matrix_keypad_init_gpio(struct platform_device *pdev, · line 317

Quoted 12 lines
drivers/input/keyboard/matrix_keypad.c +5 -0
 		dev_err(&pdev->dev, "missing row or column GPIOs\n");
 		return -EINVAL;
 	}
 
+	if (nrow > MATRIX_MAX_ROWS || ncol > MATRIX_MAX_COLS) {
+		dev_err(&pdev->dev, "too many row or column GPIOs\n");
+		return -EINVAL;
+	}
+
 	keypad->num_row_gpios = nrow;
 	keypad->num_col_gpios = ncol;
 

Thanks.

Signature · 1 line
Dmitry
maintainer
#6 lore raw

Re: [PATCH 03/10] Input: applespi - cancel touchpad registration work on removal

In reply to Lee Jones
Quoted 28 lines · Lee Jones

applespi_probe() allocates its driver state with devm_kzalloc_obj() and initiates an asynchronous touchpad information query whose completion schedules applespi->work to allocate and register the managed touchpad input device in applespi_worker().

applespi_remove() disables the ACPI GPE and drains in-flight SPI writes and reads, but never cancels applespi->work. If a touchpad info response scheduled applespi->work just before applespi_drain_reads() completed, applespi_worker() can run during or after devres teardown, corrupting the device resource list via devm_input_allocate_device() and dereferencing freed driver data.

Cancel applespi->work synchronously after applespi_drain_reads(), once no further SPI responses can schedule it.

Fixes 038b1a05eae6 ("Input: add Apple SPI keyboard and trackpad driver")
---
 drivers/input/keyboard/applespi.c | 1 +
 1 file changed, 1 insertion(+)
drivers/input/keyboard/applespi.c +0 -0
index 96c504f28495..d964cd3ee5af 100644

drivers/input/keyboard/applespi.c static void applespi_remove(struct spi_device *spi) · line 1822

Quoted 4 lines
drivers/input/keyboard/applespi.c +1 -0
@@ -1819,6 +1819,7 @@ static void applespi_remove(struct spi_device *spi)
 	device_wakeup_disable(&spi->dev);
 
 	applespi_drain_reads(applespi);
+	cancel_work_sync(&applespi->work);

Likely should be disable_work_sync() instead.

Thanks.

Signature · 1 line
Dmitry
maintainer Applied
#10 lore raw

Re: [PATCH 05/10] Input: stinger - zero-initialise driver state in stinger_connect()

In reply to Lee Jones
Quoted 10 lines · Lee Jones

stinger_connect() allocates struct stinger with kmalloc_obj() without initialising the signed packet index stinger->idx.

When serial bytes arrive in stinger_interrupt(), negative values of stinger->idx pass the stinger->idx < STINGER_MAX_LENGTH check and cause stinger->data[stinger->idx++] to write before the start of stinger->data on the heap, corrupting stinger->dev or adjacent slab memory. Initial values of 4 or greater never match the stinger->idx == 4 reset check and permanently wedge packet assembly.

Quoted 7 lines

Allocate struct stinger with kzalloc_obj() so stinger->idx and the packet buffer start zeroed.

Fixes 17dd3f0f7aa7 ("[PATCH] drivers/input/joystick: convert to dynamic input_dev allocation")

Applied, thank you.

Signature · 1 line
Dmitry
maintainer Applied
#14 lore raw

Re: [PATCH 07/10] Input: axp20x-pek - skip IRQ handling during sleep without input device

In reply to Lee Jones
Quoted 10 lines · Lee Jones

On Cherry Trail systems where an ACPI GPIO button device already handles the power button, axp20x_pek_should_register_input() returns false and axp20x_pek_probe() skips axp20x_pek_probe_input_device(). This leaves axp20x_pek->input NULL and both irq_dbr and irq_dbf zero-initialised.

axp20x_pek_suspend() and axp20x_pek_resume() nevertheless pass irq_dbf and irq_dbr unconditionally to disable_irq(), enable_irq(), and their wakeup counterparts, manipulating IRQ 0 (the legacy x86 system timer) across suspend and resume.

Quoted 7 lines

Skip interrupt management in axp20x_pek_suspend() and axp20x_pek_resume() when no input device was registered.

Fixes 8a78050ee257 ("Input: axp20x-pek - revert "always register interrupt handlers" change")

Applied, thank you.

Signature · 1 line
Dmitry
maintainer Applied
#16 lore raw

Re: [PATCH 08/10] Input: mt6779-keypad - enable keypad clock before programming registers

In reply to Lee Jones
Quoted 8 lines · Lee Jones

mt6779_keypad_pdrv_probe() writes the debounce and matrix selection registers over MMIO before acquiring and enabling the "kpd" clock via devm_clk_get_enabled().

When the keypad clock is gated off at boot or its clock provider defers probe, accessing unclocked keypad MMIO registers can trigger a bus abort or silently drop the configuration writes.

Quoted 7 lines

Acquire and enable the "kpd" clock before accessing the keypad registers.

Fixes f28af984e771 ("Input: mt6779-keypad - add MediaTek keypad driver")

Applied, thank you.

Signature · 1 line
Dmitry
maintainer Applied
#18 lore raw

Re: [PATCH 09/10] Input: pinephone-keyboard - request IRQ before registering input device

In reply to Lee Jones
Quoted 12 lines · Lee Jones

ppkb_probe() registers ppkb->input before installing its threaded interrupt handler with devm_request_threaded_irq().

As soon as input_register_device() exposes the keyboard (including synchronous open by the console keyboard handler), ppkb_open() enables matrix scanning. If a key is held during this window, the controller asserts its level-triggered interrupt line before the handler is registered, causing the kernel to disable the unhandled IRQ. In addition, devres unwinds in reverse order on unbind, freeing the IRQ handler before input unregistration invokes ppkb_close() to disable scanning.

Quoted 8 lines

Request the threaded IRQ before calling input_register_device() so the handler is in place before scanning can be enabled and outlives input unregistration on teardown.

Fixes 17406967ec0f ("Input: pinephone-keyboard - add PinePhone keyboard driver")

Applied, thank you.

Signature · 1 line
Dmitry
maintainer Applied
#20 lore raw

Re: [PATCH 10/10] Input: wacom_w8001 - use reinit_completion() in w8001_command()

In reply to Lee Jones
Quoted 9 lines · Lee Jones

w8001->cmd_done is already initialised in w8001_connect() before opening the serio port, yet w8001_command() calls init_completion() again for each command.

Calling init_completion() on an active completion reinitialises its internal waitqueue spinlock, triggering lockdep warnings and racing with complete() in w8001_interrupt() if a late response to a previously timed-out command arrives concurrently.

Quoted 6 lines

Use reinit_completion() in w8001_command() instead.

Fixes 3eb1aa43ef5c ("Input: add support for Wacom W8001 penabled serial touchscreen")

Applied, thank you.

Signature · 1 line
Dmitry
maintainer
#4 lore raw

Re: [PATCH 02/10] Input: cyapa - validate firmware image size in cyapa_pip_check_fw()

In reply to Lee Jones
Quoted 13 lines · Lee Jones

cyapa_pip_check_fw() parses the firmware header, the trailing application integrity record, and the application rows without verifying that the supplied firmware buffer is large enough to hold them.

A truncated firmware image smaller than struct cyapa_tsg_bin_image_head causes an out-of-bounds read in cyapa_pip_fw_head_check() and can underflow the unsigned size subtraction in cyapa_get_image_record_data_num(). An image containing a valid header but zero complete flash records causes image_records[flash_records_count
- 1] to read before the start of fw->data. Finally, an image whose metadata specifies an app_len exceeding the available application records reads past the end of fw->data while computing app_crc.

Quoted 8 lines

Validate the header size, ensure at least one flash record is present, and bound the application row count against the non-integrity record count before dereferencing image_records.

Fixes 5812d3067294 ("Input: cyapa - add gen5 trackpad firmware update support")

Applied with some minor edits, thank you.

Signature · 1 line
Dmitry
maintainer Applied
#12 lore raw

Re: [PATCH 06/10] Input: synaptics-rmi4 - check for NULL drvdata in rmi_set_attn_data()

In reply to Lee Jones
Quoted 7 lines · Lee Jones

Transport drivers such as hid-rmi remain registered and continue delivering attention reports via rmi_set_attn_data() even if the physical RMI driver failed to probe rmi_dev or was unbound via sysfs.

When rmi_dev is unbound, dev_get_drvdata(&rmi_dev->dev) returns NULL and rmi_set_attn_data() dereferences drvdata->enabled in interrupt context.

Quoted 8 lines

Check that drvdata is non-NULL before accessing drvdata->enabled, matching rmi_process_interrupt_requests(), rmi_driver_suspend(), and rmi_driver_resume().

Fixes b908d3cd812a ("Input: synaptics-rmi4 - allow to add attention data")

Applied, thank you.

Signature · 1 line
Dmitry