mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: "Ajay Gupta" <ajayg@nvidia.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Dmitry Baryshkov" <dmitry.baryshkov@linaro.org>,
	"Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
	"Haotien Hsu" <haotienh@nvidia.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] usb: typec: fix potential array underflow in ucsi_ccg_sync_control()
Date: Tue, 12 Nov 2024 13:51:39 +0200	[thread overview]
Message-ID: <ZzNBS4M9c0tjSmX1@kuha.fi.intel.com> (raw)
In-Reply-To: <c69ef0b3-61b0-4dde-98dd-97b97f81d912@stanley.mountain>

On Mon, Nov 11, 2024 at 02:08:06PM +0300, Dan Carpenter wrote:
> The "command" variable can be controlled by the user via debugfs.  The
> worry is that if con_index is zero then "&uc->ucsi->connector[con_index
> - 1]" would be an array underflow.
> 
> Fixes: 170a6726d0e2 ("usb: typec: ucsi: add support for separate DP altmode devices")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

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

> ---
>  drivers/usb/typec/ucsi/ucsi_ccg.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c
> index bccfc03b5986..fcb8e61136cf 100644
> --- a/drivers/usb/typec/ucsi/ucsi_ccg.c
> +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c
> @@ -644,6 +644,10 @@ static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command)
>  	    uc->has_multiple_dp) {
>  		con_index = (uc->last_cmd_sent >> 16) &
>  			UCSI_CMD_CONNECTOR_MASK;
> +		if (con_index == 0) {
> +			ret = -EINVAL;
> +			goto unlock;
> +		}
>  		con = &uc->ucsi->connector[con_index - 1];
>  		ucsi_ccg_update_set_new_cam_cmd(uc, con, &command);
>  	}
> @@ -651,6 +655,7 @@ static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command)
>  	ret = ucsi_sync_control_common(ucsi, command);
>  
>  	pm_runtime_put_sync(uc->dev);
> +unlock:
>  	mutex_unlock(&uc->lock);
>  
>  	return ret;
> -- 
> 2.45.2

-- 
heikki

      reply	other threads:[~2024-11-12 11:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-11 11:08 Dan Carpenter
2024-11-12 11:51 ` 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=ZzNBS4M9c0tjSmX1@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=ajayg@nvidia.com \
    --cc=dan.carpenter@linaro.org \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=haotienh@nvidia.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=u.kleine-koenig@baylibre.com \
    /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

all inboxes | Powered by JetHome®