Skip to contentSkip to conversation

Input: adp5588-keys - Added checking of key and key_val variables

PATCH In review Denis Arefev 2 participants 2 messages Sep 30, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: adp5588-keys - Added checking of key and key_val variables

If the adp5588_read function returns 0, then there will be an overflow of the kpad->keycode buffer.

If the adp5588_read function returns a negative value, then the logic is broken - the wrong value is used as an index of the kpad->keycode array.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 drivers/input/keyboard/adp5588-keys.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/input/keyboard/adp5588-keys.c +7 -4
index 1b0279393df4..d05387f9c11f 100644
@@ -526,14 +526,17 @@ static void adp5588_report_events(struct adp5588_kpad *kpad, int ev_cnt)
 	int i;
 
 	for (i = 0; i < ev_cnt; i++) {
-		int key = adp5588_read(kpad->client, KEY_EVENTA + i);
-		int key_val = key & KEY_EV_MASK;
-		int key_press = key & KEY_EV_PRESSED;
+		int key, key_val, key_press;
 
+		key = adp5588_read(kpad->client, KEY_EVENTA + i);
+		if (key < 0)
+			continue;
+		key_val = key & KEY_EV_MASK;
+		key_press = key & KEY_EV_PRESSED;
 		if (key_val >= GPI_PIN_BASE && key_val <= GPI_PIN_END) {
 			/* gpio line used as IRQ source */
 			adp5588_gpio_irq_handle(kpad, key_val, key_press);
-		} else {
+		} else if (key_val > 0) {
 			int row = (key_val - 1) / ADP5588_COLS_MAX;
 			int col =  (key_val - 1) % ADP5588_COLS_MAX;
 			int code = MATRIX_SCAN_CODE(row, col, kpad->row_shift);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 7 lines · Denis Arefev

If the adp5588_read function returns 0, then there will be an overflow of the kpad->keycode buffer.

If the adp5588_read function returns a negative value, then the logic is broken - the wrong value is used as an index of the kpad->keycode array.

Quoted 5 lines

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---

Hi Denis,

Thanks for the patch. However, I'm working on a more complete rework of this as suggested in [1]. I should be sending patches for it today or tomorrow.

[1]: https://lore.kernel.org/linux-input/[email protected]/
- Nuno Sá