lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Z6DVRbmwB859RlCt@kuha.fi.intel.com>
Date: Mon, 3 Feb 2025 16:40:05 +0200
From: Heikki Krogerus <heikki.krogerus@...ux.intel.com>
To: Elson Roy Serrao <quic_eserrao@...cinc.com>
Cc: gregkh@...uxfoundation.org, xu.yang_2@....com,
	linux-usb@...r.kernel.org, linux-kernel@...r.kernel.org,
	stable@...r.kernel.org
Subject: Re: [PATCH] usb: roles: cache usb roles received during switch
 registration

On Mon, Jan 27, 2025 at 03:07:15PM -0800, Elson Roy Serrao wrote:
> The role switch registration and set_role() can happen in parallel as they
> are invoked independent of each other. There is a possibility that a driver
> might spend significant amount of time in usb_role_switch_register() API
> due to the presence of time intensive operations like component_add()
> which operate under common mutex. This leads to a time window after
> allocating the switch and before setting the registered flag where the set
> role notifications are dropped. Below timeline summarizes this behavior
> 
> Thread1				|	Thread2
> usb_role_switch_register()	|
> 	|			|
> 	---> allocate switch	|
> 	|			|
> 	---> component_add()	|	usb_role_switch_set_role()
> 	|			|	|
> 	|			|	--> Drop role notifications
> 	|			|	    since sw->registered
> 	|			|	    flag is not set.
> 	|			|
> 	--->Set registered flag.|
> 
> To avoid this, cache the last role received and set it once the switch
> registration is complete. Since we are now caching the roles based on
> registered flag, protect this flag with the switch mutex.

Instead, why not just mark the switch registered from the get-go?

diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index c58a12c147f4..cf38be82d397 100644
--- a/drivers/usb/roles/class.c
+++ b/drivers/usb/roles/class.c
@@ -387,6 +387,8 @@ usb_role_switch_register(struct device *parent,
        dev_set_name(&sw->dev, "%s-role-switch",
                     desc->name ? desc->name : dev_name(parent));
 
+       sw->registered = true;
+
        ret = device_register(&sw->dev);
        if (ret) {
                put_device(&sw->dev);
@@ -399,8 +401,6 @@ usb_role_switch_register(struct device *parent,
                        dev_warn(&sw->dev, "failed to add component\n");
        }
 
-       sw->registered = true;
-
        /* TODO: Symlinks for the host port and the device controller. */
 
        return sw;


thanks,

-- 
heikki

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ