Hi Peter,
If the protocol is already installed, you want to return an error
so the PE/COFF image for the driver will be unloaded. Following the
example from Section 7.8 of UEFI Driver Writer's Guide an error code
of EFI_ABORTED can be used for this case.
Status = gBS->LocateProtocol (&gEfiPkcs7VerifyProtocolGuid, NULL, (VOID
**)&Useless);
if (!EFI_ERROR (Status)) {
return EFI_ABORTED;
}
Best regards,
Mike
> -----Original Message-----
> From: edk2-devel [mailto:[email protected]] On Behalf Of Peter
> Jones
> Sent: Thursday, September 29, 2016 8:59 AM
> To: [email protected]
> Cc: Peter Jones <[email protected]>
> Subject: [edk2] [PATCH] Pkcs7VerifyDxe: Don't allow Pkcs7Verify to install
> protocols
> twice.
>
> This patch makes Pkcs7VerifyDxe check that it has not already been
> installed before installing its protocols. This prevents the case where
> loading it as an external driver (either manually, through Driver####
> variables, etc.) will refuse to add a second provider of the API.
>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Peter Jones <[email protected]>
> ---
> SecurityPkg/Pkcs7Verify/Pkcs7VerifyDxe/Pkcs7VerifyDxe.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/SecurityPkg/Pkcs7Verify/Pkcs7VerifyDxe/Pkcs7VerifyDxe.c
> b/SecurityPkg/Pkcs7Verify/Pkcs7VerifyDxe/Pkcs7VerifyDxe.c
> index 07fdf55..3389af4 100644
> --- a/SecurityPkg/Pkcs7Verify/Pkcs7VerifyDxe/Pkcs7VerifyDxe.c
> +++ b/SecurityPkg/Pkcs7Verify/Pkcs7VerifyDxe/Pkcs7VerifyDxe.c
> @@ -1030,8 +1030,16 @@ Pkcs7VerifyDriverEntry (
> IN EFI_SYSTEM_TABLE *SystemTable
> )
> {
> - EFI_STATUS Status;
> - EFI_HANDLE Handle;
> + EFI_STATUS Status;
> + EFI_HANDLE Handle;
> + EFI_PKCS7_VERIFY_PROTOCOL Useless;
> +
> + //
> + // Avoid loading a second copy if this is built as an external module.
> + //
> + Status = gBS->LocateProtocol (&gEfiPkcs7VerifyProtocolGuid, NULL, (VOID **)
> &Useless);
> + if (Status != EFI_NOT_FOUND)
> + return EFI_SUCCESS;>
> //
> // Install UEFI Pkcs7 Verification Protocol
> --
> 2.10.0
>
> _______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel