Re: [PATCH] usbip: vhci_hcd: move sysfs attribute setup into probe/remove

From: Greg KH

Date: Sat Aug 15 2026 - 11:32:30 EST


On Sat, Aug 15, 2026 at 08:04:27PM +0530, Deepanshu Kartikey wrote:
>
> The vhci sysfs attribute group is created in vhci_start() and removed in
> vhci_stop(), guarded by usb_hcd_is_primary_hcd(). Since vhci_start() and
> vhci_stop() run from usb_add_hcd()/usb_remove_hcd(), which are each called
> twice, the attach attribute is live while only one of the two hcds exists:
> it is created during the first usb_add_hcd() before vhci_hcd_ss is set,
> and it survives the first usb_put_hcd() during removal. A concurrent write
> to attach can therefore reach a NULL or freed vhci_hcd_ss.
>
> Create the group at the end of vhci_hcd_probe(), after both hcds are
> added, and remove it at the start of vhci_hcd_remove(), before either
> reference is dropped. sysfs_remove_group() drains in-flight store
> callbacks, so no writer can be inside attach_store() once it returns.

If you are going to move the creation, please do so in a race-free way
and properly make the driver core control this by setting these up as
default attributes.

A huge hint that something is wrong in a driver is when it calls a
sysfs_*() function, like this. That's not ok, so either it is doing
something out-of-the-ordinary and it requires it, or it's broken.

WHat has recently changed to make this start to fail now to require this
change?

thanks,

greg k-h