Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Odd issue sharing a USB device between Windows and WSL2 #458

Closed
thijsputman opened this issue Oct 3, 2022 · 18 comments
Closed

Odd issue sharing a USB device between Windows and WSL2 #458

thijsputman opened this issue Oct 3, 2022 · 18 comments

Comments

@thijsputman
Copy link

Using usbipd-win 2.4.0 to connect a Yubikey into WSL2.

Next to using the Yubikey in WSL2, I'm running a gpg-agent on the Windows-side to be able to use the Yubikey for SSH operations from Windows too. I'm attaching and detaching the Yubikey from WSL2 as needed in order to use it in Windows.

This work like a charm, with one very odd caveat:

If upon booting the system I use the Yubikey in Windows first (through gpg-agent / scdaemon), I'm subsequently unable to attach it to WSL2 until I reboot the system (details below). If instead I first attach it into WSL2 I can seemingly keep detaching and attaching it at will (and using it in Windows) without any further issue...

In the first (failing) case, the following is shown on the WSL2-side:

$ sudo usbip attach -r 192.168.xxx.xxx -b 3-2
usbip: error: Attach Request for 3-2 failed - Device in error state

The log produced by usbipd on the Windows-side (captured in 2.3.0; the problem persists in 2.4.0 though) appears to indicate the device is somehow busy?

dbug: Usbipd.Server[1000]
      new connection from 192.168.xxx.xxx
dbug: Usbipd.ConnectedClient[1000]
      Received opcode: OP_REQ_IMPORT
fail: Usbipd.ConnectedClient[3]
      An exception occurred while communicating with the client:
      System.IO.FileNotFoundException: Unable to find the specified file.
         at Usbipd.ConfigurationManager.GetVBoxDevice(BusId ) in D:\a\usbipd-win\usbipd-win\Usbipd\ConfigurationManager.cs:line 292
         at Usbipd.VBoxUsb.ClaimDeviceOnce(BusId ) in D:\a\usbipd-win\usbipd-win\Usbipd\VBoxUsb.cs:line 66
         at Usbipd.VBoxUsb.ClaimDevice(BusId ) in D:\a\usbipd-win\usbipd-win\Usbipd\VBoxUsb.cs:line 76
         at Usbipd.VBoxUsb.ClaimDevice(BusId ) in D:\a\usbipd-win\usbipd-win\Usbipd\VBoxUsb.cs:line 82
         at Usbipd.ConnectedClient.HandleRequestImportAsync(CancellationToken ) in D:\a\usbipd-win\usbipd-win\Usbipd\ConnectedClient.cs:line 158
dbug: Usbipd.Server[1000]
      connection closed

What I've tried to resolve the issue:

  • Physically unplug/plug the Yubikey
  • Unbind/bind the Yubikey using usbipd on the Windows-side
  • Using another USB port (and binding that one)
  • Using another Yubikey of the same make and model (in both of the aforementioned ports)
  • Killing gpg-agent and scdaemon on the Windows-side
  • Restarting the usbipd service

None of these actions appear to resolve the issue. The only solution (thus far) appears to be to reboot Windows and ensure I first attach the device to WSL2 before attempting to use it from Windows....

@dorssel
Copy link
Owner

dorssel commented Oct 3, 2022

That is weird indeed.

It looks like (not sure, though), that VBoxUsbMon is not able to replace the hardwareId/driver. So, the device is present (with the original driver), then usbipd instructs VBoxUsbMon to grab it, VBoxUsbMon reports success, but then the device (with the replaced driver) cannot be found. Maybe that is because the driver was not changed by VBoxUsbMon after all, or maybe the device itself is indeed in some kind of error state due to the driver swap.

Can you try the following:

  • open Windows device manager
  • set it to "View devices by connection"
  • find the device, and make sure it remains in view for the remainder of this test
  • wsl attach such that it fails (i.e. reach the error state)
  • while doing that, check the state of the device in device manager
  • does it show any changes? in device name? in error state ("yellow bang")? is this very brief and then recovers, or does the change persist?
  • afterwards, check the Windows EventLog to see if VBoxUsbMon reported any errors

@thijsputman
Copy link
Author

Reproduction of the issue appears less reliable than I initially assumed — just restarted my machine and can't seem to reproduce it for now... 🫤

Anyway, I'm using this setup on a daily basis so it'll probably pop up again in the near future. If it does, I'll go through the above instructions. Thanks for the prompt response!

For now, the only (potentially) relevant observation is that the Yubikey initially gets identified as a NIST SP 800-73 [PIV] smart card in Device Manager; after an initial attach/detach to WSL2 it comes back as an Unknown Smart Card (which apparently is a valid driver — there's no yellow exclamation mark or anything like that).

@dorssel
Copy link
Owner

dorssel commented Oct 5, 2022

What is the output from usbipd list for these different identifiers? (NIST ... vs. Unknown). Is the actual hardwareID (VID:PID) different?

@thijsputman
Copy link
Author

They're identical (1050:0407).

Good to note that the actual device listed is a Microsoft Usbccid Smartcard Reader (WUDF) (by connection the parent device of the smart card device). It has the VID and PID of the Yubikey so I'm guessing it's the actual Yubikey. The smart card device appears to be some kind of software component (provided by the ScFilter driver) — I'm guessing it's unrelated to my problem...

@thijsputman
Copy link
Author

Well... The issue does not appear to be related to usbipd-win.

Instead, it seems that Windows occasionally doesn't load the Yubikey smart card driver properly. When encountering the problem described above, the smart card functionalities don't work on the Windows-side either (hadn't actually tested that). The entire NIST SP 800-73 [PIV] / Unknown Smart Card device never appears in device manager when inserting the Yubikey in that situation...

I'm guessing VBoxUsbMon simply trips over the underlying issue on the Windows-side (whatever that may be; still trying to work that one out).

@thijsputman thijsputman closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2022
@thijsputman
Copy link
Author

Okay — spoke too soon, the saga might continue...

I've installed the Yubikey Smart card Minidriver in Windows, replacing the generic Microsoft driver for the smart card with a driver provided by Yubico.

Now the problem only occurs when using usbipd. On the Windows-side, the Yubikey recovers from the error state after unplugging and plugging it back in (it's fully usable again on the Windows-side after that). Repeated attempts at attaching the device to WSL all result in the same error: Attach Request for 3-2 failed - Device in error state.

This device shows up in device manager after usbip on WSL generates the error:

image

These are the only related errors and warnings that show up in Event Viewer (repeated for every attempt at attaching the device):

image

With these messages:

The driver \Driver\VBoxUSB failed to load for the device USB\Vid_80EE&Pid_CAFE\6&1a565baf&0&2.
Metadata staging failed, result=0x80072EFD for container '{00000000-0000-0000-FFFF-FFFFFFFFFFFF}'
Metadata staging failed, result=0x80072EFD for container '{F824E50E-D258-5D12-AE08-73B9A1D7F224}'
Metadata staging failed, result=0x80004005 for container '{F824E50E-D258-5D12-AE08-73B9A1D7F224}'

Furthermore, one sort of related "information" event shows up:

The description for Event ID 26 from source Application Popup cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event: 

\SystemRoot\System32\Drivers\VBoxUSB.sys failed to load

The message resource is present but the message was not found in the message table

image

@thijsputman thijsputman reopened this Oct 12, 2022
@dorssel
Copy link
Owner

dorssel commented Oct 25, 2022

Can you try version 2.4.1?
It fixes some Authenticode issues with the installer signatures. It looks like in your case Windows does not trust the VBoxUSB driver, which seems to be Authenticode related. I thought the differences between 2.4.0 and 2.4.1 would not have any effect once you make it passed the installer, but maybe I was wrong...

@thijsputman
Copy link
Author

Just installed it — will keep you posted should anything change (or not change 😉)...

@dorssel
Copy link
Owner

dorssel commented Dec 17, 2022

@thijsputman
Has this issue been resolved?

@thijsputman
Copy link
Author

It still happens occasionally.

I haven't been able to determine any kind of (relevant) pattern to it. For now it's infrequent enough (and reliable resolved by a reboot) to just be a minor nuisance...

@dorssel
Copy link
Owner

dorssel commented Dec 22, 2022

Still interesting... Are you perhaps running a third party virus scanner?

@thijsputman
Copy link
Author

Nope.

Only thing I can think of is that I'm running a relatively "old" Windows installation; about 2,5-years since it was freshly installed.

@supleed2
Copy link

supleed2 commented Mar 11, 2023

I've been having a similar issue for a while now but never discovered this particular issue before. It seems to have the same symptoms. Powershell looks like this:

> usbipd wsl attach -b 1-1
usbipd: info: Using default WSL distribution 'Ubuntu'; specify the '--distribution' option to select a different one.
usbip: error: Attach Request for 1-1 failed - Device in error state

usbipd: error: Failed to attach device with busid '1-1'.

Looking at Device Manager, the device now shows up as something called VirtualBox USB with VID:PID 80EE:CAFE. This seems to happen regardless of which device I use (USB Drive, An emulated USB Device on a development board) but only on one windows machine. The USB devices work when I try to connect to them from the same wsl distro, but running usbipd on another windows machine on the same LAN network.

Device Manager Screenshots

image
image

Event viewer for `usbipd-win` shows a similar error as above:
Category: Usbipd.ConnectedClient
EventId: 3

An exception occurred while communicating with the client:

Exception: 
System.IO.FileNotFoundException: Unable to find the specified file.
   at Usbipd.ConfigurationManager.GetVBoxDevice(BusId ) in D:\a\usbipd-win\usbipd-win\Usbipd\ConfigurationManager.cs:line 289
   at Usbipd.VBoxUsb.ClaimDeviceOnce(BusId ) in D:\a\usbipd-win\usbipd-win\Usbipd\VBoxUsb.cs:line 66
   at Usbipd.VBoxUsb.ClaimDevice(BusId ) in D:\a\usbipd-win\usbipd-win\Usbipd\VBoxUsb.cs:line 76
   at Usbipd.VBoxUsb.ClaimDevice(BusId ) in D:\a\usbipd-win\usbipd-win\Usbipd\VBoxUsb.cs:line 82
   at Usbipd.ConnectedClient.HandleRequestImportAsync(CancellationToken ) in D:\a\usbipd-win\usbipd-win\Usbipd\ConnectedClient.cs:line 272
   at Usbipd.ConnectedClient.HandleRequestImportAsync(CancellationToken ) in D:\a\usbipd-win\usbipd-win\Usbipd\ConnectedClient.cs:line 272
   at Usbipd.ConnectedClient.RunAsync(CancellationToken ) in D:\a\usbipd-win\usbipd-win\Usbipd\ConnectedClient.cs:line 74
I have the same Kernel-PnP warning:
The driver \Driver\VBoxUSB failed to load for the device USB\Vid_80EE&Pid_CAFE\D9116FBF.

But I don't see the DeviceSetupManager Errors.

Is there anything I can try / get that might help figure this out? I'm able to work by copying files over to Windows first but it's still clunky. When usbipd-win worked, it worked great :)

Edit: Just trying to cover all questions previously asked, I'm not using anything other than Windows Defender, and winver reports Version 22H2 (OS Build 22621.1344)

@dorssel
Copy link
Owner

dorssel commented Mar 12, 2023

@supleed2
Obviously, this has to do with driver loading. usbipd-win installs the same drivers (binary identical) as VirtualBox. There is a "generic driver" install for normal attach (PnP) during installation, and the driver is installed explicitly when using --force. If you are not having a full installation of VirtualBox (which is known to clash with usbipd-win if the driver versions don't match), first try to repair or reinstall usbipd-win. For good measure, reboot after the (re-)install, even if the installer does not think it is necessary.

If that does not work ... maybe your issue is related to https://borncity.com/win/2018/07/06/windows-10-v1803-hcvi-causes-driver-error-code-39/. Try with core isolation off.

@supleed2
Copy link

Thank you for the help! I managed to get it working, now I can get back to being productive ❤️

I had installed VirtualBox to test yesterday and it wasn't able to pass through the usb device either, so I had uninstalled it immediately.

Noting the steps I took here incase it helps in the future:

  • Uninstall the device in Device Manager (including the option to remove the driver if available)
  • Remove usbipd-win via winget uninstall --purge dorssel.usbipd-win and then reboot (Previously I had just uninstalled via control panel)
  • Install usbipd-win via winget install dorssel.usbipd-win and then reboot again
  • Connect device and use the force option to install the right driver, then bind normally to allow the device to be used in windows until attached (In admin powershell): usbipd bind -f -b <busid>, then usbipd bind -b <busid>

@dorssel
Copy link
Owner

dorssel commented Jun 2, 2023

@thijsputman
Does this issue still happen with 3.0.0?

@thijsputman
Copy link
Author

Haven't seen the issue occur since I installed 3.0.0 — prior to that it'd only been happening occasionally (once or twice per month), so maybe it still will...

Anyway, we can probably conclude it's an esoteric problem specific to my hardware/drivers; feel free to close the issue.

@dorssel dorssel closed this as completed Jun 2, 2023
@RT-Tap
Copy link

RT-Tap commented Aug 14, 2023

Hey I'm having this exact issue. I tried and successfully passed the yubikey through for the firs time a couple days ago , everyhting worked fine including attaching then detaching multiple times, then a windows update forced a reboot (I cant describe in words how much I hate it and how much time ive spent trying to prevent the reboot but I digress) and ever since the reboot I can't connect again, I just get the same VirtualBox USB error.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants