From: "M. Vefa Bicakci" <m.v.b@runbox.com>
To: linux-usb@vger.kernel.org
Cc: "M. Vefa Bicakci" <m.v.b@runbox.com>,
stable@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Alan Stern <stern@rowland.harvard.edu>,
Bastien Nocera <hadess@hadess.net>, Shuah Khan <shuah@kernel.org>,
Valentina Manea <valentina.manea.m@gmail.com>,
syzkaller@googlegroups.com
Subject: [PATCH v3 3/4] usbcore/driver: Fix incorrect downcast
Date: Tue, 22 Sep 2020 14:07:02 +0300 [thread overview]
Message-ID: <20200922110703.720960-4-m.v.b@runbox.com> (raw)
In-Reply-To: <20200922110703.720960-1-m.v.b@runbox.com>
This commit resolves a minor bug in the selection/discovery of more
specific USB device drivers for devices that are currently bound to
generic USB device drivers.
The bug is related to the way a candidate USB device driver is
compared against the generic USB device driver. The code in
is_dev_usb_generic_driver() assumes that the device driver in question
is a USB device driver by calling to_usb_device_driver(dev->driver)
to downcast; however I have observed that this assumption is not always
true, through code instrumentation.
This commit avoids the incorrect downcast altogether by comparing
the USB device's driver (i.e., dev->driver) to the generic USB
device driver directly. This method was suggested by Alan Stern.
This bug was found while investigating Andrey Konovalov's report
indicating usbip device driver misbehaviour with the recently merged
generic USB device driver selection feature. The report is linked
below.
Fixes: d5643d2249 ("USB: Fix device driver race")
Link: https://lore.kernel.org/linux-usb/CAAeHK+zOrHnxjRFs=OE8T=O9208B9HP_oo8RZpyVOZ9AJ54pAA@mail.gmail.com/
Cc: <stable@vger.kernel.org> # 5.8
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Bastien Nocera <hadess@hadess.net>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Valentina Manea <valentina.manea.m@gmail.com>
Cc: <syzkaller@googlegroups.com>
Signed-off-by: M. Vefa Bicakci <m.v.b@runbox.com>
---
v3: Simplify the device driver pointer comparison to avoid incorrect
downcast, as suggested by Alan Stern. Minor edits to the commit
message.
v2: Following Bastien Nocera's code review comment, use is_usb_device()
to verify that a device is bound to a USB device driver (as opposed
to, e.g., a USB interface driver) to avoid incorrect downcast.
---
drivers/usb/core/driver.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 950044a6e77f..7d90cbe063ec 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -905,21 +905,14 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
return 0;
}
-static bool is_dev_usb_generic_driver(struct device *dev)
-{
- struct usb_device_driver *udd = dev->driver ?
- to_usb_device_driver(dev->driver) : NULL;
-
- return udd == &usb_generic_driver;
-}
-
static int __usb_bus_reprobe_drivers(struct device *dev, void *data)
{
struct usb_device_driver *new_udriver = data;
struct usb_device *udev;
int ret;
- if (!is_dev_usb_generic_driver(dev))
+ /* Don't reprobe if current driver isn't usb_generic_driver */
+ if (dev->driver != &usb_generic_driver.drvwrap.driver)
return 0;
udev = to_usb_device(dev);
--
2.26.2
next prev parent reply other threads:[~2020-09-22 11:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200922110703.720960-1-m.v.b@runbox.com>
2020-09-22 11:07 ` [PATCH v3 1/4] Revert "usbip: Implement a match function to fix usbip" M. Vefa Bicakci
2020-09-22 23:03 ` Shuah Khan
2020-09-22 11:07 ` [PATCH v3 2/4] usbcore/driver: Fix specific driver selection M. Vefa Bicakci
2020-09-22 11:07 ` M. Vefa Bicakci [this message]
2020-09-25 14:51 ` [PATCH v3 3/4] usbcore/driver: Fix incorrect downcast Greg Kroah-Hartman
2020-09-25 16:31 ` M. Vefa Bicakci
2020-09-26 5:37 ` Greg Kroah-Hartman
2020-09-22 11:07 ` [PATCH v3 4/4] usbcore/driver: Accommodate usbip M. Vefa Bicakci
2020-09-22 23:04 ` Shuah Khan
2020-09-23 6:08 ` M. Vefa Bicakci
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=20200922110703.720960-4-m.v.b@runbox.com \
--to=m.v.b@runbox.com \
--cc=gregkh@linuxfoundation.org \
--cc=hadess@hadess.net \
--cc=linux-usb@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=stable@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=syzkaller@googlegroups.com \
--cc=valentina.manea.m@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).