linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] usb: typec: tcpm: fix use-after-free case in tcpm_register_source_caps
@ 2024-05-14 22:01 Amit Sunil Dhamne
  2024-05-14 23:00 ` Ondřej Jirman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Amit Sunil Dhamne @ 2024-05-14 22:01 UTC (permalink / raw)
  To: linux, heikki.krogerus, gregkh, megi
  Cc: badhri, rdbabiera, linux-usb, linux-kernel, Amit Sunil Dhamne,
	stable

There could be a potential use-after-free case in
tcpm_register_source_caps(). This could happen when:
 * new (say invalid) source caps are advertised
 * the existing source caps are unregistered
 * tcpm_register_source_caps() returns with an error as
   usb_power_delivery_register_capabilities() fails

This causes port->partner_source_caps to hold on to the now freed source
caps.

Reset port->partner_source_caps value to NULL after unregistering
existing source caps.

Fixes: 230ecdf71a64 ("usb: typec: tcpm: unregister existing source caps before re-registration")
Cc: stable@vger.kernel.org
Signed-off-by: Amit Sunil Dhamne <amitsd@google.com>
---
 drivers/usb/typec/tcpm/tcpm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 8a1af08f71b6..be4127ef84e9 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -3014,8 +3014,10 @@ static int tcpm_register_source_caps(struct tcpm_port *port)
 	memcpy(caps.pdo, port->source_caps, sizeof(u32) * port->nr_source_caps);
 	caps.role = TYPEC_SOURCE;
 
-	if (cap)
+	if (cap) {
 		usb_power_delivery_unregister_capabilities(cap);
+		port->partner_source_caps = NULL;
+	}
 
 	cap = usb_power_delivery_register_capabilities(port->partner_pd, &caps);
 	if (IS_ERR(cap))

base-commit: 51474ab44abf907023a8a875e799b07de461e466
-- 
2.45.0.rc1.225.g2a3ae87e7f-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] usb: typec: tcpm: fix use-after-free case in tcpm_register_source_caps
  2024-05-14 22:01 [PATCH v1] usb: typec: tcpm: fix use-after-free case in tcpm_register_source_caps Amit Sunil Dhamne
@ 2024-05-14 23:00 ` Ondřej Jirman
  2024-05-19  8:00 ` Dmitry Baryshkov
  2024-05-21 13:53 ` Heikki Krogerus
  2 siblings, 0 replies; 4+ messages in thread
From: Ondřej Jirman @ 2024-05-14 23:00 UTC (permalink / raw)
  To: Amit Sunil Dhamne
  Cc: linux, heikki.krogerus, gregkh, badhri, rdbabiera, linux-usb,
	linux-kernel, stable

On Tue, May 14, 2024 at 03:01:31PM GMT, Amit Sunil Dhamne wrote:
> There could be a potential use-after-free case in
> tcpm_register_source_caps(). This could happen when:
>  * new (say invalid) source caps are advertised
>  * the existing source caps are unregistered
>  * tcpm_register_source_caps() returns with an error as
>    usb_power_delivery_register_capabilities() fails
> 
> This causes port->partner_source_caps to hold on to the now freed source
> caps.
> 
> Reset port->partner_source_caps value to NULL after unregistering
> existing source caps.
> 
> Fixes: 230ecdf71a64 ("usb: typec: tcpm: unregister existing source caps before re-registration")
> Cc: stable@vger.kernel.org
> Signed-off-by: Amit Sunil Dhamne <amitsd@google.com>
>

Reviewed-by: Ondrej Jirman <megi@xff.cz>

Thanks for the fix.

Kind regards,
	o.

>
> ---
>  drivers/usb/typec/tcpm/tcpm.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 8a1af08f71b6..be4127ef84e9 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -3014,8 +3014,10 @@ static int tcpm_register_source_caps(struct tcpm_port *port)
>  	memcpy(caps.pdo, port->source_caps, sizeof(u32) * port->nr_source_caps);
>  	caps.role = TYPEC_SOURCE;
>  
> -	if (cap)
> +	if (cap) {
>  		usb_power_delivery_unregister_capabilities(cap);
> +		port->partner_source_caps = NULL;
> +	}
>  
>  	cap = usb_power_delivery_register_capabilities(port->partner_pd, &caps);
>  	if (IS_ERR(cap))
> 
> base-commit: 51474ab44abf907023a8a875e799b07de461e466
> -- 
> 2.45.0.rc1.225.g2a3ae87e7f-goog
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] usb: typec: tcpm: fix use-after-free case in tcpm_register_source_caps
  2024-05-14 22:01 [PATCH v1] usb: typec: tcpm: fix use-after-free case in tcpm_register_source_caps Amit Sunil Dhamne
  2024-05-14 23:00 ` Ondřej Jirman
@ 2024-05-19  8:00 ` Dmitry Baryshkov
  2024-05-21 13:53 ` Heikki Krogerus
  2 siblings, 0 replies; 4+ messages in thread
From: Dmitry Baryshkov @ 2024-05-19  8:00 UTC (permalink / raw)
  To: Amit Sunil Dhamne
  Cc: linux, heikki.krogerus, gregkh, megi, badhri, rdbabiera,
	linux-usb, linux-kernel, stable

On Tue, May 14, 2024 at 03:01:31PM -0700, Amit Sunil Dhamne wrote:
> There could be a potential use-after-free case in
> tcpm_register_source_caps(). This could happen when:
>  * new (say invalid) source caps are advertised
>  * the existing source caps are unregistered
>  * tcpm_register_source_caps() returns with an error as
>    usb_power_delivery_register_capabilities() fails
> 
> This causes port->partner_source_caps to hold on to the now freed source
> caps.
> 
> Reset port->partner_source_caps value to NULL after unregistering
> existing source caps.
> 
> Fixes: 230ecdf71a64 ("usb: typec: tcpm: unregister existing source caps before re-registration")
> Cc: stable@vger.kernel.org
> Signed-off-by: Amit Sunil Dhamne <amitsd@google.com>
> ---
>  drivers/usb/typec/tcpm/tcpm.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>


-- 
With best wishes
Dmitry

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] usb: typec: tcpm: fix use-after-free case in tcpm_register_source_caps
  2024-05-14 22:01 [PATCH v1] usb: typec: tcpm: fix use-after-free case in tcpm_register_source_caps Amit Sunil Dhamne
  2024-05-14 23:00 ` Ondřej Jirman
  2024-05-19  8:00 ` Dmitry Baryshkov
@ 2024-05-21 13:53 ` Heikki Krogerus
  2 siblings, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2024-05-21 13:53 UTC (permalink / raw)
  To: Amit Sunil Dhamne
  Cc: linux, gregkh, megi, badhri, rdbabiera, linux-usb, linux-kernel,
	stable

On Tue, May 14, 2024 at 03:01:31PM -0700, Amit Sunil Dhamne wrote:
> There could be a potential use-after-free case in
> tcpm_register_source_caps(). This could happen when:
>  * new (say invalid) source caps are advertised
>  * the existing source caps are unregistered
>  * tcpm_register_source_caps() returns with an error as
>    usb_power_delivery_register_capabilities() fails
> 
> This causes port->partner_source_caps to hold on to the now freed source
> caps.
> 
> Reset port->partner_source_caps value to NULL after unregistering
> existing source caps.
> 
> Fixes: 230ecdf71a64 ("usb: typec: tcpm: unregister existing source caps before re-registration")
> Cc: stable@vger.kernel.org
> Signed-off-by: Amit Sunil Dhamne <amitsd@google.com>

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

> ---
>  drivers/usb/typec/tcpm/tcpm.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 8a1af08f71b6..be4127ef84e9 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -3014,8 +3014,10 @@ static int tcpm_register_source_caps(struct tcpm_port *port)
>  	memcpy(caps.pdo, port->source_caps, sizeof(u32) * port->nr_source_caps);
>  	caps.role = TYPEC_SOURCE;
>  
> -	if (cap)
> +	if (cap) {
>  		usb_power_delivery_unregister_capabilities(cap);
> +		port->partner_source_caps = NULL;
> +	}
>  
>  	cap = usb_power_delivery_register_capabilities(port->partner_pd, &caps);
>  	if (IS_ERR(cap))
> 
> base-commit: 51474ab44abf907023a8a875e799b07de461e466
> -- 
> 2.45.0.rc1.225.g2a3ae87e7f-goog

-- 
heikki

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-21 13:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-14 22:01 [PATCH v1] usb: typec: tcpm: fix use-after-free case in tcpm_register_source_caps Amit Sunil Dhamne
2024-05-14 23:00 ` Ondřej Jirman
2024-05-19  8:00 ` Dmitry Baryshkov
2024-05-21 13:53 ` Heikki Krogerus

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).