Description
Affected: Firmware targeting EFI < 1.10 and UEFI drivers that do not use BootServices.open_protocol
and BootServices.close_protocol
.
Prior to EFI 1.10, the EFI_BOOT_SERVICES.UninstallProtocolInterface
function lacks the safety checks that were added in 1.10. It simply removes a protocol from a handle, and if the last protocol is removed from a handle, that handle is freed by firmware and no longer valid. It is entirely up to the caller to ensure that there are no remaining references to that protocol and potentially that handle. Post-1.10, the firmware is able to see any consumers that have used open_protocol
or close_protocol
and attempt to disconnect those consumers before removing the protocol, failing if it is unable to do so.
As far as I can tell, the firmware does not have a direct mechanism to let you know that a handle has been removed and is invalid. I've got a couple ideas about how to go about this:
- Ensure the handle is valid at every callsite, potentially using
locate_handle
, though that requires a protocol to search for. There isn't another UEFI function that would be suitable, as the rest of the protocol-related functions need to be passed a valid handle. - Remove
Copy
andClone
fromHandle
, add anunsafe_clone
, and note the unsafety, trusting the caller.
This feels like a can of worms; some input before I start working on an implementation would be appreciated. :)