From: "Jan Beulich" Subject: [PATCH] x86/EFI: add code interfacing with the secure boot shim Date: Thu, 06 Dec 2012 13:05:48 +0000 Message-ID: <50C0A63C02000078000AE910@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part5C6DC13C.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part5C6DC13C.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ... to validate the kernel image (which is required to be in PE format, as is e.g. the case for the Linux bzImage when built with CONFIG_EFI_STUB). Signed-off-by: Jan Beulich --- a/xen/arch/x86/efi/boot.c +++ b/xen/arch/x86/efi/boot.c @@ -24,6 +24,18 @@ #include #include =20 +#define SHIM_LOCK_PROTOCOL_GUID \ + { 0x605dab50, 0xe046, 0x4300, {0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, = 0x8b, 0x23} } + +typedef EFI_STATUS +(/* _not_ EFIAPI */ *EFI_SHIM_LOCK_VERIFY) ( + IN VOID *Buffer, + IN UINT32 Size); + +typedef struct { + EFI_SHIM_LOCK_VERIFY Verify; +} EFI_SHIM_LOCK_PROTOCOL; + extern char start[]; extern u32 cpuid_ext_features; =20 @@ -640,12 +652,14 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SY static EFI_GUID __initdata gop_guid =3D EFI_GRAPHICS_OUTPUT_PROTOCOL_G= UID; static EFI_GUID __initdata bio_guid =3D BLOCK_IO_PROTOCOL; static EFI_GUID __initdata devp_guid =3D DEVICE_PATH_PROTOCOL; + static EFI_GUID __initdata shim_lock_guid =3D SHIM_LOCK_PROTOCOL_GUID;= EFI_LOADED_IMAGE *loaded_image; EFI_STATUS status; unsigned int i, argc; CHAR16 **argv, *file_name, *cfg_file_name =3D NULL; UINTN cols, rows, depth, size, map_key, info_size, gop_mode =3D ~0; EFI_HANDLE *handles =3D NULL; + EFI_SHIM_LOCK_PROTOCOL *shim_lock; EFI_GRAPHICS_OUTPUT_PROTOCOL *gop =3D NULL; EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info; EFI_FILE_HANDLE dir_handle; @@ -835,6 +849,11 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SY read_file(dir_handle, s2w(&name), &kernel); efi_bs->FreePool(name.w); =20 + if ( !EFI_ERROR(efi_bs->LocateProtocol(&shim_lock_guid, NULL, + (void **)&shim_lock)) && + shim_lock->Verify(kernel.ptr, kernel.size) !=3D EFI_SUCCESS ) + blexit(L"Dom0 kernel image could not be verified\r\n"); + name.s =3D get_value(&cfg, section.s, "ramdisk"); if ( name.s ) { --=__Part5C6DC13C.0__= Content-Type: text/plain; name="x86-EFI-secure-shim.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-EFI-secure-shim.patch" x86/EFI: add code interfacing with the secure boot shim=0A=0A... to = validate the kernel image (which is required to be in PE=0Aformat, as is = e.g. the case for the Linux bzImage when built with=0ACONFIG_EFI_STUB).=0A= =0ASigned-off-by: Jan Beulich =0A=0A--- a/xen/arch/x86/e= fi/boot.c=0A+++ b/xen/arch/x86/efi/boot.c=0A@@ -24,6 +24,18 @@=0A #include = =0A #include =0A =0A+#define SHIM_LOCK_PROTOCOL= _GUID \=0A+ { 0x605dab50, 0xe046, 0x4300, {0xab, 0xb6, 0x3d, 0xd8, 0x10, = 0xdd, 0x8b, 0x23} }=0A+=0A+typedef EFI_STATUS=0A+(/* _not_ EFIAPI */ = *EFI_SHIM_LOCK_VERIFY) (=0A+ IN VOID *Buffer,=0A+ IN UINT32 = Size);=0A+=0A+typedef struct {=0A+ EFI_SHIM_LOCK_VERIFY Verify;=0A+} = EFI_SHIM_LOCK_PROTOCOL;=0A+=0A extern char start[];=0A extern u32 = cpuid_ext_features;=0A =0A@@ -640,12 +652,14 @@ efi_start(EFI_HANDLE = ImageHandle, EFI_SY=0A static EFI_GUID __initdata gop_guid =3D = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;=0A static EFI_GUID __initdata = bio_guid =3D BLOCK_IO_PROTOCOL;=0A static EFI_GUID __initdata = devp_guid =3D DEVICE_PATH_PROTOCOL;=0A+ static EFI_GUID __initdata = shim_lock_guid =3D SHIM_LOCK_PROTOCOL_GUID;=0A EFI_LOADED_IMAGE = *loaded_image;=0A EFI_STATUS status;=0A unsigned int i, argc;=0A = CHAR16 **argv, *file_name, *cfg_file_name =3D NULL;=0A UINTN cols, = rows, depth, size, map_key, info_size, gop_mode =3D ~0;=0A EFI_HANDLE = *handles =3D NULL;=0A+ EFI_SHIM_LOCK_PROTOCOL *shim_lock;=0A = EFI_GRAPHICS_OUTPUT_PROTOCOL *gop =3D NULL;=0A EFI_GRAPHICS_OUTPUT_MODE= _INFORMATION *mode_info;=0A EFI_FILE_HANDLE dir_handle;=0A@@ -835,6 = +849,11 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SY=0A read_file(dir_ha= ndle, s2w(&name), &kernel);=0A efi_bs->FreePool(name.w);=0A =0A+ if = ( !EFI_ERROR(efi_bs->LocateProtocol(&shim_lock_guid, NULL,=0A+ = (void **)&shim_lock)) &&=0A+ shim_lock->Verify(kernel.ptr, = kernel.size) !=3D EFI_SUCCESS )=0A+ blexit(L"Dom0 kernel image = could not be verified\r\n");=0A+=0A name.s =3D get_value(&cfg, = section.s, "ramdisk");=0A if ( name.s )=0A {=0A --=__Part5C6DC13C.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part5C6DC13C.0__=--