David Hubbard
3c3c233677
hw/usb/hcd-ohci: Fix #1510, #303: pid not IN or OUT
This changes the ohci validation to not assert if invalid data is fed to the
ohci controller. The poc in https://bugs.launchpad.net/qemu/+bug/1907042 and
migrated to bug #303 does the following to feed it a SETUP pid (valid)
at an EndPt of 1 (invalid - all SETUP pids must be addressed to EndPt 0):
uint32_t MaxPacket = 64;
uint32_t TDFormat = 0;
uint32_t Skip = 0;
uint32_t Speed = 0;
uint32_t Direction = 0; /* #define OHCI_TD_DIR_SETUP 0 */
uint32_t EndPt = 1;
uint32_t FuncAddress = 0;
ed->attr = (MaxPacket << 16) | (TDFormat << 15) | (Skip << 14)
| (Speed << 13) | (Direction << 11) | (EndPt << 7)
| FuncAddress;
ed->tailp = /*TDQTailPntr= */ 0;
ed->headp = ((/*TDQHeadPntr= */ &td[0]) & 0xfffffff0)
| (/* ToggleCarry= */ 0 << 1);
ed->next_ed = (/* NextED= */ 0 & 0xfffffff0)
qemu-fuzz also caught the same issue in #1510. They are both fixed by this
patch.
With a tiny OS[1] that boots and executes the poc the repro shows the issue:
* OS that sends USB requests to a USB mass storage device
but sends a SETUP with EndPt = 1
* qemu 6.2.0 (Debian 1:6.2+dfsg-2ubuntu6.19)
* qemu HEAD (4e66a0854)
* Actual OHCI controller (hardware)
Command line:
qemu-system-x86_64 -m 20 \
-device pci-ohci,id=ohci \
-drive if=none,format=raw,id=d,file=testmbr.raw \
-device usb-storage,bus=ohci.0,drive=d \
--trace "usb_*" --trace "ohci_*" -D qemu.log
Results are:
qemu 6.2.0 | qemu HEAD | actual HW
------------+-----------+----------------
assertion | assertion | sets stall bit
The assertion message is:
> qemu-system-x86_64: ../../hw/usb/core.c:744: usb_ep_get: Assertion `pid == USB_TOKEN_IN || pid == USB_TOKEN_OUT' failed.
> Aborted (core dumped)
Tip: if the flags "-serial pty -serial stdio" are added to the command line
the poc outputs its USB requests like this:
> Free mem 2M ohci port0 conn FS
> setup { 80 6 0 1 0 0 8 0 }
> ED info=80000 { mps=8 en=0 d=0 } tail=c20920
> td0 c20880 nxt=c20960 f2000000 setup cbp=c20900 be=c20907 cbp=0 be=c20907
> td1 c20960 nxt=c20980 f3140000 in cbp=c20908 be=c2090f cbp=0 be=c2090f
> td2 c20980 nxt=c20920 f3080000 out cbp=0 be=0 cbp=0 be=0
> rx { 12 1 0 2 0 0 0 8 }
> setup { 0 5 1 0 0 0 0 0 } tx {}
> ED info=80000 { mps=8 en=0 d=0 } tail=c20880
> td0 c20920 nxt=c20960 f2000000 setup cbp=c20900 be=c20907 cbp=0 be=c20907
> td1 c20960 nxt=c20880 f3100000 in cbp=0 be=0 cbp=0 be=0
> setup { 80 6 0 1 0 0 12 0 }
> ED info=80081 { mps=8 en=0 d=1 } tail=c20960
> td0 c20880 nxt=c209c0 f2000000 setup cbp=c20920 be=c20927
> td1 c209c0 nxt=c209e0 f3140000 in cbp=c20928 be=c20939
> td2 c209e0 nxt=c20960 f3080000 out cbp=0 be=0qemu-system-x86_64: ../../hw/usb/core.c:744: usb_ep_get: Assertion `pid == USB_TOKEN_IN || pid == USB_TOKEN_OUT' failed.
> Aborted (core dumped)
[1] The OS disk image has been emailed to philmd@linaro.org, mjt@tls.msk.ru,
and kraxel@redhat.com:
* testBadSetup.img.xz
* sha256: 045b43f4396de02b149518358bf8025d5ba11091e86458875339fc649e6e5ac6
Signed-off-by: David Hubbard <dmamfmgm@gmail.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[PMM: authorship and signed-off-by tag names fixed up as
per on-list agreement]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2024-05-31 11:26:00 +01:00
..
2024-04-18 11:17:27 +02:00
2024-03-01 08:27:33 +01:00
2023-07-25 17:24:12 +01:00
2023-07-25 17:24:12 +01:00
2023-08-31 19:47:43 +02:00
2023-12-30 07:38:06 +11:00
2020-09-18 14:12:32 -04:00
2021-05-02 17:24:50 +02:00
2021-05-05 15:06:01 +02:00
2021-01-22 14:51:35 +01:00
2021-09-01 06:37:13 +02:00
2023-10-06 13:27:48 +02:00
2022-01-13 10:22:37 +01:00
2024-04-01 19:47:40 +03:00
2023-12-30 07:38:06 +11:00
2023-12-30 07:38:06 +11:00
2023-12-30 07:38:06 +11:00
2024-05-09 00:07:21 +02:00
2021-03-15 17:00:58 +01:00
2023-12-30 07:38:06 +11:00
2023-02-08 07:28:05 +01:00
2024-04-16 11:50:52 +01:00
2023-12-30 07:38:06 +11:00
2023-12-30 07:38:06 +11:00
2022-11-08 11:13:48 +01:00
2024-04-25 10:21:06 +01:00
2022-05-11 16:49:06 +02:00
2023-12-30 07:38:06 +11:00
2024-02-20 20:34:21 +03:00
2024-02-20 20:34:21 +03:00
2024-02-20 20:34:21 +03:00
2024-02-20 20:34:21 +03:00
2022-11-08 11:13:48 +01:00
2023-12-30 07:38:06 +11:00
2024-02-27 09:37:25 +01:00
2024-05-31 11:26:00 +01:00
2023-02-27 22:29:02 +01:00
2024-02-20 20:34:21 +03:00
2024-02-20 20:34:21 +03:00
2023-02-27 22:29:02 +01:00
2023-12-30 07:38:06 +11:00
2023-01-08 01:54:22 -05:00
2023-12-30 07:38:06 +11:00
2020-10-21 11:36:19 +02:00
2023-12-30 07:38:06 +11:00
2021-05-28 09:10:20 +02:00
2023-12-30 07:38:06 +11:00
2013-02-19 12:30:05 +01:00
2023-12-30 07:38:06 +11:00
2024-02-27 09:37:25 +01:00
2021-12-30 17:16:32 +01:00
2024-04-18 11:17:27 +02:00
2021-02-17 14:29:12 +01:00
2021-09-01 06:37:13 +02:00
2022-11-08 11:13:48 +01:00
2020-03-16 23:02:25 +01:00
2023-08-31 19:47:43 +02:00
2024-01-05 13:35:25 +00:00
2024-05-31 11:26:00 +01:00
2020-08-21 06:18:24 -04:00
2020-09-18 14:12:32 -04:00
2021-09-01 06:37:13 +02:00
2023-12-30 07:38:06 +11:00
2023-12-30 07:38:06 +11:00
2023-02-27 22:29:02 +01:00
2023-11-28 14:26:37 +01:00
2024-05-10 15:45:15 +02:00
2021-05-02 17:24:50 +02:00
2024-04-25 10:21:06 +01:00