Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] usb: typec: fix use after free in typec_register_port()
@ 2019-11-26 14:04 Wen Yang
  2019-11-26 15:46 ` Heikki Krogerus
  0 siblings, 1 reply; 2+ messages in thread
From: Wen Yang @ 2019-11-26 14:04 UTC (permalink / raw)
  To: Heikki Krogerus; +Cc: Greg Kroah-Hartman, Wen Yang, linux-usb, linux-kernel

We can't use "port->sw" and/or "port->mux" after it has been freed.

Fixes: 23481121c81d ("usb: typec: class: Don't use port parent for getting mux handles")
Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/usb/typec/class.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 7ece6ca..91d6227 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -1612,14 +1612,16 @@ struct typec_port *typec_register_port(struct device *parent,
 
 	port->sw = typec_switch_get(&port->dev);
 	if (IS_ERR(port->sw)) {
+		ret = PTR_ERR(port->sw);
 		put_device(&port->dev);
-		return ERR_CAST(port->sw);
+		return ERR_PTR(ret);
 	}
 
 	port->mux = typec_mux_get(&port->dev, NULL);
 	if (IS_ERR(port->mux)) {
+		ret = PTR_ERR(port->mux);
 		put_device(&port->dev);
-		return ERR_CAST(port->mux);
+		return ERR_PTR(ret);
 	}
 
 	ret = device_add(&port->dev);
-- 
1.8.3.1


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

* Re: [PATCH] usb: typec: fix use after free in typec_register_port()
  2019-11-26 14:04 [PATCH] usb: typec: fix use after free in typec_register_port() Wen Yang
@ 2019-11-26 15:46 ` Heikki Krogerus
  0 siblings, 0 replies; 2+ messages in thread
From: Heikki Krogerus @ 2019-11-26 15:46 UTC (permalink / raw)
  To: Wen Yang; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel

On Tue, Nov 26, 2019 at 10:04:52PM +0800, Wen Yang wrote:
> We can't use "port->sw" and/or "port->mux" after it has been freed.
> 
> Fixes: 23481121c81d ("usb: typec: class: Don't use port parent for getting mux handles")
> Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>

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

> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: linux-usb@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/usb/typec/class.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 7ece6ca..91d6227 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -1612,14 +1612,16 @@ struct typec_port *typec_register_port(struct device *parent,
>  
>  	port->sw = typec_switch_get(&port->dev);
>  	if (IS_ERR(port->sw)) {
> +		ret = PTR_ERR(port->sw);
>  		put_device(&port->dev);
> -		return ERR_CAST(port->sw);
> +		return ERR_PTR(ret);
>  	}
>  
>  	port->mux = typec_mux_get(&port->dev, NULL);
>  	if (IS_ERR(port->mux)) {
> +		ret = PTR_ERR(port->mux);
>  		put_device(&port->dev);
> -		return ERR_CAST(port->mux);
> +		return ERR_PTR(ret);
>  	}
>  
>  	ret = device_add(&port->dev);
> -- 
> 1.8.3.1

thanks,

-- 
heikki

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-26 14:04 [PATCH] usb: typec: fix use after free in typec_register_port() Wen Yang
2019-11-26 15:46 ` Heikki Krogerus

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org
	public-inbox-index linux-usb

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git