linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Alexander Potapenko <glider@google.com>
Cc: dvyukov@google.com, elver@google.com, linux-input@vger.kernel.org
Subject: Re: [PATCH] Input: psmouse: check the result of PSMOUSE_CMD_GET* commands
Date: Fri, 10 Dec 2021 18:54:59 -0800	[thread overview]
Message-ID: <YbQTA9NWoDAknJKB@google.com> (raw)
In-Reply-To: <20211129143845.1472453-1-glider@google.com>

Hi Alexander,

On Mon, Nov 29, 2021 at 03:38:45PM +0100, Alexander Potapenko wrote:
> Execution of a PSMOUSE_CMD_GET* command may fail, leaving the output
> buffer uninitialized. Make sure to check the return value of
> ps2_command() and bail out before checking the buffer contents.
> 
> The use of uninitialized data in genius_detect() was detected by KMSAN,
> other places were fixed for the sake of uniformity.
> 
> Signed-off-by: Alexander Potapenko <glider@google.com>
> ---
>  drivers/input/mouse/psmouse-base.c | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
> index 0b4a3039f312f..a3305653ce891 100644
> --- a/drivers/input/mouse/psmouse-base.c
> +++ b/drivers/input/mouse/psmouse-base.c
> @@ -546,13 +546,16 @@ static int genius_detect(struct psmouse *psmouse, bool set_properties)
>  {
>  	struct ps2dev *ps2dev = &psmouse->ps2dev;
>  	u8 param[4];
> +	int error;
>  
>  	param[0] = 3;
>  	ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
>  	ps2_command(ps2dev,  NULL, PSMOUSE_CMD_SETSCALE11);
>  	ps2_command(ps2dev,  NULL, PSMOUSE_CMD_SETSCALE11);
>  	ps2_command(ps2dev,  NULL, PSMOUSE_CMD_SETSCALE11);
> -	ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
> +	error = ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
> +	if (error)
> +		return error;

If we care about this I think we should care about errors from the rest
of ps2_command()s. Otherwise we might have buffer initialized, but we
are still checking potential garbage in it.

Thanks.

-- 
Dmitry

  reply	other threads:[~2021-12-11  2:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-29 14:38 [PATCH] Input: psmouse: check the result of PSMOUSE_CMD_GET* commands Alexander Potapenko
2021-12-11  2:54 ` Dmitry Torokhov [this message]
2021-12-13 11:26   ` Alexander Potapenko
2021-12-13 11:32     ` Alexander Potapenko

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=YbQTA9NWoDAknJKB@google.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=glider@google.com \
    --cc=linux-input@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).