linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: adp5588-keys - Added checking of key and key_val variables
@ 2024-09-20  9:23 Denis Arefev
  0 siblings, 0 replies; 3+ messages in thread
From: Denis Arefev @ 2024-09-20  9:23 UTC (permalink / raw)
  To: Michael Hennerich
  Cc: Dmitry Torokhov, linux-input, linux-kernel, lvc-project, stable

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.

Cc: stable@vger.kernel.org # v5.10+
Signed-off-by: Denis Arefev <arefev@swemel.ru>
---
 drivers/input/keyboard/adp5588-keys.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c
index 1b0279393df4..d05387f9c11f 100644
--- a/drivers/input/keyboard/adp5588-keys.c
+++ b/drivers/input/keyboard/adp5588-keys.c
@@ -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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] Input: adp5588-keys - Added checking of key and key_val variables
@ 2024-09-30  8:36 Denis Arefev
  2024-09-30  9:33 ` Nuno Sá
  0 siblings, 1 reply; 3+ messages in thread
From: Denis Arefev @ 2024-09-30  8:36 UTC (permalink / raw)
  To: Michael Hennerich
  Cc: Dmitry Torokhov, linux-input, linux-kernel, lvc-project, stable

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.

Cc: stable@vger.kernel.org # v5.10+
Signed-off-by: Denis Arefev <arefev@swemel.ru>
---
 drivers/input/keyboard/adp5588-keys.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c
index 1b0279393df4..d05387f9c11f 100644
--- a/drivers/input/keyboard/adp5588-keys.c
+++ b/drivers/input/keyboard/adp5588-keys.c
@@ -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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Input: adp5588-keys - Added checking of key and key_val variables
  2024-09-30  8:36 [PATCH] Input: adp5588-keys - Added checking of key and key_val variables Denis Arefev
@ 2024-09-30  9:33 ` Nuno Sá
  0 siblings, 0 replies; 3+ messages in thread
From: Nuno Sá @ 2024-09-30  9:33 UTC (permalink / raw)
  To: Denis Arefev, Michael Hennerich
  Cc: Dmitry Torokhov, linux-input, linux-kernel, lvc-project, stable

On Mon, 2024-09-30 at 11:36 +0300, Denis Arefev wrote:
> 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.
> 
> Cc: stable@vger.kernel.org # v5.10+
> Signed-off-by: Denis Arefev <arefev@swemel.ru>
> ---

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/Zu0vq0ogr2HzXWv7@google.com/
- Nuno Sá


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-09-30  9:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-30  8:36 [PATCH] Input: adp5588-keys - Added checking of key and key_val variables Denis Arefev
2024-09-30  9:33 ` Nuno Sá
  -- strict thread matches above, loose matches on Subject: below --
2024-09-20  9:23 Denis Arefev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).