bulwarkid / virtual-fido

A Virtual FIDO2 USB Device
MIT License
1.19k stars 52 forks source link

Unable to start on Linux #8

Closed jeroenhd closed 1 year ago

jeroenhd commented 1 year ago

I have trouble running the demo on Linux. From what I can tell, this is looks to be some kind of protocol problem.

As instructed, I have commented out the call to usbip.exe and I'm calling the usbip command manually (usbip attach -r 127.0.0.1 -b 2-2 in a separate terminal). I have modprobed vhci-hcd (the usual driver) without issue. This setup has been used for actual USB/IP work before and it worked surprisingly well.

When I run the demo, I get the following stacktrace from virtual-fido:

$ go run main.go start
panic: ERROR: Could not read data - EOF

goroutine 6 [running]:
virtual_fido.checkErr(...)
        /tmp/virtual-fido/virtual_fido/util.go:22
virtual_fido.readBE[...]({0x7625a0, 0xc000014080})
        /tmp/virtual-fido/virtual_fido/util.go:42 +0x159
virtual_fido.(*USBIPServer).handleCommands(0x7625c0?, 0xc000068a10)
        /tmp/virtual-fido/virtual_fido/usbip_server.go:66 +0x6c
virtual_fido.(*USBIPServer).handleConnection(0xc000012df8, 0xc000068a10)
        /tmp/virtual-fido/virtual_fido/usbip_server.go:58 +0x33a
virtual_fido.(*USBIPServer).start(0x69d100?)
        /tmp/virtual-fido/virtual_fido/usbip_server.go:37 +0x138
virtual_fido.Start({0x765ed8?, 0xc0000303c0})
        /tmp/virtual-fido/virtual_fido/virtual_fido.go:9 +0x365
demo.runServer.func1()
        /tmp/virtual-fido/demo/server.go:76 +0x2a
created by demo.runServer
        /tmp/virtual-fido/demo/server.go:75 +0xa5
exit status 2

In the other terminal, the output is as follows:

$ usbip attach -r 127.0.0.1 -b 2-2
usbip: error: import device

The offending part of the code (usbip_server.go:66) seems to be parsing the incoming command:

func (server *USBIPServer) handleCommands(conn *net.Conn) {
    for {
        //fmt.Printf("--------------------------------------------\n\n")
        header := readBE[USBIPMessageHeader](*conn)  // <---- this is the call that leads to a panic
        usbipLogger.Printf("[MESSAGE HEADER] %s\n\n", header)
        if header.Command == USBIP_COMMAND_SUBMIT {
            server.handleCommandSubmit(conn, header)
        } else if header.Command == USBIP_COMMAND_UNLINK {
            server.handleCommandUnlink(conn, header)
        } else {
            panic(fmt.Sprintf("Unsupported Command; %#v", header))
        }
    }
}

I could be misunderstanding the requirements, but as far as I know the protocol should be compatible (enough) with the Windows version should be compatible?

System info: Distribution: Manjaro Linux Go version: go version go1.19 linux/amd64 Kernel version: Linux sue 5.19.7-1-MANJARO usbip version: usbip (usbip-utils 2.0) Git branch: master

cmdli commented 1 year ago

I just tested it on PopOS! and it looks like I was able to reproduce your error if I ran usbip attach -r 127.0.0.1 -b 2-2 but I was able to fix it by running that command with sudo (sudo usbip attach -r 127.0.0.1 -b 2-2). Could you try that and see if that works?

I do realize now that the Linux support is in a sorry state right now compared to Windows, which is especially embarrassing as this was initially developed on Linux. Right now you have to turn off the usbip.exe command, turn on the vhci module, and run things manually to get it running on Linux, which is all things that should just be documented. I'll add those steps to the README in order to help out future people.

jeroenhd commented 1 year ago

Looks like you're right, though the reboot of my machine may also have helped. Thanks for double checking!

I still think the full server crash is something you may want to look into; a misbehaving browser probably shouldn't kill the server.