Stable Archive mirror
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Jack Pham <jackp@codeaurora.org>
Cc: Greg KH <gregkh@linuxfoundation.org>,
	Subbaraman Narayanamurthy <subbaram@codeaurora.org>,
	linux-usb@vger.kernel.org, Mayank Rana <mrana@codeaurora.org>,
	stable@vger.kernel.org
Subject: Re: [PATCH] usb: typec: ucsi: Clear PPM capability data in ucsi_init() error path
Date: Wed, 9 Jun 2021 15:03:05 +0300	[thread overview]
Message-ID: <YMCt+aiot6yObtZA@kuha.fi.intel.com> (raw)
In-Reply-To: <20210609073535.5094-1-jackp@codeaurora.org>

On Wed, Jun 09, 2021 at 12:35:35AM -0700, Jack Pham wrote:
> From: Mayank Rana <mrana@codeaurora.org>
> 
> If ucsi_init() fails for some reason (e.g. ucsi_register_port()
> fails or general communication failure to the PPM), particularly at
> any point after the GET_CAPABILITY command had been issued, this
> results in unwinding the initialization and returning an error.
> However the ucsi structure's ucsi_capability member retains its
> current value, including likely a non-zero num_connectors.
> And because ucsi_init() itself is done in a workqueue a UCSI
> interface driver will be unaware that it failed and may think the
> ucsi_register() call was completely successful.  Later, if
> ucsi_unregister() is called, due to this stale ucsi->cap value it
> would try to access the items in the ucsi->connector array which
> might not be in a proper state or not even allocated at all and
> results in NULL or invalid pointer dereference.
> 
> Fix this by clearing the ucsi->cap value to 0 during the error
> path of ucsi_init() in order to prevent a later ucsi_unregister()
> from entering the connector cleanup loop.
> 
> Fixes: c1b0bc2dabfa ("usb: typec: Add support for UCSI interface")
> Cc: stable@vger.kernel.org
> Signed-off-by: Mayank Rana <mrana@codeaurora.org>
> Signed-off-by: Jack Pham <jackp@codeaurora.org>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/ucsi/ucsi.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index b433169ef6fa..b7d104c80d85 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1253,6 +1253,7 @@ static int ucsi_init(struct ucsi *ucsi)
>  	}
>  
>  err_reset:
> +	memset(&ucsi->cap, 0, sizeof(ucsi->cap));
>  	ucsi_reset_ppm(ucsi);
>  err:
>  	return ret;
> -- 
> 2.24.0

-- 
heikki

      reply	other threads:[~2021-06-09 12:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-09  7:35 [PATCH] usb: typec: ucsi: Clear PPM capability data in ucsi_init() error path Jack Pham
2021-06-09 12:03 ` Heikki Krogerus [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=YMCt+aiot6yObtZA@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jackp@codeaurora.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mrana@codeaurora.org \
    --cc=stable@vger.kernel.org \
    --cc=subbaram@codeaurora.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 read-only IMAP folder(s) and NNTP newsgroup(s).