linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Denis Arefev <arefev@swemel.ru>
Cc: stable@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Michael Hennerich <michael.hennerich@analog.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	lvc-project@linuxtesting.org
Subject: Re: [PATCH 5/10] Input: adp5588-keys - added a check key_val
Date: Thu, 19 Sep 2024 14:45:45 +0000	[thread overview]
Message-ID: <Zuw5GZ2k3T-JKhHK@google.com> (raw)
In-Reply-To: <20240919142914.100609-1-arefev@swemel.ru>

Hi Denis,

On Thu, Sep 19, 2024 at 05:29:14PM +0300, Denis Arefev wrote:
> No upstream commit exists for this commit.

Sorry, what does this mean?

> 
> If the adp5588_read function returns 0, then there will be an
> overflow of the kpad->keycode[key_val - 1] 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.
> 
> Fixes: 69a4af606ed4 ("Input: adp5588-keys - support GPI events for ADP5588 devices")
> Cc: stable@vger.kernel.org
> Signed-off-by: Denis Arefev <arefev@swemel.ru>
> ---
>  drivers/input/keyboard/adp5588-keys.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c
> index 90a59b973d00..19be8054eb5f 100644
> --- a/drivers/input/keyboard/adp5588-keys.c
> +++ b/drivers/input/keyboard/adp5588-keys.c
> @@ -272,6 +272,8 @@ static void adp5588_report_events(struct adp5588_kpad *kpad, int ev_cnt)
>  		int key = adp5588_read(kpad->client, Key_EVENTA + i);
>  		int key_val = key & KEY_EV_MASK;
>  
> +		if (key_val <= 0)
> +			continue;

We should be checking the original value (key) and not masked value.
Masked value will never be negative.

		int key, key_vali, key_press;

		key = adp5588_read(kpad->client, Key_EVENTA + i);
		if (key < 0)
			continue;

		key_val = key & key & KEY_EV_MASK;
		key_press = key & KEY_EV_PRESSED;
		if (key_val >= GPI_PIN_BASE && key_val <= GPI_PIN_END) {
			...
		} else if (key_val > 0) {
			...
		}

Thanks.

-- 
Dmitry

      reply	other threads:[~2024-09-19 14:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-19 14:29 [PATCH 5/10] Input: adp5588-keys - added a check key_val Denis Arefev
2024-09-19 14:45 ` Dmitry Torokhov [this message]

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=Zuw5GZ2k3T-JKhHK@google.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=arefev@swemel.ru \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=michael.hennerich@analog.com \
    --cc=stable@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).