summaryrefslogtreecommitdiffstats
path: root/src/interface/efi/efi_usb.c
Commit message (Collapse)AuthorAgeFilesLines
* [build] Mark known reviewed files as permitted for UEFI Secure BootMichael Brown2026-01-141-0/+1
| | | | | | | | | Some past security reviews carried out for UEFI Secure Boot signing submissions have covered specific drivers or functional areas of iPXE. Mark all of the files comprising these areas as permitted for UEFI Secure Boot. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [efi] Drop to external TPL for calls to ConnectController()Michael Brown2025-07-141-3/+2Star
| | | | | | | | | | | | | | | There is nothing in the current versions of the UEFI specification that limits the TPL at which we may call ConnectController() or DisconnectController(). However, at least some platforms (observed with a Lenovo ThinkPad T14s Gen 5) will occasionally and unpredictably lock up before returning from ConnectController() if called at a TPL higher than TPL_APPLICATION. Work around whatever defect is present on these systems by dropping to the current external TPL for all calls to ConnectController() or DisconnectController(). Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [efi] Leave asynchronous USB endpoints open until device is removedMichael Brown2021-01-031-11/+13
| | | | | | | | | | | | | | | | | | | | Some UEFI device drivers will react to an asynchronous USB transfer failure by dubiously terminating the scheduled transfer from within the completion handler. We already have code from commit fbb776f ("[efi] Leave USB endpoint descriptors in existence until device is removed") that avoids freeing memory in this situation, in order to avoid use-after-free bugs. This is not sufficient to avoid potential problems, since with an xHCI controller the act of closing the endpoint requires issuing a command and awaiting completion via the event ring, which may in turn dispatch further USB transfer completion events. Avoid these problems by leaving the USB endpoint open (but with the refill timer stopped) until the device is finally removed, as is already done for control and bulk transfers. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [efi] Allow EFI_USB_IO_PROTOCOL interfaces to be nullified and leakedMichael Brown2020-12-171-9/+39
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [efi] Avoid dropping below TPL as at entry to iPXEMichael Brown2020-11-201-20/+16Star
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | iPXE will currently drop to TPL_APPLICATION whenever the current system time is obtained via currticks(), since the system time mechanism relies on a timer that can fire only when the TPL is below TPL_CALLBACK. This can cause unexpected behaviour if the system time is obtained in the middle of an API call into iPXE by external code. For example, MnpDxe sets up a 10ms periodic timer running at TPL_CALLBACK to poll the underling EFI_SIMPLE_NETWORK_PROTOCOL device for received packets. If the resulting poll within iPXE happens to hit a code path that requires obtaining the current system time (e.g. due to reception of an STP packet, which affects iPXE's blocked link timer), then iPXE will end up temporarily dropping to TPL_APPLICATION. This can potentially result in retriggering the MnpDxe periodic timer, causing code to be unexpectedly re-entered. Fix by recording the external TPL at any entry point into iPXE and dropping only as far as this external TPL, rather than dropping unconditionally to TPL_APPLICATION. The side effect of this change is that iPXE's view of the current system time will be frozen for the duration of any API calls made into iPXE by external code at TPL_CALLBACK or above. Since any such external code is already responsible for allowing execution at TPL_APPLICATION to occur, then this should not cause a problem in practice. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [efi] Split efi_usb_path() out to a separate functionMichael Brown2020-10-161-50/+24Star
| | | | | | | Provide efi_usb_path() as a standalone function, to allow for reuse by the USB mass storage driver. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [efi] Split device path functions out to efi_path.cMichael Brown2020-10-161-2/+2
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [usb] Move usbio driver to end of USB driver listMichael Brown2020-10-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | iPXE will often have multiple drivers available for a USB device. For example: some USB network devices will support both RNDIS and CDC-ECM, and any device may be consumed by the fallback "usbio" driver under UEFI in order to expose an EFI_USB_IO_PROTOCOL instance. The driver scoring mechanism is used to select a device configuration based on the availability of drivers for the interfaces exposed in each configuration. For the case of RNDIS versus CDC-ECM, this mechanism will always produce the correct result since RNDIS and CDC-ECM will not exist within the same configuration and so each configuration will receive a score based on the relevant driver. This guarantee does not hold for the "usbio" driver, which will match against any device. It is a surprising coincidence that the "usbio" driver seems to usually end up at the tail end of the USB drivers list, thereby resulting in the expected behaviour. Guarantee the expected behaviour by explicitly placing the "usbio" driver at the end of the USB drivers list. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [efi] Fix reporting of USB supported languages arrayMichael Brown2020-10-021-10/+15
| | | | | | | The length as returned by UsbGetSupportedLanguages() should not include the length of the descriptor header itself. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [efi] Avoid integer underflow on malformed USB string descriptorsMichael Brown2020-10-021-0/+7
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [efi] Disconnect controllers before uninstalling EFI_USB_IO_PROTOCOLMichael Brown2020-09-291-0/+6
| | | | | | | | | | | | | | | | | | | | The call to UninstallMultipleProtocolInterfaces() will implicitly disconnect any relevant controllers, and there is no specified requirement to explicitly call DisconnectController() prior to callling UninstallMultipleProtocolInterfaces(). However, some UEFI implementations (observed with the USB keyboard driver on a Microsoft Surface Go) will fail to implicitly disconnect the controller and will consequently fail to uninstall the protocols. The net effect is that unplugging and replugging a USB keyboard may leave the keyboard in a non-functional state. Work around these broken UEFI implementations by including an unnecessary call to DisconnectController() before the call to UninstallMultipleProtocolInterfaces(). Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [efi] Report any USB errors as EFI_USB_ERR_SYSTEMMichael Brown2020-09-291-3/+2Star
| | | | | | | | | | | | | | | | | | Some UEFI USB drivers (e.g. the UsbKbDxe driver in EDK2) will react to a reported EFI_USB_ERR_STALL by attempting to clear the endpoint halt. This is redundant with iPXE's EFI_USB_IO_PROTOCOL implementation, since endpoint stalls are cleared automatically by the USB core as needed. The UEFI USB driver's attempt to clear the endpoint halt can introduce an unwanted 5 second delay per endpoint if the USB error was the result of a device being physically removed, since the control transfer will always time out. Fix by reporting all USB errors as EFI_USB_ERR_SYSTEM instead of EFI_USB_ERR_STALL. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [efi] Leave USB endpoint descriptors in existence until device is removedMichael Brown2020-09-291-28/+80
| | | | | | | | | | | | | | | | | | | Some UEFI USB drivers (observed with the keyboard driver on a Microsoft Surface Go) will react to an asynchronous USB transfer failure by terminating the transfer from within the completion handler. This closes the USB endpoint and, in the current implementation, frees the containing structure. This can lead to use-after-free bugs after the UEFI USB driver's completion handler returns, since the calling code in iPXE expects that a completion handler will not perform a control-flow action such as terminating the transfer. Fix by leaving the USB endpoint structure allocated until the device is finally removed, as is already done (as an optimisation) for control and bulk transfers. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [efi] Match EDK2 numbering for USB portsMichael Brown2020-08-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The various USB specifications all use one-based numbering for ports. This scheme is applied consistently across the various relevant specifications, covering both port numbers that appear on the wire (i.e. downstream hub port numbers) and port numbers that exist only logically (i.e. root hub port numbers). The UEFI specification is ambiguous about the port numbers as used for the ParentPortNumber field within a USB_DEVICE_PATH structure. As of UEFI specification version 2.8 errata B: - section 10.3.4.5 just states "USB Parent Port Number" with no indication of being zero-based or one-based - section 17.1.1 notes that for the EFI_USB2_HC_PROTOCOL, references to PortNumber parameters are zero-based for root hub ports - section 17.1.1 also mentions a TranslatorPortNumber used by EFI_USB2_HC_PROTOCOL, with no indication of being zero-based or one-based - there are no other mentions of USB port numbering schemes. Experimentation and inspection of the EDK2 codebase reveals that at least the EDK2 reference implementation will use zero-based numbering for both root and non-root hub ports when populating a USB_DEVICE_PATH structure (though will inconsistently use one-based numbering for the TranslatorPortNumber parameter). Use zero-based numbering for both root and non-root hub ports when constructing a USB_DEVICE_PATH in order to match the behaviour of the EDK2 implementation. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [efi] Raise TPL within EFI_USB_IO_PROTOCOL entry pointsMichael Brown2018-02-201-6/+41
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [efi] Run at TPL_CALLBACK to protect against UEFI timersMichael Brown2018-02-201-46/+2Star
| | | | | | | | | | | | | | | | | | | As noted in the comments, UEFI manages to combines the all of the worst aspects of both a polling design (inefficiency and inability to sleep until something interesting happens) and of an interrupt-driven design (the complexity of code that could be preempted at any time, thanks to UEFI timers). This causes problems in particular for UEFI USB keyboards: the keyboard driver calls UsbAsyncInterruptTransfer() to set up a periodic timer which is used to poll the USB bus. This poll may interrupt a critical section within iPXE, typically resulting in list corruption and either a hang or reboot. Work around this problem by mirroring the BIOS design, in which we run with interrupts disabled almost all of the time. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [usb] Allow USB endpoints to specify a reserved header length for refillsMichael Brown2016-01-191-1/+1
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [efi] Expose unused USB devices via EFI_USB_IO_PROTOCOLMichael Brown2015-09-141-0/+1305
Allow the UEFI platform firmware to provide drivers for unrecognised devices, by exposing our own implementation of EFI_USB_IO_PROTOCOL. Signed-off-by: Michael Brown <mcb30@ipxe.org>