Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] usb: roles: fix a potential use after free
@ 2019-11-24 14:22 Wen Yang
  2019-11-25  9:35 ` Peter Chen
  2019-11-26 15:49 ` Heikki Krogerus
  0 siblings, 2 replies; 4+ messages in thread
From: Wen Yang @ 2019-11-24 14:22 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Heikki Krogerus
  Cc: Wen Yang, Hans de Goede, Chunfeng Yun, Suzuki K Poulose,
	linux-usb, linux-kernel

Free the sw structure only after we are done using it.
This patch just moves the put_device() down a bit to avoid the
use after free.

Fixes: 5c54fcac9a9d ("usb: roles: Take care of driver module reference counting")
Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Chunfeng Yun <chunfeng.yun@mediatek.com>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: linux-usb@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/usb/roles/class.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index 8273126..63a00ff 100644
--- a/drivers/usb/roles/class.c
+++ b/drivers/usb/roles/class.c
@@ -169,8 +169,8 @@ struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *fwnode)
 void usb_role_switch_put(struct usb_role_switch *sw)
 {
 	if (!IS_ERR_OR_NULL(sw)) {
-		put_device(&sw->dev);
 		module_put(sw->dev.parent->driver->owner);
+		put_device(&sw->dev);
 	}
 }
 EXPORT_SYMBOL_GPL(usb_role_switch_put);
-- 
1.8.3.1


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

* Re: [PATCH] usb: roles: fix a potential use after free
  2019-11-24 14:22 [PATCH] usb: roles: fix a potential use after free Wen Yang
@ 2019-11-25  9:35 ` Peter Chen
  2019-11-26 15:49 ` Heikki Krogerus
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Chen @ 2019-11-25  9:35 UTC (permalink / raw)
  To: Wen Yang
  Cc: Greg Kroah-Hartman, Heikki Krogerus, Hans de Goede, Chunfeng Yun,
	Suzuki K Poulose, linux-usb, linux-kernel

On 19-11-24 22:22:36, Wen Yang wrote:
> Free the sw structure only after we are done using it.
> This patch just moves the put_device() down a bit to avoid the
> use after free.
> 
> Fixes: 5c54fcac9a9d ("usb: roles: Take care of driver module reference counting")
> Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Hans de Goede <hdegoede@redhat.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Chunfeng Yun <chunfeng.yun@mediatek.com>
> Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
> Cc: linux-usb@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/usb/roles/class.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index 8273126..63a00ff 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -169,8 +169,8 @@ struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *fwnode)
>  void usb_role_switch_put(struct usb_role_switch *sw)
>  {
>  	if (!IS_ERR_OR_NULL(sw)) {
> -		put_device(&sw->dev);
>  		module_put(sw->dev.parent->driver->owner);
> +		put_device(&sw->dev);
>  	}
>  }
>  EXPORT_SYMBOL_GPL(usb_role_switch_put);
> -- 
> 1.8.3.1
> 

Reviewed-by: Peter Chen <peter.chen@nxp.com>

-- 

Thanks,
Peter Chen

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

* Re: [PATCH] usb: roles: fix a potential use after free
  2019-11-24 14:22 [PATCH] usb: roles: fix a potential use after free Wen Yang
  2019-11-25  9:35 ` Peter Chen
@ 2019-11-26 15:49 ` Heikki Krogerus
  2019-11-26 15:50   ` Heikki Krogerus
  1 sibling, 1 reply; 4+ messages in thread
From: Heikki Krogerus @ 2019-11-26 15:49 UTC (permalink / raw)
  To: Wen Yang
  Cc: Greg Kroah-Hartman, Hans de Goede, Chunfeng Yun,
	Suzuki K Poulose, linux-usb, linux-kernel

On Sun, Nov 24, 2019 at 10:22:36PM +0800, Wen Yang wrote:
> Free the sw structure only after we are done using it.
> This patch just moves the put_device() down a bit to avoid the
> use after free.
> 
> Fixes: 5c54fcac9a9d ("usb: roles: Take care of driver module reference counting")
> Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Hans de Goede <hdegoede@redhat.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Chunfeng Yun <chunfeng.yun@mediatek.com>
> Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
> Cc: linux-usb@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/usb/roles/class.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index 8273126..63a00ff 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -169,8 +169,8 @@ struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *fwnode)
>  void usb_role_switch_put(struct usb_role_switch *sw)
>  {
>  	if (!IS_ERR_OR_NULL(sw)) {
> -		put_device(&sw->dev);
>  		module_put(sw->dev.parent->driver->owner);
> +		put_device(&sw->dev);
>  	}
>  }
>  EXPORT_SYMBOL_GPL(usb_role_switch_put);
> -- 
> 1.8.3.1

-- 
heikki

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

* Re: [PATCH] usb: roles: fix a potential use after free
  2019-11-26 15:49 ` Heikki Krogerus
@ 2019-11-26 15:50   ` Heikki Krogerus
  0 siblings, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2019-11-26 15:50 UTC (permalink / raw)
  To: Wen Yang
  Cc: Greg Kroah-Hartman, Hans de Goede, Chunfeng Yun,
	Suzuki K Poulose, linux-usb, linux-kernel

On Tue, Nov 26, 2019 at 05:49:17PM +0200, Heikki Krogerus wrote:
> On Sun, Nov 24, 2019 at 10:22:36PM +0800, Wen Yang wrote:
> > Free the sw structure only after we are done using it.
> > This patch just moves the put_device() down a bit to avoid the
> > use after free.
> > 
> > Fixes: 5c54fcac9a9d ("usb: roles: Take care of driver module reference counting")
> > Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
> > Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> > Cc: Hans de Goede <hdegoede@redhat.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
> > Cc: linux-usb@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org

Ups, sorry. I meant:

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

thanks,

-- 
heikki

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-24 14:22 [PATCH] usb: roles: fix a potential use after free Wen Yang
2019-11-25  9:35 ` Peter Chen
2019-11-26 15:49 ` Heikki Krogerus
2019-11-26 15:50   ` 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