driver core: avoid klist_remove() on unattached knode_driver
Subsystems (3)
PATCH 1/1 driver core: avoid klist_remove() on unattached knode_driver
usb_driver_claim_interface() sets dev->driver directly and skips device_bind_driver() when the interface is not yet registered, so the device can reach teardown with dev->driver set but knode_driver never added to the driver's klist_devices. __device_release_driver() then unconditionally calls klist_remove() on the unattached node, which dereferences a NULL klist pointer in klist_put() and crashes.
Guard the klist_remove() with klist_node_attached(), mirroring the existing check in bus_remove_device() for knode_bus.
--- drivers/base/dd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/base/dd.c +2 -1
@@ -1354,7 +1354,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)device_unbind_cleanup (dev);device_links_driver_cleanup (dev); -klist_remove (&dev->p->knode_driver); +if (klist_node_attached (&dev->p->knode_driver)) +klist_remove (&dev->p->knode_driver);device_pm_check_callbacks (dev);bus_notify (dev,BUS_NOTIFY_UNBOUND_DRIVER );
Signature · 1 line
2.34.1
PATCH v2 1/1 driver core: avoid klist_remove() on unattached knode_driver
usb_driver_claim_interface() sets dev->driver directly and skips device_bind_driver() when the interface is not yet registered, so the device can reach teardown with dev->driver set but knode_driver never added to the driver's klist_devices. __device_release_driver() then unconditionally calls klist_remove() on the unattached node, which dereferences a NULL klist pointer in klist_put() and crashes.
Only remove the node if the device is actually bound, mirroring the check device_is_bound() already provides for the driver core. This matches the existing guard on knode_bus in bus_remove_device().
--- drivers/base/dd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/base/dd.c +2 -1
@@ -1354,7 +1354,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)device_unbind_cleanup (dev);device_links_driver_cleanup (dev); -klist_remove (&dev->p->knode_driver); +if (device_is_bound (dev)) +klist_remove (&dev->p->knode_driver);device_pm_check_callbacks (dev);bus_notify (dev,BUS_NOTIFY_UNBOUND_DRIVER );
Signature · 1 line
2.34.1
Greg KH
maintainerQuoted 11 lines · Nguyen Quang Le Kien
usb_driver_claim_interface()setsdev->driverdirectly and skipsdevice_bind_driver()when the interface is not yet registered, so the device can reach teardown withdev->driverset butknode_drivernever added to the driver'sklist_devices.__device_release_driver()then unconditionally callsklist_remove()on the unattached node, which dereferences a NULL klist pointer inklist_put()and crashes.Only remove the node if the device is actually bound, mirroring the check
device_is_bound()already provides for the driver core. This matches the existing guard onknode_businbus_remove_device().
Quoted 6 lines
Reported-by [email protected]Signed-off-by Nguyen Quang Le Kien <[email protected]>--- drivers/base/dd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
What changed from v1?
And why did you send the same patch as Edward Adam Davis <[email protected]> just did:
https://lore.kernel.org/r/[email protected]
What is suddenly causing people to care about syzbot bugs for USB?
thanks,
greg k-h
Hi Greg,
v1 used klist_node_attached(&dev->p->knode_driver). v1 passed the syzbot test, but after reviewing the code again I realized klist_node_attached() isn't really the right check at that level -- it's a raw klist API. device_is_bound() is what driver core uses to ask whether a device is bound, and it also handles the NULL dev->p case. So I switched to that in v2. Nothing else changed.
As for syzbot -- it's just where I find kernel bugs, and it can test my patches for me. That's all.
Thanks,
Kien
Greg Kroah-Hartman
maintainerQuoted 1 line · Nguyen Quang Le Kien
Hi Greg,
Please provide email context when responding, some of us get 1000+ emails a day.
Quoted 3 lines
v1 used
klist_node_attached(&dev->p->knode_driver). v1 passed the syzbot test, but after reviewing the code again I realizedklist_node_attached()isn't really the right check at that level -- it's a raw klist API.
Then please document this in the proper place, for v2, as required.
thanks,
greg k-h
PATCH v3 1/1 driver core: avoid klist_remove() on unattached knode_driver
In reply to Greg KHusb_driver_claim_interface() sets dev->driver directly and skips device_bind_driver() when the interface is not yet registered, so the device can reach teardown with dev->driver set but knode_driver never added to the driver's klist_devices. __device_release_driver() then unconditionally calls klist_remove() on the unattached node, which dereferences a NULL klist pointer in klist_put() and crashes.
Only remove the node if the device is actually bound. Use device_is_bound() rather than klist_node_attached() directly: the latter is a raw klist API and does not NULL-check dev->p, while device_is_bound() is the standard bound-state check used throughout driver core (driver_bound(), __device_attach()).
--- drivers/base/dd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/base/dd.c +2 -1
@@ -1354,7 +1354,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)device_unbind_cleanup (dev);device_links_driver_cleanup (dev); -klist_remove (&dev->p->knode_driver); +if (device_is_bound (dev)) +klist_remove (&dev->p->knode_driver);device_pm_check_callbacks (dev);bus_notify (dev,BUS_NOTIFY_UNBOUND_DRIVER );
Signature · 1 line
2.34.1
Greg Kroah-Hartman
maintainerQuoted 39 lines · Nguyen Quang Le Kien
usb_driver_claim_interface()setsdev->driverdirectly and skipsdevice_bind_driver()when the interface is not yet registered, so the device can reach teardown withdev->driverset butknode_drivernever added to the driver'sklist_devices.__device_release_driver()then unconditionally callsklist_remove()on the unattached node, which dereferences a NULL klist pointer inklist_put()and crashes.Only remove the node if the device is actually bound. Use
device_is_bound()rather thanklist_node_attached()directly: the latter is a raw klist API and does not NULL-checkdev->p, whiledevice_is_bound()is the standard bound-state check used throughout driver core (driver_bound(),__device_attach()).Fixes 94e7b1c5ff20 ("[PATCH] Add a klist to struct device_driver for the devices bound to it.")Reported-by [email protected]Signed-off-by Nguyen Quang Le Kien <[email protected]>--- drivers/base/dd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/base/dd.c +2
-1@@ -1354,7 +1354,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)device_unbind_cleanup (dev);device_links_driver_cleanup (dev); -klist_remove (&dev->p->knode_driver); +if (device_is_bound (dev)) +klist_remove (&dev->p->knode_driver);device_pm_check_callbacks (dev);bus_notify (dev,BUS_NOTIFY_UNBOUND_DRIVER );Signature · 1 line
2.34.1
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.
You are receiving this message because of the following common error(s) as indicated below:
- This looks like a new version of a previously submitted patch, but you did not list below the --- line any changes from the previous version. Please read the section entitled "The canonical patch format" in the kernel file, Documentation/process/submitting-patches.rst for what needs to be done here to properly describe this.
- You have marked a patch with a "Fixes:" tag for a commit that is in an older released kernel, yet you do not have a cc: stable line in the signed-off-by area at all, which means that the patch will not be applied to any older kernel releases. To properly fix this, please follow the documented rules in the Documentation/process/stable-kernel-rules.rst file for how to resolve this.
- You have sent patches very very quickly, with no time to have others review them. Slow down, there is no rush here, and no deadlines.
If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.
thanks,
greg k-h's patch email bot
PATCH v4 1/1 driver core: avoid klist_remove() on unattached knode_driver
usb_driver_claim_interface() sets dev->driver directly and skips device_bind_driver() when the interface is not yet registered, so the device can reach teardown with dev->driver set but knode_driver never added to the driver's klist_devices. __device_release_driver() then unconditionally calls klist_remove() on the unattached node, which dereferences a NULL klist pointer in klist_put() and crashes.
Only remove the node if the device is actually bound. Use device_is_bound() rather than klist_node_attached() directly: the latter is a raw klist API and does not NULL-check dev->p, while device_is_bound() is the standard bound-state check used throughout driver core (driver_bound(), __device_attach()).
---
Changes in v4:
- add a changelog below the --- line, as required by submitting-patches.rst
- add Cc: [email protected], Fixes: points to a released kernel
Changes in v3:
- document in the commit message why device_is_bound() is used instead of klist_node_attached()
- add Fixes: tag
Changes in v2:
- use device_is_bound() instead of klist_node_attached() as the bound check, per review
--- drivers/base/dd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/base/dd.c +2 -1
@@ -1354,7 +1354,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)device_unbind_cleanup (dev);device_links_driver_cleanup (dev); -klist_remove (&dev->p->knode_driver); +if (device_is_bound (dev)) +klist_remove (&dev->p->knode_driver);device_pm_check_callbacks (dev);bus_notify (dev,BUS_NOTIFY_UNBOUND_DRIVER );
Signature · 1 line
2.34.1
Greg KH
maintainerQuoted 18 lines · Nguyen Quang Le Kien
usb_driver_claim_interface()setsdev->driverdirectly and skipsdevice_bind_driver()when the interface is not yet registered, so the device can reach teardown withdev->driverset butknode_drivernever added to the driver'sklist_devices.__device_release_driver()then unconditionally callsklist_remove()on the unattached node, which dereferences a NULL klist pointer inklist_put()and crashes.Only remove the node if the device is actually bound. Use
device_is_bound()rather thanklist_node_attached()directly: the latter is a raw klist API and does not NULL-checkdev->p, whiledevice_is_bound()is the standard bound-state check used throughout driver core (driver_bound(),__device_attach()).Fixes 94e7b1c5ff20 ("[PATCH] Add a klist to struct device_driver for the devices bound to it.")Reported-by [email protected]Signed-off-by Nguyen Quang Le Kien <[email protected]>
Quoted 4 lines
---
Changes in v4:
- add a changelog below the --- line, as required bysubmitting-patches.rst
- add Cc: [email protected], Fixes: points to a released kernel
Please slow down. As my bot said, there is no rush, no deadline, and it's the middle of the merge window and we can't even do anything with this anyway.
At the least, wait a week between patch revisions. If you wish to see patches reviewed faster, then help out with actual reviews of patches from others. Constantly resending stuff like this doesn't make anyone want to review this at all.
thanks,
greg k-h
Danilo Krummrich
maintainer(Cc: linux-usb)
Quoted 1 line · Nguyen Quang Le Kien
Fixes 94e7b1c5ff20 ("[PATCH] Add a klist to struct device_driver for the devices bound to it.")
This is not the correct commit to reference, this commit seems fine.
drivers/base/dd.c static void __device_release_driver(struct device *dev, struct device *parent) · line 1358
Quoted 11 lines
drivers/base/dd.c +2
-1@@ -1354,7 +1354,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)device_unbind_cleanup (dev);device_links_driver_cleanup (dev); -klist_remove (&dev->p->knode_driver); +if (device_is_bound (dev)) +klist_remove (&dev->p->knode_driver);
This looks like band-aid for the underlying design tension in the USB core (which we should address instead) and does not belong in the driver core.
It's not visible from the above diff, but with this patch the control flow becomes:
if (dev->driver) {
if (device_is_bound(dev))
klist_remove(&dev->p->knode_driver);
...
}but dev->driver already indicates that the device is bound to dev->driver in this context.
The reason we "need" this check regardless is that usb_driver_claim_interface() (ab)uses dev->driver to indicate that a certain USB driver claimed, or rather reserved, this device.
There are two cases in usb_driver_claim_interface():
(1) The device to claim is already registered with the driver core, in which case device_bind_driver(dev) is called and dev->driver is correctly set during the bind attempt.
(2) The device to claim was not yet registered with the driver core. This can happen when the USB interface the driver actually binds to is registered (and hence probed) before the additional interface the driver wants to claim is registered. The USB core sets dev->driver independent of the bind state to indicate it has reserved the interface.
The first case is perfectly fine, but the issue with the second case is that now dev->driver is semantically overloaded:
The USB core treats it as "dev is reserved for dev->driver" and the driver core treats it as "dev is currently binding or bound to dev->driver", but that's not actually the case yet, since device_bind_driver() hasn't been called yet.
IOW, dev->driver should only be set under the device lock before calling device_bind_driver(), and, in case of failure, should be cleared after device_bind_driver() with the device lock still held.
Besides the reported crash, another implication of this is that all other functions from device_release_driver() are called as well, even though device_bind_driver() was never called before, and there is no guarantee that this does not cause other unexpected side effects already or in the future.
I think one solution could be to add a new claimed field to struct usb_interface to indicate that the interface is reserved for a certain driver and make usb_device_match() reject the device if ever probed otherwise.
Another solution (but that's a bit more work) would be to separate interface registration from interface probing in usb_set_configuration(). Of course that needs help from the driver core as well, but it would also get us rid of the slightly odd situation that a driver may operate a claimed device already, even though it is not yet registered with the driver core.
I'd suggest going for a claimed field in struct usb_interface first to fix the immediate problem and then take it from there.
That said, I wonder if there's more to think about with the usb_driver_claim_interface() / usb_driver_release_interface() API.
After having a brief look it seems that drivers have invented various different approaches to protect against the case where userspace could write the claimed interface's name to:
/sys/bus/usb/drivers/<driver>/unbind
I think this could be much cleaner if the driver core would support "claimed" devices" natively. OTH, there's only ~20 drivers across USB and PnP though, so probably not worth.
Quoted 86 lines · Danilo Krummrich
(Cc: linux-usb)
Quoted 1 line · Nguyen Quang Le Kien
Fixes 94e7b1c5ff20 ("[PATCH] Add a klist to struct device_driver for the devices bound to it.")This is not the correct commit to reference, this commit seems fine.
drivers/base/dd.c static void __device_release_driver(struct device *dev, struct device *parent) · line 1358
Quoted 11 lines
drivers/base/dd.c +2
-1@@ -1354,7 +1354,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)device_unbind_cleanup (dev);device_links_driver_cleanup (dev); -klist_remove (&dev->p->knode_driver); +if (device_is_bound (dev)) +klist_remove (&dev->p->knode_driver);This looks like band-aid for the underlying design tension in the USB core (which we should address instead) and does not belong in the driver core.
It's not visible from the above diff, but with this patch the control flow becomes:
if (dev->driver) { if (device_is_bound(dev)) klist_remove(&dev->p->knode_driver); ... }but
dev->driveralready indicates that the device is bound todev->driverin this context.The reason we "need" this check regardless is that
usb_driver_claim_interface()(ab)usesdev->driverto indicate that a certain USB driver claimed, or rather reserved, this device.There are two cases in
usb_driver_claim_interface():(1) The device to claim is already registered with the driver core, in which case
device_bind_driver(dev)is called anddev->driveris correctly set during the bind attempt.(2) The device to claim was not yet registered with the driver core. This can happen when the USB interface the driver actually binds to is registered (and hence probed) before the additional interface the driver wants to claim is registered. The USB core sets
dev->driverindependent of the bind state to indicate it has reserved the interface.The first case is perfectly fine, but the issue with the second case is that now
dev->driveris semantically overloaded:The USB core treats it as "dev is reserved for
dev->driver" and the driver core treats it as "dev is currently binding or bound todev->driver", but that's not actually the case yet, sincedevice_bind_driver()hasn't been called yet.IOW,
dev->drivershould only be set under the device lock before callingdevice_bind_driver(), and, in case of failure, should be cleared afterdevice_bind_driver()with the device lock still held.Besides the reported crash, another implication of this is that all other functions from
device_release_driver()are called as well, even thoughdevice_bind_driver()was never called before, and there is no guarantee that this does not cause other unexpected side effects already or in the future.I think one solution could be to add a new claimed field to struct
usb_interfaceto indicate that the interface is reserved for a certain driver and makeusb_device_match()reject the device if ever probed otherwise.Another solution (but that's a bit more work) would be to separate interface registration from interface probing in
usb_set_configuration(). Of course that needs help from the driver core as well, but it would also get us rid of the slightly odd situation that a driver may operate a claimed device already, even though it is not yet registered with the driver core.I'd suggest going for a claimed field in struct
usb_interfacefirst to fix the immediate problem and then take it from there.That said, I wonder if there's more to think about with the
usb_driver_claim_interface()/usb_driver_release_interface()API.After having a brief look it seems that drivers have invented various different approaches to protect against the case where userspace could write the claimed interface's name to:
Quoted 5 lines
/sys/bus/usb/drivers/<driver>/unbind
I think this could be much cleaner if the driver core would support "claimed" devices" natively. OTH, there's only ~20 drivers across USB and PnP though, so probably not worth.
I don't object to the idea of adding a "claimed" field to usb_interface.
However, isn't it true that the driver core has always supported the idea of a driver being associated with a device before binding? In particular, __device_attach() specifically checks for dev->driver being already set. If it is, the match and probe steps are skipped.
Are you saying that this code path should be removed as well?
As it is, the driver core does sort of support "claimed devices". Namely, a device is claimed (or probing) if dev->driver is set and device_is_bound(dev) is false.
Alan Stern
Danilo Krummrich
maintainerQuoted 93 lines · Alan Stern
Quoted 86 lines · Danilo Krummrich
(Cc: linux-usb)
Quoted 1 line · Nguyen Quang Le Kien
Fixes 94e7b1c5ff20 ("[PATCH] Add a klist to struct device_driver for the devices bound to it.")This is not the correct commit to reference, this commit seems fine.
drivers/base/dd.c static void __device_release_driver(struct device *dev, struct device *parent) · line 1358
Quoted 11 lines
drivers/base/dd.c +2
-1@@ -1354,7 +1354,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)device_unbind_cleanup (dev);device_links_driver_cleanup (dev); -klist_remove (&dev->p->knode_driver); +if (device_is_bound (dev)) +klist_remove (&dev->p->knode_driver);This looks like band-aid for the underlying design tension in the USB core (which we should address instead) and does not belong in the driver core.
It's not visible from the above diff, but with this patch the control flow becomes:
if (dev->driver) { if (device_is_bound(dev)) klist_remove(&dev->p->knode_driver); ... }but
dev->driveralready indicates that the device is bound todev->driverin this context.The reason we "need" this check regardless is that
usb_driver_claim_interface()(ab)usesdev->driverto indicate that a certain USB driver claimed, or rather reserved, this device.There are two cases in
usb_driver_claim_interface():(1) The device to claim is already registered with the driver core, in which case
device_bind_driver(dev)is called anddev->driveris correctly set during the bind attempt.(2) The device to claim was not yet registered with the driver core. This can happen when the USB interface the driver actually binds to is registered (and hence probed) before the additional interface the driver wants to claim is registered. The USB core sets
dev->driverindependent of the bind state to indicate it has reserved the interface.The first case is perfectly fine, but the issue with the second case is that now
dev->driveris semantically overloaded:The USB core treats it as "dev is reserved for
dev->driver" and the driver core treats it as "dev is currently binding or bound todev->driver", but that's not actually the case yet, sincedevice_bind_driver()hasn't been called yet.IOW,
dev->drivershould only be set under the device lock before callingdevice_bind_driver(), and, in case of failure, should be cleared afterdevice_bind_driver()with the device lock still held.Besides the reported crash, another implication of this is that all other functions from
device_release_driver()are called as well, even thoughdevice_bind_driver()was never called before, and there is no guarantee that this does not cause other unexpected side effects already or in the future.I think one solution could be to add a new claimed field to struct
usb_interfaceto indicate that the interface is reserved for a certain driver and makeusb_device_match()reject the device if ever probed otherwise.Another solution (but that's a bit more work) would be to separate interface registration from interface probing in
usb_set_configuration(). Of course that needs help from the driver core as well, but it would also get us rid of the slightly odd situation that a driver may operate a claimed device already, even though it is not yet registered with the driver core.I'd suggest going for a claimed field in struct
usb_interfacefirst to fix the immediate problem and then take it from there.That said, I wonder if there's more to think about with the
usb_driver_claim_interface()/usb_driver_release_interface()API.After having a brief look it seems that drivers have invented various different approaches to protect against the case where userspace could write the claimed interface's name to:
Quoted 5 lines
/sys/bus/usb/drivers/<driver>/unbind
I think this could be much cleaner if the driver core would support "claimed" devices" natively. OTH, there's only ~20 drivers across USB and PnP though, so probably not worth.
Quoted 6 lines
I don't object to the idea of adding a "claimed" field to
usb_interface.However, isn't it true that the driver core has always supported the idea of a driver being associated with a device before binding? In particular,
__device_attach()specifically checks fordev->driverbeing already set. If it is, the match and probe steps are skipped.
Ah, I also wanted to add a comment about this, but forgot about it, sorry.
This was added ~25 years ago to be able to hardwire a system device to a specific driver, which less than a year after was replaced entirely by something else and later converted back to a bus with proper match() logic. But the dev->driver special case in __device_attach() was never removed.
So, I guess it is fair to say it was always there, but the driver core does not really handle dev->driver being set "randomly" outside of the bind/unbind lifecycle in general. It is expected that it is only set when the driver is actually bound (or binding).
One example is __device_release_driver(), if device_bind_driver() (or really_probe()) wasn't called, we should also not land within the if (dev->driver) conditional of __device_release_driver().
Also note that usb_driver_claim_interface() is the only callsite in the kernel that does set dev->driver without a subsequent device_bind_driver() while holding the device lock.
(Well, actually, after a thorough check, there's w1, which hardwires the w1_slave_driver, where it should actually use a trivial match() callback.)
In general, matching should be done through the match() callback.
Quoted 1 line
Are you saying that this code path should be removed as well?
Yes, I think we should remove it. It's a rather error prone special case that can easily be handled with normal match() logic.
A message that is not in the archive (sent off-list or not yet received): CAEe5be5OjseCMxGQP=QMd1L-muOTDguaay_-21moS1+xRNNNyw@mail.gmail.com
Danilo Krummrich
maintainerQuoted 4 lines · Akihiko Kai
Quoted 2 lines · Danilo Krummrich
usb_driver_claim_interface()is the only callsite in the kernel that does setdev->driverwithout a subsequentdevice_bind_driver().
Quoted 8 lines
Small correction, I think there are a few more.
usb_port(drivers/usb/core/port.c:782) setsdev->driverbeforedevice_register(), andusb_port_driverhas no ->match and no ->probe, so it depends entirely on the__device_attach()dev->driverpath to get bound. ccwgroup (drivers/s390/cio/ccwgroup.c:385) andpata_parport(drivers/ata/pata_parport/pata_parport.c:515) do the same. So that path doesn't look USB-claim-specific, and if we ever want to remove it,usb_portwould need a ->match() first.
Good catch, I think those should be fixed as well.
I had a brief look at the usb_port one and it should be exactly the same case as w1, which I already fixed [1]. Actually, it is even simpler, usb_device_match() can just handle the usb_port_device_type, as the USB core already does for other device types. I can send a patch for this later on.
[1] https://lore.kernel.org/driver-core/[email protected]/
Quoted 10 lines
For the root cause, what about this: in
usb_driver_claim_interface(), when the interface isn't registered yet, just don't setdev->driver-- record the claim on structusb_interfaceinstead. Then, once the interface gets added inusb_set_configuration(), bind it explicitly withdevice_bind_driver(). That skips ->probe, which is exactly what usb_audio's claim-now-bind-later needs, and it also attachesknode_driverso teardown is safe. The__device_attach()path can stay for w1/ccwgroup/pata_parport.Does that sound reasonable?
I'd prefer to get rid of the dev->driver path in __device_attach(), I think there's no reason not to use the common match() path instead.
So, for a fix that also goes into stable trees what you propose sounds reasonable, but eventually we should use the match() infrastructure instead.
Quoted 2 lines · Danilo Krummrich
So, for a fix that also goes into stable trees what you propose sounds reasonable, but eventually we should use the
match()infrastructure instead.
I've implemented the approach you described:
- In usb_driver_claim_interface(), when !device_is_registered(dev), skip setting dev->driver. Instead set two new fields on struct
usb_interface: claimed:1 and claimed_driver.
- In usb_set_configuration(), after device_add() succeeds, check intf->claimed and call device_bind_driver() explicitly. This skips ->probe() and attaches knode_driver to the driver's klist, making teardown safe.
- The __device_attach() dev->driver path in dd.c is left untouched for w1 / ccwgroup / pata_parport.
syzbot confirmed the fix; the reproducer no longer triggers:
Tested-by: [email protected] Patch: https://syzkaller.appspot.com/x/patch.diff?x=12af8b49580000 Dashboard: https://syzkaller.appspot.com/bug?extid=87188222c77c0dbbdb4d
Will send v5 shortly with the syzbot Tested-by added and the subject retitled to "usb: core: ..." since the change is scoped to USB only.
Could I get a Reviewed-by from you?
Thanks,
Kiennql