mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: RD Babiera <rdbabiera@google.com>
Cc: badhri@google.com, gregkh@linuxfoundation.org,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v1] usb: typec: altmodes/displayport: do not index invalid pin_assignments
Date: Tue, 24 Jun 2025 11:43:50 +0300	[thread overview]
Message-ID: <aFplRgD8nju9ShAO@kuha.fi.intel.com> (raw)
In-Reply-To: <20250618224943.3263103-2-rdbabiera@google.com>

On Wed, Jun 18, 2025 at 10:49:42PM +0000, RD Babiera wrote:
> A poorly implemented DisplayPort Alt Mode port partner can indicate
> that its pin assignment capabilities are greater than the maximum
> value, DP_PIN_ASSIGN_F. In this case, calls to pin_assignment_show
> will cause a BRK exception due to an out of bounds array access.
> 
> Prevent for loop in pin_assignment_show from accessing
> invalid values in pin_assignments by adding DP_PIN_ASSIGN_MAX
> value in typec_dp.h and using i < DP_PIN_ASSIGN_MAX as a loop
> condition.
> 
> Fixes: 0e3bb7d6894d ("usb: typec: Add driver for DisplayPort alternate mode")
> Cc: stable@vger.kernel.org
> Signed-off-by: RD Babiera <rdbabiera@google.com>
> Reviewed-by: Badhri Jagan Sridharan <badhri@google.com>

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

> ---
>  drivers/usb/typec/altmodes/displayport.c | 2 +-
>  include/linux/usb/typec_dp.h             | 1 +
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
> index b09b58d7311d..773786129dfb 100644
> --- a/drivers/usb/typec/altmodes/displayport.c
> +++ b/drivers/usb/typec/altmodes/displayport.c
> @@ -677,7 +677,7 @@ static ssize_t pin_assignment_show(struct device *dev,
>  
>  	assignments = get_current_pin_assignments(dp);
>  
> -	for (i = 0; assignments; assignments >>= 1, i++) {
> +	for (i = 0; assignments && i < DP_PIN_ASSIGN_MAX; assignments >>= 1, i++) {
>  		if (assignments & 1) {
>  			if (i == cur)
>  				len += sprintf(buf + len, "[%s] ",
> diff --git a/include/linux/usb/typec_dp.h b/include/linux/usb/typec_dp.h
> index f2da264d9c14..acb0ad03bdac 100644
> --- a/include/linux/usb/typec_dp.h
> +++ b/include/linux/usb/typec_dp.h
> @@ -57,6 +57,7 @@ enum {
>  	DP_PIN_ASSIGN_D,
>  	DP_PIN_ASSIGN_E,
>  	DP_PIN_ASSIGN_F, /* Not supported after v1.0b */
> +	DP_PIN_ASSIGN_MAX,
>  };
>  
>  /* DisplayPort alt mode specific commands */
> 
> base-commit: e04c78d86a9699d136910cfc0bdcf01087e3267e
> -- 
> 2.50.0.rc2.701.gf1e915cc24-goog

-- 
heikki

      reply	other threads:[~2025-06-24  8:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-18 22:49 RD Babiera
2025-06-24  8:43 ` 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=aFplRgD8nju9ShAO@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=badhri@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=rdbabiera@google.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

all inboxes | Powered by JetHome®