-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error redirection a usb device to a qemu virtual machine #50
Comments
Thanks for the report! Re Looks like the issue with running the examples is that I'm not sure whether it makes to add reset handling to existing examples or add another one to demonstrate proper reset handling.
For now, could you share the command you use to run QEMU to enable USB redirection? |
The process of working in steps is described in this article: |
I pushed a few changes to the Re the link you shared: interesting! Could you explain what is the purpose of redirecting a virtual USB device emulated with Raw Gadget on host into QEMU guest? You could emulate a device within the QEMU guest directly. Or do you want to use a Raw Gadget-based proxy to MitM a real device while redirecting its traffic to the QEMU guest? |
The module and the keyboard example (sleep(1) -> sleep(10) ) are compiled from the dev branch. device:
or
or
usbredir:
qemu:
usbdump (usage usbmon):
The initial goal is fuzzing the usbredir library.
In the process of exploring the capabilities of raw_gadget and usb_proxy, there was also such an idea that at the beginning of the session, use redirection of a regular device and use a standard handler, and then send a packet with mutated data and monitor the reaction of qemu entities. |
Compared the logs with redirecting a real keyboard At the time of the user's invitation, usbredir tries to execute real:
emulator:
|
Pushed another change to |
Thanks! Now keyboard redirection works fine both with qemu and via virt-manager. |
Awesome! So Raw Gadget works with usbredir, the only thing is that the emulation code needs to handle the reset event properly. Let's keep this issue open as a reminder for me to:
|
Just noticed the discussion here :) Probably not related to the issue, but I noticed that you are discussing about the reset. From my previous experience(I can't recall everything now, it was like 3-4 years ago), some USB devices behave very weird if they receive the reset event for the second time. I was using https://github.com/usb-tools/USBProxy-legacy to do proxy, and I called libusb_reset_device() before expose the USB device to Host, but then Host send another reset event(which is a normal behaviour if the USB device is plugged to Host directly) to the device, which cause the device hang and not functioning In the end, I added a config/variable to decide whether I shoud call libusb_reset_device() before expose the device to Host or not |
@AristoChen Yeah, I wound't be surprised if some USB devices break on multiple resets :) Most of them should handle them though. So I would say resetting the device if the host asks for it should be the default behavior of a USB proxy. But yeah, this is not related to handling the reset event in Raw Gadget. |
Sent the patches upstream and implemented usb-proxy support for resent handling (didn't send a PR yet). |
Raw Gadget patches are now in Closing this issue as resolved. Handing of reset in USB proxy is tracked in AristoChen/usb-proxy#9. |
The error is reproduced for both the master and dev branches, and for the module from the dev branch it is not possible to run the printer and keyboard example application, but a proxy device is successfully created using the usb_proxy application.
master:
$ sudo ./keyboard
...
ioctl(USB_RAW_IOCTL_EP_WRITE): Cannot send after transport endpoint shutdown
$ sudo ./printer
...
ioctl(USB_RAW_IOCTL_EP_READ): Cannot send after transport endpoint shutdown
ioctl(USB_RAW_IOCTL_EP_WRITE): Cannot send after transport endpoint shutdown
usbredir (example printer):
$ sudo usbredirect --device 0525:a4a8 --as 127.0.0.1:4000 --verbose 5
(usbredirect:12580): usbredirect-ERROR **: 20:22:46.937: usbredirhost: error resetting device: LIBUSB_ERROR_NOT_FOUND
Ловушка трассировки/останова
=====================================================================
dev:
$ sudo ./keyboard
event: connect, length: 0
ep #0:
name: ep1in-bulk
addr: 1
type: ___ blk ___
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #1:
name: ep2out-bulk
addr: 2
type: ___ blk ___
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #2:
name: ep5in-int
addr: 5
type: ___ ___ int
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #3:
name: ep6in-bulk
addr: 6
type: ___ blk ___
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #4:
name: ep7out-bulk
addr: 7
type: ___ blk ___
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #5:
name: ep10in-int
addr: 10
type: ___ ___ int
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #6:
name: ep11in-bulk
addr: 11
type: ___ blk ___
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #7:
name: ep12out-bulk
addr: 12
type: ___ blk ___
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #8:
name: ep15in-int
addr: 15
type: ___ ___ int
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #9:
name: ep1out-bulk
addr: 1
type: ___ blk ___
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #10:
name: ep2in-bulk
addr: 2
type: ___ blk ___
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #11:
name: ep-aout
addr: 255
type: ___ blk int
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #12:
name: ep-bin
addr: 255
type: ___ blk int
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #13:
name: ep-cout
addr: 255
type: ___ blk int
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #14:
name: ep-dout
addr: 255
type: ___ blk int
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #15:
name: ep-ein
addr: 255
type: ___ blk int
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #16:
name: ep-fout
addr: 255
type: ___ blk int
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #17:
name: ep-gin
addr: 255
type: ___ blk int
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #18:
name: ep-hout
addr: 255
type: ___ blk int
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #19:
name: ep-iout
addr: 255
type: ___ blk int
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #20:
name: ep-jin
addr: 255
type: ___ blk int
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #21:
name: ep-kout
addr: 255
type: ___ blk int
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #22:
name: ep-lin
addr: 255
type: ___ blk int
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #23:
name: ep-mout
addr: 255
type: ___ blk int
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
int_in: addr = 5
fail: unknown event
$ sudo ./printer
event: connect, length: 0
ep #0:
name: ep1in-bulk
addr: 1
type: ___ blk ___
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #1:
name: ep2out-bulk
addr: 2
type: ___ blk ___
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #2:
name: ep5in-int
addr: 5
type: ___ ___ int
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #3:
name: ep6in-bulk
addr: 6
type: ___ blk ___
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #4:
name: ep7out-bulk
addr: 7
type: ___ blk ___
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #5:
name: ep10in-int
addr: 10
type: ___ ___ int
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #6:
name: ep11in-bulk
addr: 11
type: ___ blk ___
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #7:
name: ep12out-bulk
addr: 12
type: ___ blk ___
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #8:
name: ep15in-int
addr: 15
type: ___ ___ int
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #9:
name: ep1out-bulk
addr: 1
type: ___ blk ___
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #10:
name: ep2in-bulk
addr: 2
type: ___ blk ___
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #11:
name: ep-aout
addr: 255
type: ___ blk int
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #12:
name: ep-bin
addr: 255
type: ___ blk int
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #13:
name: ep-cout
addr: 255
type: ___ blk int
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #14:
name: ep-dout
addr: 255
type: ___ blk int
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #15:
name: ep-ein
addr: 255
type: ___ blk int
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #16:
name: ep-fout
addr: 255
type: ___ blk int
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #17:
name: ep-gin
addr: 255
type: ___ blk int
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #18:
name: ep-hout
addr: 255
type: ___ blk int
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #19:
name: ep-iout
addr: 255
type: ___ blk int
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #20:
name: ep-jin
addr: 255
type: ___ blk int
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #21:
name: ep-kout
addr: 255
type: ___ blk int
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
ep #22:
name: ep-lin
addr: 255
type: ___ blk int
dir : in ___
maxpacket_limit: 65535
max_streams: 16
ep #23:
name: ep-mout
addr: 255
type: ___ blk int
dir : ___ out
maxpacket_limit: 65535
max_streams: 16
bulk_out: addr = 2
bulk_in: addr = 1
fail: unknown event
usb-proxy:
$ lsusb
...
Bus 002 Device 004: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
...
$ sudo ./usb-proxy --vendor_id=0bda --product_id=0129
...
ep0: transferred 0 bytes (out)
EP1(bulk_out): read 16 bytes from host
EP82(bulk_in): wrote 4 bytes to host
EP1(bulk_out): read 16 bytes from host
EP82(bulk_in): wrote 4 bytes to host
EP1(bulk_out): read 16 bytes from host
EP82(bulk_in): wrote 4 bytes to host
EP1(bulk_out): read 24 bytes from host
EP1(bulk_out): read 32 bytes from host
EP1(bulk_out): read 12 bytes from host
EP1(bulk_out): read 24 bytes from host
new proxy-usb device:
$ lsusb
Bus 001 Device 003: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
...
redir with virt-manager:
(continue) $ sudo ./usb-proxy --vendor_id=0bda --product_id=0129
...
ioctl(USB_RAW_IOCTL_EP_READ): Cannot send after transport endpoint shutdown
ioctl(USB_RAW_IOCTL_EP_WRITE): Cannot send after transport endpoint shutdown
The text was updated successfully, but these errors were encountered: