EFI Secure boot support
Subsystems (2)
cover EFI Secure boot support
Hi,
This patch serie is the first one to add the secure boot support to barebox on efi
For now on this will allow you to execute only properly signed EFI Application.
And request confirmation for non signed binary other than EFI
Later will add non signed EFI Application execution request at user request and MoK Support, add other goodies.
Please pull
The following changes since commit 071eb906506d478a3d0b04460625e64edbcd1294:
efi: fix secure and setup mode report (2017-03-04 13:20:38 +0800)
are available in the git repository at:
git://git.jcrosoft.org/barebox.git delivery/efi-sb
for you to fetch changes up to 99e61a9be467fab5b5127b1233c4c4e70288e84c:
efi: enable sercure boot support (2017-03-04 13:20:38 +0800)
----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (2):
boot: if we are in secure boot mode
efi: enable sercure boot support
arch/x86/Kconfig | 1 + commands/go.c | 7 +++++++ common/Kconfig | 8 ++++++++ common/Makefile | 1 + common/bootm.c | 7 +++++++ common/efi/efi-image.c | 1 + common/secure_boot.c | 43 +++++++++++++++++++++++++++++++++++++++++++ drivers/efi/efi-device.c | 9 +++++++++ include/bootm.h | 1 + include/secure_boot.h | 25 +++++++++++++++++++++++++ 10 files changed, 103 insertions(+) create mode 100644 common/secure_boot.c create mode 100644 include/secure_boot.h
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/5 efi: add more security related guid for the efivars
--- common/efi-guid.c | 6 ++++++ include/efi.h | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+)
common/efi-guid.c +6 -0
@@ -81,6 +81,12 @@ const char *efi_guid_string(efi_guid_t *g)EFI_GUID_STRING (EFI_TCG_PROTOCOL_GUID ,"TcgService" ,"TCGServices Protocol" );/* TPM 2.0 */ EFI_GUID_STRING (EFI_TCG2_PROTOCOL_GUID ,"Tcg2Service" ,"TCG2Services Protocol" ); +EFI_GUID_STRING (EFI_VENDOR_KEYS_NV_VARIABLE_NAME_GUID ,"VendorKeysNv" ,"Vendor Keys Non-Volatile" ); +EFI_GUID_STRING (EFI_AUTHENTICATED_VARIABLE_GUID ,"AuthVar" ,"Authenticated Variable" ); +EFI_GUID_STRING (EFI_IMAGE_SECURITY_DATABASE_GUID ,"ImageSecurityDB" ,"Image Security Database" ); +EFI_GUID_STRING (EFI_CERT_DB_GUID ,"CertDB" ,"Certificate Database" ); +EFI_GUID_STRING (EFI_SECURE_BOOT_ENABLE_DISABLE_GUID ,"SecureBootEnable" ,"Secure Boot Enable Disable" ); +EFI_GUID_STRING (EFI_CUSTOM_MODE_ENABLE_GUID ,"CustomMode" ,"CustomMode" );/* File */ EFI_GUID_STRING (EFI_IDEBUSDXE_INF_GUID ,"IdeBusDxe.inf" ,"EFI IdeBusDxe.inf File GUID" );
include/efi.h +18 -0
@@ -507,6 +507,24 @@ extern efi_runtime_services_t *RT;#define EFI_TCG2_PROTOCOL_GUID \ EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f) +#define EFI_VENDOR_KEYS_NV_VARIABLE_NAME_GUID \ + EFI_GUID(0x9073e4e0, 0x60ec, 0x4b6e, 0x99, 0x3, 0x4c, 0x22, 0x3c, 0x26, 0x0f, 0x3c) + +#define EFI_AUTHENTICATED_VARIABLE_GUID \ + EFI_GUID(0xaaf32c78, 0x947b, 0x439a, 0xa1, 0x80, 0x2e, 0x14, 0x4e, 0xc3,0x77, 0x92) + +#define EFI_IMAGE_SECURITY_DATABASE_GUID \ + EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, 0xda, 0xd0, 0xe, 0x67, 0x65, 0x6f) + +#define EFI_CERT_DB_GUID \ + EFI_GUID(0xd9bee56e, 0x75dc, 0x49d9, 0xb4, 0xd7, 0xb5, 0x34, 0x21, 0xf, 0x63, 0x7a) + +#define EFI_SECURE_BOOT_ENABLE_DISABLE_GUID \ + EFI_GUID(0xf0a30bc7, 0xaf08, 0x4556, 0x99, 0xc4, 0x00, 0x10, 0x9, 0xc9, 0x3a, 0x44) + +#define EFI_CUSTOM_MODE_ENABLE_GUID \ + EFI_GUID(0xc076ec0c, 0x7028, 0x4399, 0xa0, 0x72, 0x71, 0xee, 0x5c, 0x44, 0x8b, 0x9f) +extern efi_guid_t efi_file_info_id;extern efi_guid_t efi_simple_file_system_protocol_guid;extern efi_guid_t efi_device_path_protocol_guid;
Signature · 7 lines
2.11.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/5 efi: fix lds for secure boot support
everythink need to be aligned to 4096
--- arch/x86/mach-efi/elf_ia32_efi.lds.S | 10 +++++++--- arch/x86/mach-efi/elf_x86_64_efi.lds.S | 10 ++++++---- arch/x86/mach-efi/include/mach/barebox.lds.h | 14 +++++++++++++- include/asm-generic/barebox.lds.h | 8 +++++--- 4 files changed, 31 insertions(+), 11 deletions(-)
arch/x86/mach-efi/elf_ia32_efi.lds.S +7 -3
@@ -50,22 +50,23 @@ SECTIONS *(COMMON) } - . = ALIGN(64); + . = ALIGN(4096); __barebox_initcalls_start = .; __barebox_initcalls : { INITCALLS } __barebox_initcalls_end = .; + . = ALIGN(4096); __barebox_exitcalls_start = .; __barebox_exitcalls : { EXITCALLS } __barebox_exitcalls_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_magicvar_start = .; .barebox_magicvar : { BAREBOX_MAGICVARS } __barebox_magicvar_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_cmd_start = .; __barebox_cmd : { BAREBOX_CMDS } __barebox_cmd_end = .;
@@ -76,6 +77,9 @@ SECTIONS .rel : { *(.rel.data) *(.rel.data.*) + *(.rela.barebox*) + *(.rela.initcall*) + *(.rela.exitcall*) *(.rel.got) *(.rel.stab) *(.data.rel.ro.local)
arch/x86/mach-efi/elf_x86_64_efi.lds.S +6 -4
@@ -23,6 +23,7 @@ SECTIONS *(.text) *(.text.*) *(.gnu.linkonce.t.*) + . = ALIGN(16); } _etext = .;
@@ -33,8 +34,8 @@ SECTIONS *(.reloc) } - . = ALIGN(4096); _sdata = .; + . = ALIGN(4096); .data : { *(.rodata*)
@@ -52,22 +53,23 @@ SECTIONS *(.rel.local) } - . = ALIGN(64); + . = ALIGN(4096); __barebox_initcalls_start = .; __barebox_initcalls : { INITCALLS } __barebox_initcalls_end = .; + . = ALIGN(4096); __barebox_exitcalls_start = .; __barebox_exitcalls : { EXITCALLS } __barebox_exitcalls_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_magicvar_start = .; .barebox_magicvar : { BAREBOX_MAGICVARS } __barebox_magicvar_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_cmd_start = .; __barebox_cmd : { BAREBOX_CMDS } __barebox_cmd_end = .;
arch/x86/mach-efi/include/mach/barebox.lds.h +13 -1
@@ -1 +1,13 @@ -/* empty */ +/* +* Copyright (C) 2017 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> +* +* Under GPL v2 +*/ + +#ifndef __EFI_MACH_BAREBOX_LDS_H__ +#define __EFI_MACH_BAREBOX_LDS_H__ + +/* For secure boot we need all the section to be 4096 alligned */ +#define STRUCT_ALIGNMENT 4096 + +#endif /* __EFI_MACH_BAREBOX_LDS_H__ */
include/asm-generic/barebox.lds.h +5 -3
@@ -3,15 +3,17 @@* Align to a 32 byte boundary equal to the * alignment gcc 4.5 uses for a struct */ -#define STRUCT_ALIGNMENT 32 -#define STRUCT_ALIGN () . = ALIGN(STRUCT_ALIGNMENT) -#if definedCONFIG_X86 || \ definedCONFIG_ARCH_EP93XX || \ definedCONFIG_ARCH_ZYNQ #include <mach/barebox.lds.h> #endif +#ifndef STRUCT_ALIGNMENT +#define STRUCT_ALIGNMENT 32 +#endif +#define STRUCT_ALIGN () . = ALIGN(STRUCT_ALIGNMENT) +#ifndef PRE_IMAGE #define PRE_IMAGE #endif
Signature · 7 lines
2.11.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/5] efi: fix lds for secure boot support
Am Donnerstag, den 09.03.2017, 15:34 +0100 schrieb Jean-Christophe PLAGNIOL-VILLARD:
Quoted 1 line
everythink need to be aligned to 4096
Why? The commit message isn't really telling anything.
Regards,
Lucas
Quoted 133 lines
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- arch/x86/mach-efi/elf_ia32_efi.lds.S | 10 +++++++--- arch/x86/mach-efi/elf_x86_64_efi.lds.S | 10 ++++++---- arch/x86/mach-efi/include/mach/barebox.lds.h | 14 +++++++++++++- include/asm-generic/barebox.lds.h | 8 +++++--- 4 files changed, 31 insertions(+), 11 deletions(-)arch/x86/mach-efi/elf_ia32_efi.lds.S +7
-3@@ -50,22 +50,23 @@ SECTIONS *(COMMON) } - . = ALIGN(64); + . = ALIGN(4096); __barebox_initcalls_start = .; __barebox_initcalls : { INITCALLS } __barebox_initcalls_end = .; + . = ALIGN(4096); __barebox_exitcalls_start = .; __barebox_exitcalls : { EXITCALLS } __barebox_exitcalls_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_magicvar_start = .; .barebox_magicvar : { BAREBOX_MAGICVARS } __barebox_magicvar_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_cmd_start = .; __barebox_cmd : { BAREBOX_CMDS } __barebox_cmd_end = .;@@ -76,6 +77,9 @@ SECTIONS .rel : { *(.rel.data) *(.rel.data.*) + *(.rela.barebox*) + *(.rela.initcall*) + *(.rela.exitcall*) *(.rel.got) *(.rel.stab) *(.data.rel.ro.local)arch/x86/mach-efi/elf_x86_64_efi.lds.S +6
-4@@ -23,6 +23,7 @@ SECTIONS *(.text) *(.text.*) *(.gnu.linkonce.t.*) + . = ALIGN(16); } _etext = .;@@ -33,8 +34,8 @@ SECTIONS *(.reloc) } - . = ALIGN(4096); _sdata = .; + . = ALIGN(4096); .data : { *(.rodata*)@@ -52,22 +53,23 @@ SECTIONS *(.rel.local) } - . = ALIGN(64); + . = ALIGN(4096); __barebox_initcalls_start = .; __barebox_initcalls : { INITCALLS } __barebox_initcalls_end = .; + . = ALIGN(4096); __barebox_exitcalls_start = .; __barebox_exitcalls : { EXITCALLS } __barebox_exitcalls_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_magicvar_start = .; .barebox_magicvar : { BAREBOX_MAGICVARS } __barebox_magicvar_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_cmd_start = .; __barebox_cmd : { BAREBOX_CMDS } __barebox_cmd_end = .;arch/x86/mach-efi/include/mach/barebox.lds.h +13
-1@@ -1 +1,13 @@ -/* empty */ +/* +* Copyright (C) 2017 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> +* +* Under GPL v2 +*/ + +#ifndef __EFI_MACH_BAREBOX_LDS_H__ +#define __EFI_MACH_BAREBOX_LDS_H__ + +/* For secure boot we need all the section to be 4096 alligned */ +#define STRUCT_ALIGNMENT 4096 + +#endif /* __EFI_MACH_BAREBOX_LDS_H__ */ include/asm-generic/barebox.lds.h +0
-3@@ -3,15 +3,17 @@* Align to a 32 byte boundary equal to the * alignment gcc 4.5 uses for a struct */ -#define STRUCT_ALIGNMENT 32 -#define STRUCT_ALIGN () . = ALIGN(STRUCT_ALIGNMENT) -#if definedCONFIG_X86 || \ definedCONFIG_ARCH_EP93XX || \ definedCONFIG_ARCH_ZYNQ #include <mach/barebox.lds.h>
include/asm-generic/barebox.lds.h line 19
Quoted 10 lines
include/asm-generic/barebox.lds.h +5
-0#endif +#ifndef STRUCT_ALIGNMENT +#define STRUCT_ALIGNMENT 32 +#endif +#define STRUCT_ALIGN () . = ALIGN(STRUCT_ALIGNMENT) +#ifndef PRE_IMAGE #define PRE_IMAGE #endif
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/5] efi: fix lds for secure boot support
Quoted 8 lines · Lucas Stach
Am Donnerstag, den 09.03.2017, 15:34 +0100 schrieb Jean-Christophe PLAGNIOL-VILLARD:
Quoted 1 line
everythink need to be aligned to 4096
Why? The commit message isn't really telling anything.
This is a requierment by EFI
Best Regards,
J.
Quoted 139 lines
Regards,
LucasQuoted 135 lines
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>---
arch/x86/mach-efi/elf_ia32_efi.lds.S | 10 +++++++--- arch/x86/mach-efi/elf_x86_64_efi.lds.S | 10 ++++++---- arch/x86/mach-efi/include/mach/barebox.lds.h | 14 +++++++++++++- include/asm-generic/barebox.lds.h | 8 +++++--- 4 files changed, 31 insertions(+), 11 deletions(-)arch/x86/mach-efi/elf_ia32_efi.lds.S +7
-3@@ -50,22 +50,23 @@ SECTIONS *(COMMON) } - . = ALIGN(64); + . = ALIGN(4096); __barebox_initcalls_start = .; __barebox_initcalls : { INITCALLS } __barebox_initcalls_end = .; + . = ALIGN(4096); __barebox_exitcalls_start = .; __barebox_exitcalls : { EXITCALLS } __barebox_exitcalls_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_magicvar_start = .; .barebox_magicvar : { BAREBOX_MAGICVARS } __barebox_magicvar_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_cmd_start = .; __barebox_cmd : { BAREBOX_CMDS } __barebox_cmd_end = .;@@ -76,6 +77,9 @@ SECTIONS .rel : { *(.rel.data) *(.rel.data.*) + *(.rela.barebox*) + *(.rela.initcall*) + *(.rela.exitcall*) *(.rel.got) *(.rel.stab) *(.data.rel.ro.local)arch/x86/mach-efi/elf_x86_64_efi.lds.S +6
-4@@ -23,6 +23,7 @@ SECTIONS *(.text) *(.text.*) *(.gnu.linkonce.t.*) + . = ALIGN(16); } _etext = .;@@ -33,8 +34,8 @@ SECTIONS *(.reloc) } - . = ALIGN(4096); _sdata = .; + . = ALIGN(4096); .data : { *(.rodata*)@@ -52,22 +53,23 @@ SECTIONS *(.rel.local) } - . = ALIGN(64); + . = ALIGN(4096); __barebox_initcalls_start = .; __barebox_initcalls : { INITCALLS } __barebox_initcalls_end = .; + . = ALIGN(4096); __barebox_exitcalls_start = .; __barebox_exitcalls : { EXITCALLS } __barebox_exitcalls_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_magicvar_start = .; .barebox_magicvar : { BAREBOX_MAGICVARS } __barebox_magicvar_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_cmd_start = .; __barebox_cmd : { BAREBOX_CMDS } __barebox_cmd_end = .;arch/x86/mach-efi/include/mach/barebox.lds.h +13
-1@@ -1 +1,13 @@ -/* empty */ +/* +* Copyright (C) 2017 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> +* +* Under GPL v2 +*/ + +#ifndef __EFI_MACH_BAREBOX_LDS_H__ +#define __EFI_MACH_BAREBOX_LDS_H__ + +/* For secure boot we need all the section to be 4096 alligned */ +#define STRUCT_ALIGNMENT 4096 + +#endif /* __EFI_MACH_BAREBOX_LDS_H__ */ include/asm-generic/barebox.lds.h +0
-3@@ -3,15 +3,17 @@* Align to a 32 byte boundary equal to the * alignment gcc 4.5 uses for a struct */ -#define STRUCT_ALIGNMENT 32 -#define STRUCT_ALIGN () . = ALIGN(STRUCT_ALIGNMENT) -#if definedCONFIG_X86 || \ definedCONFIG_ARCH_EP93XX || \ definedCONFIG_ARCH_ZYNQ #include <mach/barebox.lds.h> #endif
Quoted 10 lines
include/asm-generic/barebox.lds.h line 19
Quoted 8 lines
include/asm-generic/barebox.lds.h +5
-0+#ifndef STRUCT_ALIGNMENT +#define STRUCT_ALIGNMENT 32 +#endif +#define STRUCT_ALIGN () . = ALIGN(STRUCT_ALIGNMENT) +#ifndef PRE_IMAGE #define PRE_IMAGE #endif
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/5] efi: fix lds for secure boot support
Am Freitag, den 10.03.2017, 18:17 +0800 schrieb Jean-Christophe PLAGNIOL-VILLARD:
Quoted 8 lines
Quoted 7 lines · Lucas Stach
Am Donnerstag, den 09.03.2017, 15:34 +0100 schrieb Jean-Christophe PLAGNIOL-VILLARD:
Quoted 1 line
everythink need to be aligned to 4096
Why? The commit message isn't really telling anything.
This is a requierment by EFI
This is in no way an EFI requirement.
Googling tells me that the signing procedure for EFI secure boot is built around a PE binary. PE in turn is based on the COFF binary format which, unlike ELF, has no section descriptions in the header and therefore requires the sections to be placed page aligned (4K on x86, 4K or 64K on ARM64).
All of the above is what should have been included in the commit message, to allow other people to understand the commit and not require them to google their way to the justification of this commit.
Regards,
Lucas
Quoted 152 lines
Best Regards,
J.Quoted 149 lines
Regards,
LucasQuoted 143 lines
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>---
arch/x86/mach-efi/elf_ia32_efi.lds.S | 10 +++++++--- arch/x86/mach-efi/elf_x86_64_efi.lds.S | 10 ++++++---- arch/x86/mach-efi/include/mach/barebox.lds.h | 14 +++++++++++++- include/asm-generic/barebox.lds.h | 8 +++++--- 4 files changed, 31 insertions(+), 11 deletions(-)arch/x86/mach-efi/elf_ia32_efi.lds.S +7
-3@@ -50,22 +50,23 @@ SECTIONS *(COMMON) } - . = ALIGN(64); + . = ALIGN(4096); __barebox_initcalls_start = .; __barebox_initcalls : { INITCALLS } __barebox_initcalls_end = .; + . = ALIGN(4096); __barebox_exitcalls_start = .; __barebox_exitcalls : { EXITCALLS } __barebox_exitcalls_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_magicvar_start = .; .barebox_magicvar : { BAREBOX_MAGICVARS } __barebox_magicvar_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_cmd_start = .; __barebox_cmd : { BAREBOX_CMDS } __barebox_cmd_end = .;@@ -76,6 +77,9 @@ SECTIONS .rel : { *(.rel.data) *(.rel.data.*) + *(.rela.barebox*) + *(.rela.initcall*) + *(.rela.exitcall*) *(.rel.got) *(.rel.stab) *(.data.rel.ro.local)arch/x86/mach-efi/elf_x86_64_efi.lds.S +6
-4@@ -23,6 +23,7 @@ SECTIONS *(.text) *(.text.*) *(.gnu.linkonce.t.*) + . = ALIGN(16); } _etext = .;@@ -33,8 +34,8 @@ SECTIONS *(.reloc) } - . = ALIGN(4096); _sdata = .; + . = ALIGN(4096); .data : { *(.rodata*)@@ -52,22 +53,23 @@ SECTIONS *(.rel.local) } - . = ALIGN(64); + . = ALIGN(4096); __barebox_initcalls_start = .; __barebox_initcalls : { INITCALLS } __barebox_initcalls_end = .; + . = ALIGN(4096); __barebox_exitcalls_start = .; __barebox_exitcalls : { EXITCALLS } __barebox_exitcalls_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_magicvar_start = .; .barebox_magicvar : { BAREBOX_MAGICVARS } __barebox_magicvar_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_cmd_start = .; __barebox_cmd : { BAREBOX_CMDS } __barebox_cmd_end = .;arch/x86/mach-efi/include/mach/barebox.lds.h +13
-1@@ -1 +1,13 @@ -/* empty */ +/* +* Copyright (C) 2017 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> +* +* Under GPL v2 +*/ + +#ifndef __EFI_MACH_BAREBOX_LDS_H__ +#define __EFI_MACH_BAREBOX_LDS_H__ + +/* For secure boot we need all the section to be 4096 alligned */ +#define STRUCT_ALIGNMENT 4096 + +#endif /* __EFI_MACH_BAREBOX_LDS_H__ */ include/asm-generic/barebox.lds.h +5
-3@@ -3,15 +3,17 @@* Align to a 32 byte boundary equal to the * alignment gcc 4.5 uses for a struct */ -#define STRUCT_ALIGNMENT 32 -#define STRUCT_ALIGN () . = ALIGN(STRUCT_ALIGNMENT) -#if definedCONFIG_X86 || \ definedCONFIG_ARCH_EP93XX || \ definedCONFIG_ARCH_ZYNQ #include <mach/barebox.lds.h> #endif +#ifndef STRUCT_ALIGNMENT +#define STRUCT_ALIGNMENT 32 +#endif +#define STRUCT_ALIGN () . = ALIGN(STRUCT_ALIGNMENT) +#ifndef PRE_IMAGE #define PRE_IMAGE #endif
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/5] efi: fix lds for secure boot support
Quoted 11 lines · Lucas Stach
Am Freitag, den 10.03.2017, 18:17 +0800 schrieb Jean-Christophe PLAGNIOL-VILLARD:
Quoted 8 lines
Quoted 7 lines · Lucas Stach
Am Donnerstag, den 09.03.2017, 15:34 +0100 schrieb Jean-Christophe PLAGNIOL-VILLARD:
Quoted 1 line
everythink need to be aligned to 4096
Why? The commit message isn't really telling anything.
This is a requierment by EFI
Quoted 7 lines
This is in no way an EFI requirement.
Googling tells me that the signing procedure for EFI secure boot is built around a PE binary. PE in turn is based on the COFF binary format which, unlike ELF, has no section descriptions in the header and therefore requires the sections to be placed page aligned (4K on x86, 4K or 64K on ARM64).
No COFF does not require to have section "page aligned" which is wrong here The is a Requirement by EFI from secure boot
Otherwise EFI will not work today
Quoted 4 lines
All of the above is what should have been included in the commit message, to allow other people to understand the commit and not require them to google their way to the justification of this commit.
And read the Spec is required to undrestant EFI no? Or I need to put the spec in the commit too?
Best Regards,
J
Quoted 158 lines
Regards,
LucasQuoted 152 lines
Best Regards,
J.Quoted 149 lines
Regards,
LucasQuoted 143 lines
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>---
arch/x86/mach-efi/elf_ia32_efi.lds.S | 10 +++++++--- arch/x86/mach-efi/elf_x86_64_efi.lds.S | 10 ++++++---- arch/x86/mach-efi/include/mach/barebox.lds.h | 14 +++++++++++++- include/asm-generic/barebox.lds.h | 8 +++++--- 4 files changed, 31 insertions(+), 11 deletions(-)arch/x86/mach-efi/elf_ia32_efi.lds.S +7
-3@@ -50,22 +50,23 @@ SECTIONS *(COMMON) } - . = ALIGN(64); + . = ALIGN(4096); __barebox_initcalls_start = .; __barebox_initcalls : { INITCALLS } __barebox_initcalls_end = .; + . = ALIGN(4096); __barebox_exitcalls_start = .; __barebox_exitcalls : { EXITCALLS } __barebox_exitcalls_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_magicvar_start = .; .barebox_magicvar : { BAREBOX_MAGICVARS } __barebox_magicvar_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_cmd_start = .; __barebox_cmd : { BAREBOX_CMDS } __barebox_cmd_end = .;@@ -76,6 +77,9 @@ SECTIONS .rel : { *(.rel.data) *(.rel.data.*) + *(.rela.barebox*) + *(.rela.initcall*) + *(.rela.exitcall*) *(.rel.got) *(.rel.stab) *(.data.rel.ro.local)arch/x86/mach-efi/elf_x86_64_efi.lds.S +6
-4@@ -23,6 +23,7 @@ SECTIONS *(.text) *(.text.*) *(.gnu.linkonce.t.*) + . = ALIGN(16); } _etext = .;@@ -33,8 +34,8 @@ SECTIONS *(.reloc) } - . = ALIGN(4096); _sdata = .; + . = ALIGN(4096); .data : { *(.rodata*)@@ -52,22 +53,23 @@ SECTIONS *(.rel.local) } - . = ALIGN(64); + . = ALIGN(4096); __barebox_initcalls_start = .; __barebox_initcalls : { INITCALLS } __barebox_initcalls_end = .; + . = ALIGN(4096); __barebox_exitcalls_start = .; __barebox_exitcalls : { EXITCALLS } __barebox_exitcalls_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_magicvar_start = .; .barebox_magicvar : { BAREBOX_MAGICVARS } __barebox_magicvar_end = .; - . = ALIGN(64); + . = ALIGN(4096); __barebox_cmd_start = .; __barebox_cmd : { BAREBOX_CMDS } __barebox_cmd_end = .;arch/x86/mach-efi/include/mach/barebox.lds.h +13
-1@@ -1 +1,13 @@ -/* empty */ +/* +* Copyright (C) 2017 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> +* +* Under GPL v2 +*/ + +#ifndef __EFI_MACH_BAREBOX_LDS_H__ +#define __EFI_MACH_BAREBOX_LDS_H__ + +/* For secure boot we need all the section to be 4096 alligned */ +#define STRUCT_ALIGNMENT 4096 + +#endif /* __EFI_MACH_BAREBOX_LDS_H__ */ include/asm-generic/barebox.lds.h +5
-3@@ -3,15 +3,17 @@* Align to a 32 byte boundary equal to the * alignment gcc 4.5 uses for a struct */ -#define STRUCT_ALIGNMENT 32 -#define STRUCT_ALIGN () . = ALIGN(STRUCT_ALIGNMENT) -#if definedCONFIG_X86 || \ definedCONFIG_ARCH_EP93XX || \ definedCONFIG_ARCH_ZYNQ #include <mach/barebox.lds.h> #endif +#ifndef STRUCT_ALIGNMENT +#define STRUCT_ALIGNMENT 32 +#endif +#define STRUCT_ALIGN () . = ALIGN(STRUCT_ALIGNMENT) +#ifndef PRE_IMAGE #define PRE_IMAGE #endif
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/5] efi: fix lds for secure boot support
Am Freitag, den 10.03.2017, 14:54 +0100 schrieb Jean-Christophe PLAGNIOL-VILLARD:
Quoted 22 lines · Lucas Stach
Quoted 11 lines
Am Freitag, den 10.03.2017, 18:17 +0800 schrieb Jean-Christophe PLAGNIOL-VILLARD:
Quoted 8 lines
Quoted 7 lines · Lucas Stach
Am Donnerstag, den 09.03.2017, 15:34 +0100 schrieb Jean-Christophe PLAGNIOL-VILLARD:
Quoted 1 line
everythink need to be aligned to 4096
Why? The commit message isn't really telling anything.
This is a requierment by EFI
Quoted 7 lines
This is in no way an EFI requirement.
Googling tells me that the signing procedure for EFI secure boot is built around a PE binary. PE in turn is based on the COFF binary format which, unlike ELF, has no section descriptions in the header and therefore requires the sections to be placed page aligned (4K on x86, 4K or 64K on ARM64).
No COFF does not require to have section "page aligned" which is wrong here The is a Requirement by EFI from secure boot
Quoted 9 lines
Otherwise EFI will not work today
Quoted 4 lines
All of the above is what should have been included in the commit message, to allow other people to understand the commit and not require them to google their way to the justification of this commit.
And read the Spec is required to undrestant EFI no? Or I need to put the spec in the commit too?
At least a pointer to the relevant part of the spec would be appreciated.
That we are even having this conversation shows that your commit messages are a bit too terse. Being a bit more verbose would be really helpful for other folks trying to understand your changes.
Thanks,
Lucas
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/5] efi: fix lds for secure boot support
In reply to Jean-Christophe PLAGNIOL-VILLARDQuoted 12 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 11 lines · Lucas Stach
Am Freitag, den 10.03.2017, 18:17 +0800 schrieb Jean-Christophe PLAGNIOL-VILLARD:
Quoted 8 lines
Quoted 7 lines · Lucas Stach
Am Donnerstag, den 09.03.2017, 15:34 +0100 schrieb Jean-Christophe PLAGNIOL-VILLARD:
Quoted 1 line
everythink need to be aligned to 4096
Why? The commit message isn't really telling anything.
This is a requierment by EFI
Quoted 8 lines
Quoted 7 lines
This is in no way an EFI requirement.
Googling tells me that the signing procedure for EFI secure boot is built around a PE binary. PE in turn is based on the COFF binary format which, unlike ELF, has no section descriptions in the header and therefore requires the sections to be placed page aligned (4K on x86, 4K or 64K on ARM64).
No COFF does not require to have section "page aligned" which is wrong here
This is the job of the loader to aligned them in memory but on EFI it's required to sign the binary.
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH 3/5 efi: fix secure and setup mode report
In reply to Jean-Christophe PLAGNIOL-VILLARD--- drivers/efi/efi-device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/efi/efi-device.c +3 -3
@@ -365,7 +365,7 @@ static int efi_is_secure_boot(void)free (val); } -return ret !=1 ; +return ret !=0 ; }static int efi_is_setup_mode (void )
@@ -379,7 +379,7 @@ static int efi_is_setup_mode(void)free (val); } -return ret !=1 ; +return ret !=0 ; }static int efi_init_devices (void )
@@ -406,7 +406,7 @@ static int efi_init_devices(void)dev_add_param_int_ro (efi_bus.dev,"fw_revision" , efi_sys_table->fw_revision,"%u" );dev_add_param_int_ro (efi_bus.dev,"secure_boot" , secure_boot,"%d" );dev_add_param_int_ro (efi_bus.dev,"secure_mode" , - secure_boot & setup_mode,"%u" ); + secure_boot & !setup_mode,"%u" ); efi_bus.dev->info = efi_businfo;
Signature · 7 lines
2.11.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 3/5] efi: fix secure and setup mode report
Quoted 28 lines · Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- drivers/efi/efi-device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/efi/efi-device.c +2
-2@@ -365,7 +365,7 @@ static int efi_is_secure_boot(void)free (val); } -return ret !=1 ; +return ret !=0 ; }static int efi_is_setup_mode (void )@@ -379,7 +379,7 @@ static int efi_is_setup_mode(void)free (val); } -return ret !=1 ; +return ret !=0 ; }static int efi_init_devices (void )
drivers/efi/efi-device.c static int efi_init_devices(void) · line 409
Quoted 5 lines
drivers/efi/efi-device.c +1
-1@@ -406,7 +406,7 @@ static int efi_init_devices(void)dev_add_param_int_ro (efi_bus.dev,"fw_revision" , efi_sys_table->fw_revision,"%u" );dev_add_param_int_ro (efi_bus.dev,"secure_boot" , secure_boot,"%d" );dev_add_param_int_ro (efi_bus.dev,"secure_mode" , - secure_boot & setup_mode,"%u" ); + secure_boot & !setup_mode,"%u" );
While a bitwise 'and' operator surely works with booleans here you should still use a logical 'and' operator here.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 3/5] efi: fix secure and setup mode report
Quoted 27 lines · Sascha Hauer
Quoted 26 lines · Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- drivers/efi/efi-device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/efi/efi-device.c +2
-2@@ -365,7 +365,7 @@ static int efi_is_secure_boot(void)free (val); } -return ret !=1 ; +return ret !=0 ; }static int efi_is_setup_mode (void )@@ -379,7 +379,7 @@ static int efi_is_setup_mode(void)free (val); } -return ret !=1 ; +return ret !=0 ; }
Quoted 10 lines
drivers/efi/efi-device.c static int efi_init_devices(void) · line 409
Quoted 7 lines
drivers/efi/efi-device.c +1
-1static int efi_init_devices (void )@@ -406,7 +406,7 @@ static int efi_init_devices(void)dev_add_param_int_ro (efi_bus.dev,"fw_revision" , efi_sys_table->fw_revision,"%u" );dev_add_param_int_ro (efi_bus.dev,"secure_boot" , secure_boot,"%d" );dev_add_param_int_ro (efi_bus.dev,"secure_mode" , - secure_boot & setup_mode,"%u" ); + secure_boot & !setup_mode,"%u" );While a bitwise 'and' operator surely works with booleans here you should still use a logical 'and' operator here.
ok
Best Regards,
J.
Quoted 8 lines
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH 4/5 boot: if we are in secure boot mode
In reply to Jean-Christophe PLAGNIOL-VILLARDrequest confirmation before booting an unsigned image
with a default timeout
--- commands/go.c | 7 +++++++ common/Kconfig | 8 ++++++++ common/Makefile | 1 + common/bootm.c | 7 +++++++ common/secure_boot.c | 43 +++++++++++++++++++++++++++++++++++++++++++ include/bootm.h | 1 + include/secure_boot.h | 25 +++++++++++++++++++++++++ 7 files changed, 92 insertions(+) create mode 100644 common/secure_boot.c create mode 100644 include/secure_boot.h
commands/go.c +7 -0
@@ -26,6 +26,7 @@#include <fcntl.h> #include <linux/ctype.h> #include <errno.h> +#include <secure_boot.h> static int do_go (int argc,char *argv[]) {
@@ -37,6 +38,12 @@ static int do_go(int argc, char *argv[])if (argc <2 )return COMMAND_ERROR_USAGE ; + rcode =secure_boot_start_unsigned (); +if (rcode) +return rcode ?1 :0 ; + + rcode =1 ; +if (!isdigit (*argv[1 ])) { fd =open (argv[1 ],O_RDONLY );if (fd <0 ) {
common/Kconfig +8 -0
@@ -21,6 +21,9 @@ config HAS_KALLSYMS config HAS_MODULES bool +config HAS_SECURE_BOOT + bool + config HAS_CACHE bool help
@@ -184,6 +187,11 @@ config NVVAR while global variables can be changed during runtime without changing the default. +config SECURE_BOOT_TIMEOUT + prompt "Secure Boot unsigned boot timeout" + int + default 3 + menu "memory layout" source "pbl/Kconfig"
common/Makefile +1 -0
@@ -61,6 +61,7 @@ obj-$(CONFIG_UBIFORMAT) += ubiformat.o obj-$(CONFIG_BAREBOX_UPDATE_IMX_NAND_FCB) += imx-bbu-nand-fcb.o obj-$(CONFIG_CONSOLE_RATP) += ratp.o obj-$(CONFIG_BOOT) += boot.o +obj-$(CONFIG_HAS_SECURE_BOOT) += secure_boot.o quiet_cmd_pwd_h = PWDH $@ ifdef CONFIG_PASSWORD
common/bootm.c +7 -0
@@ -23,6 +23,7 @@#include <environment.h> #include <linux/stat.h> #include <magicvar.h> +#include <secure_boot.h> static LIST_HEAD (handler_list);
@@ -625,6 +626,12 @@ int bootm_boot(struct bootm_data *bootm_data)printf ("Passing control to %s handler\n" , handler->name); } +if (!handler->is_secure_supported &&is_secure_mode ()) { + ret =secure_boot_start_unsigned (); +if (ret) + goto err_out; + } + ret = handler->bootm (data);if (data->dryrun)printf ("Dryrun. Aborted\n" );
common/secure_boot.c new file +43 -0
43 lines not on this page · raw message
include/bootm.h +1 -0
@@ -89,6 +89,7 @@ struct image_handler {struct list_head list;int ih_os; +int is_secure_supported;enum filetype filetype;int (*bootm)(struct image_data *data);
include/secure_boot.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Copyright (c) 2017 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> +* +* Under GPLv2 Only +*/ + +#ifndef __SECURE_BOOT_H__ +#define __SECURE_BOOT_H__ + +#ifdef CONFIG_HAS_SECURE_BOOT +int is_secure_mode (void ); +int secure_boot_start_unsigned (void ); +#else +static int inline is_secure_mode (void ) +{ +return 0 ; +} + +static int inline secure_boot_start_unsigned (void ) +{ +return 0 ; +} +#endif + +#endif /* __SECURE_BOOT_H__ */
Signature · 7 lines
2.11.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 4/5] boot: if we are in secure boot mode
Quoted 30 lines · Jean-Christophe PLAGNIOL-VILLARD
request confirmation before booting an unsigned image
with a default timeout
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- commands/go.c | 7 +++++++ common/Kconfig | 8 ++++++++ common/Makefile | 1 + common/bootm.c | 7 +++++++ common/secure_boot.c | 43 +++++++++++++++++++++++++++++++++++++++++++ include/bootm.h | 1 + include/secure_boot.h | 25 +++++++++++++++++++++++++ 7 files changed, 92 insertions(+) create mode 100644 common/secure_boot.c create mode 100644 include/secure_boot.hcommands/go.c +1
-0@@ -26,6 +26,7 @@#include <fcntl.h> #include <linux/ctype.h> #include <errno.h> +#include <secure_boot.h> static int do_go (int argc,char *argv[]) {
commands/go.c static int do_go(int argc, char *argv[]) · line 43
Quoted 6 lines
commands/go.c +3
-0@@ -37,6 +38,12 @@ static int do_go(int argc, char *argv[])if (argc <2 )return COMMAND_ERROR_USAGE ; + rcode =secure_boot_start_unsigned (); +if (rcode) +return rcode ?1 :0 ;
When rcode is true, then if rcode is true, return 1, otherwise return 0?
Quoted 78 lines
commands/go.c +3
-0+ + rcode =1 ; +if (!isdigit (*argv[1 ])) { fd =open (argv[1 ],O_RDONLY );if (fd <0 ) {common/Kconfig +8
-0@@ -21,6 +21,9 @@ config HAS_KALLSYMS config HAS_MODULES bool +config HAS_SECURE_BOOT + bool + config HAS_CACHE bool help@@ -184,6 +187,11 @@ config NVVAR while global variables can be changed during runtime without changing the default. +config SECURE_BOOT_TIMEOUT + prompt "Secure Boot unsigned boot timeout" + int + default 3 + menu "memory layout" source "pbl/Kconfig"common/Makefile +1
-0@@ -61,6 +61,7 @@ obj-$(CONFIG_UBIFORMAT) += ubiformat.o obj-$(CONFIG_BAREBOX_UPDATE_IMX_NAND_FCB) += imx-bbu-nand-fcb.o obj-$(CONFIG_CONSOLE_RATP) += ratp.o obj-$(CONFIG_BOOT) += boot.o +obj-$(CONFIG_HAS_SECURE_BOOT) += secure_boot.o quiet_cmd_pwd_h = PWDH $@ ifdef CONFIG_PASSWORDcommon/bootm.c +7
-0@@ -23,6 +23,7 @@#include <environment.h> #include <linux/stat.h> #include <magicvar.h> +#include <secure_boot.h> static LIST_HEAD (handler_list);@@ -625,6 +626,12 @@ int bootm_boot(struct bootm_data *bootm_data)printf ("Passing control to %s handler\n" , handler->name); } +if (!handler->is_secure_supported &&is_secure_mode ()) { + ret =secure_boot_start_unsigned (); +if (ret) + goto err_out; + } + ret = handler->bootm (data);if (data->dryrun)printf ("Dryrun. Aborted\n" );common/secure_boot.c new file +3
-0@@ -0,0 +1,43 @@ +/* +* Copyright (c) 2017 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> +*
common/secure_boot.c line 13
Quoted 10 lines
common/secure_boot.c new file +10
-0+* Under GPLv2 Only +*/ +#include <common.h> +#include <secure_boot.h> +#include <console_countdown.h> +#include <globalvar.h> +#include <magicvar.h> +#include <init.h> + +static unsigned int sb_confirm_timeout =CONFIG_SECURE_BOOT_TIMEOUT ;
Use globalvar_add_simple_int instead of putting this into the config.
common/secure_boot.c line 15
Quoted 2 lines
common/secure_boot.c new file +2
-0+ +int secure_boot_start_unsigned (void )
This function name is very misleading. It sounds like it starts an unsigned image, but this function doesn't start anything. Second guess is that it returns a boolean whether it's allowed to start an unsigned image, but actually it returns the opposite.
common/secure_boot.c line 28
Quoted 13 lines
common/secure_boot.c new file +13
-0+{ +int ret; +char str[2 ] = { }; +int timeout = sb_confirm_timeout; + +if (!is_secure_mode ()) +return 0 ; + +printf ("Are you sure you wish to run an unsigned binary\n" ); +printf ("in a secure environment?\n" ); +printf ("press y to confirm\n" ); + + ret =console_countdown (timeout,CONSOLE_COUNTDOWN_ANYKEY , str);
console_countdown puts exactly one character in *str, no need to pass an array.
common/secure_boot.c line 39
Quoted 11 lines
common/secure_boot.c new file +11
-0+if (ret != -EINTR ) +return -EINVAL ; + +return str[0 ] =='y' ?0 : -EINVAL ; +} + +static int init_sb_confirm_timeout (void ) +{ +return globalvar_add_simple_int ("sb.confirm_timeout" , + &sb_confirm_timeout,"%u" ); +}
Ok, you already made it a globalvar. No need to put the default into kconfig then.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 4/5] boot: if we are in secure boot mode
Quoted 34 lines · Sascha Hauer
Quoted 33 lines · Jean-Christophe PLAGNIOL-VILLARD
request confirmation before booting an unsigned image
with a default timeout
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- commands/go.c | 7 +++++++ common/Kconfig | 8 ++++++++ common/Makefile | 1 + common/bootm.c | 7 +++++++ common/secure_boot.c | 43 +++++++++++++++++++++++++++++++++++++++++++ include/bootm.h | 1 + include/secure_boot.h | 25 +++++++++++++++++++++++++ 7 files changed, 92 insertions(+) create mode 100644 common/secure_boot.c create mode 100644 include/secure_boot.hcommands/go.c +1
-0@@ -26,6 +26,7 @@#include <fcntl.h> #include <linux/ctype.h> #include <errno.h> +#include <secure_boot.h> static int do_go (int argc,char *argv[]) {@@ -37,6 +38,12 @@ static int do_go(int argc, char *argv[])if (argc <2 )return COMMAND_ERROR_USAGE ;
Quoted 5 lines
commands/go.c static int do_go(int argc, char *argv[]) · line 43
Quoted 3 lines
commands/go.c +3
-0+ rcode =secure_boot_start_unsigned (); +if (rcode) +return rcode ?1 :0 ;When rcode is true, then if rcode is true, return 1, otherwise return 0?
I forget we could return a negative error on command too
Quoted 92 lines
Quoted 79 lines
commands/go.c +3
-0+ + rcode =1 ; +if (!isdigit (*argv[1 ])) { fd =open (argv[1 ],O_RDONLY );if (fd <0 ) {common/Kconfig +8
-0@@ -21,6 +21,9 @@ config HAS_KALLSYMS config HAS_MODULES bool +config HAS_SECURE_BOOT + bool + config HAS_CACHE bool help@@ -184,6 +187,11 @@ config NVVAR while global variables can be changed during runtime without changing the default. +config SECURE_BOOT_TIMEOUT + prompt "Secure Boot unsigned boot timeout" + int + default 3 + menu "memory layout" source "pbl/Kconfig"common/Makefile +1
-0@@ -61,6 +61,7 @@ obj-$(CONFIG_UBIFORMAT) += ubiformat.o obj-$(CONFIG_BAREBOX_UPDATE_IMX_NAND_FCB) += imx-bbu-nand-fcb.o obj-$(CONFIG_CONSOLE_RATP) += ratp.o obj-$(CONFIG_BOOT) += boot.o +obj-$(CONFIG_HAS_SECURE_BOOT) += secure_boot.o quiet_cmd_pwd_h = PWDH $@ ifdef CONFIG_PASSWORDcommon/bootm.c +7
-0@@ -23,6 +23,7 @@#include <environment.h> #include <linux/stat.h> #include <magicvar.h> +#include <secure_boot.h> static LIST_HEAD (handler_list);@@ -625,6 +626,12 @@ int bootm_boot(struct bootm_data *bootm_data)printf ("Passing control to %s handler\n" , handler->name); } +if (!handler->is_secure_supported &&is_secure_mode ()) { + ret =secure_boot_start_unsigned (); +if (ret) + goto err_out; + } + ret = handler->bootm (data);if (data->dryrun)printf ("Dryrun. Aborted\n" );common/secure_boot.c new file +3
-0@@ -0,0 +1,43 @@ +/* +* Copyright (c) 2017 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> +* common/secure_boot.c line 13
Quoted 10 lines
common/secure_boot.c new file +10
-0+* Under GPLv2 Only +*/ +#include <common.h> +#include <secure_boot.h> +#include <console_countdown.h> +#include <globalvar.h> +#include <magicvar.h> +#include <init.h> + +static unsigned int sb_confirm_timeout =CONFIG_SECURE_BOOT_TIMEOUT ;Use
globalvar_add_simple_intinstead of putting this into the config.
Quoted 7 lines
common/secure_boot.c line 15
Quoted 2 lines
common/secure_boot.c new file +2
-0+ +int secure_boot_start_unsigned (void )This function name is very misleading. It sounds like it starts an unsigned image, but this function doesn't start anything. Second guess is that it returns a boolean whether it's allowed to start an unsigned image, but actually it returns the opposite.
secure_boot_can_start_unsigned could be better
it return 0 if ok
an error otherwise
as we can return an security violation or other error
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 4/5] boot: if we are in secure boot mode
In reply to Jean-Christophe PLAGNIOL-VILLARDQuoted 93 lines · Jean-Christophe PLAGNIOL-VILLARD
request confirmation before booting an unsigned image
with a default timeout
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- commands/go.c | 7 +++++++ common/Kconfig | 8 ++++++++ common/Makefile | 1 + common/bootm.c | 7 +++++++ common/secure_boot.c | 43 +++++++++++++++++++++++++++++++++++++++++++ include/bootm.h | 1 + include/secure_boot.h | 25 +++++++++++++++++++++++++ 7 files changed, 92 insertions(+) create mode 100644 common/secure_boot.c create mode 100644 include/secure_boot.hcommands/go.c +7
-0@@ -26,6 +26,7 @@#include <fcntl.h> #include <linux/ctype.h> #include <errno.h> +#include <secure_boot.h> static int do_go (int argc,char *argv[]) {@@ -37,6 +38,12 @@ static int do_go(int argc, char *argv[])if (argc <2 )return COMMAND_ERROR_USAGE ; + rcode =secure_boot_start_unsigned (); +if (rcode) +return rcode ?1 :0 ; + + rcode =1 ; +if (!isdigit (*argv[1 ])) { fd =open (argv[1 ],O_RDONLY );if (fd <0 ) {common/Kconfig +8
-0@@ -21,6 +21,9 @@ config HAS_KALLSYMS config HAS_MODULES bool +config HAS_SECURE_BOOT + bool + config HAS_CACHE bool help@@ -184,6 +187,11 @@ config NVVAR while global variables can be changed during runtime without changing the default. +config SECURE_BOOT_TIMEOUT + prompt "Secure Boot unsigned boot timeout" + int + default 3 + menu "memory layout" source "pbl/Kconfig"common/Makefile +1
-0@@ -61,6 +61,7 @@ obj-$(CONFIG_UBIFORMAT) += ubiformat.o obj-$(CONFIG_BAREBOX_UPDATE_IMX_NAND_FCB) += imx-bbu-nand-fcb.o obj-$(CONFIG_CONSOLE_RATP) += ratp.o obj-$(CONFIG_BOOT) += boot.o +obj-$(CONFIG_HAS_SECURE_BOOT) += secure_boot.o quiet_cmd_pwd_h = PWDH $@ ifdef CONFIG_PASSWORDcommon/bootm.c +1
-0@@ -23,6 +23,7 @@#include <environment.h> #include <linux/stat.h> #include <magicvar.h> +#include <secure_boot.h> static LIST_HEAD (handler_list);
common/bootm.c int bootm_boot(struct bootm_data *bootm_data) · line 633
Quoted 8 lines
common/bootm.c +5
-0@@ -625,6 +626,12 @@ int bootm_boot(struct bootm_data *bootm_data)printf ("Passing control to %s handler\n" , handler->name); } +if (!handler->is_secure_supported &&is_secure_mode ()) { + ret =secure_boot_start_unsigned (); +if (ret) + goto err_out; + }
We already have CONFIG_BOOTM_FORCE_SIGNED_IMAGES which admittedly is not the most generic implementation, but in the end we shouldn't have two different ways how secure boot is integrated in the bootm code.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 4/5] boot: if we are in secure boot mode
Quoted 97 lines · Sascha Hauer
Quoted 96 lines · Jean-Christophe PLAGNIOL-VILLARD
request confirmation before booting an unsigned image
with a default timeout
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- commands/go.c | 7 +++++++ common/Kconfig | 8 ++++++++ common/Makefile | 1 + common/bootm.c | 7 +++++++ common/secure_boot.c | 43 +++++++++++++++++++++++++++++++++++++++++++ include/bootm.h | 1 + include/secure_boot.h | 25 +++++++++++++++++++++++++ 7 files changed, 92 insertions(+) create mode 100644 common/secure_boot.c create mode 100644 include/secure_boot.hcommands/go.c +7
-0@@ -26,6 +26,7 @@#include <fcntl.h> #include <linux/ctype.h> #include <errno.h> +#include <secure_boot.h> static int do_go (int argc,char *argv[]) {@@ -37,6 +38,12 @@ static int do_go(int argc, char *argv[])if (argc <2 )return COMMAND_ERROR_USAGE ; + rcode =secure_boot_start_unsigned (); +if (rcode) +return rcode ?1 :0 ; + + rcode =1 ; +if (!isdigit (*argv[1 ])) { fd =open (argv[1 ],O_RDONLY );if (fd <0 ) {common/Kconfig +8
-0@@ -21,6 +21,9 @@ config HAS_KALLSYMS config HAS_MODULES bool +config HAS_SECURE_BOOT + bool + config HAS_CACHE bool help@@ -184,6 +187,11 @@ config NVVAR while global variables can be changed during runtime without changing the default. +config SECURE_BOOT_TIMEOUT + prompt "Secure Boot unsigned boot timeout" + int + default 3 + menu "memory layout" source "pbl/Kconfig"common/Makefile +1
-0@@ -61,6 +61,7 @@ obj-$(CONFIG_UBIFORMAT) += ubiformat.o obj-$(CONFIG_BAREBOX_UPDATE_IMX_NAND_FCB) += imx-bbu-nand-fcb.o obj-$(CONFIG_CONSOLE_RATP) += ratp.o obj-$(CONFIG_BOOT) += boot.o +obj-$(CONFIG_HAS_SECURE_BOOT) += secure_boot.o quiet_cmd_pwd_h = PWDH $@ ifdef CONFIG_PASSWORDcommon/bootm.c +1
-0@@ -23,6 +23,7 @@#include <environment.h> #include <linux/stat.h> #include <magicvar.h> +#include <secure_boot.h> static LIST_HEAD (handler_list);@@ -625,6 +626,12 @@ int bootm_boot(struct bootm_data *bootm_data)printf ("Passing control to %s handler\n" , handler->name); }
Quoted 9 lines
common/bootm.c int bootm_boot(struct bootm_data *bootm_data) · line 633
Quoted 5 lines
common/bootm.c +5
-0+if (!handler->is_secure_supported &&is_secure_mode ()) { + ret =secure_boot_start_unsigned (); +if (ret) + goto err_out; + }We already have
CONFIG_BOOTM_FORCE_SIGNED_IMAGESwhich admittedly is not the most generic implementation, but in the end we shouldn't have two different ways how secure boot is integrated in the bootm code.
Did not seen it
I check it and this is only for BOOTM as we have go command too
that need to call image check too
and on efi this is not done at config time but runtime
and this is really FIT image oriented :(
Can we have one for EFI sperately first and then merge them as this will need a lot of testing and checking to ensure we break nothing
Best Regards,
J.
Quoted 8 lines
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 4/5] boot: if we are in secure boot mode
Quoted 109 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 97 lines · Sascha Hauer
Quoted 96 lines · Jean-Christophe PLAGNIOL-VILLARD
request confirmation before booting an unsigned image
with a default timeout
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- commands/go.c | 7 +++++++ common/Kconfig | 8 ++++++++ common/Makefile | 1 + common/bootm.c | 7 +++++++ common/secure_boot.c | 43 +++++++++++++++++++++++++++++++++++++++++++ include/bootm.h | 1 + include/secure_boot.h | 25 +++++++++++++++++++++++++ 7 files changed, 92 insertions(+) create mode 100644 common/secure_boot.c create mode 100644 include/secure_boot.hcommands/go.c +7
-0@@ -26,6 +26,7 @@#include <fcntl.h> #include <linux/ctype.h> #include <errno.h> +#include <secure_boot.h> static int do_go (int argc,char *argv[]) {@@ -37,6 +38,12 @@ static int do_go(int argc, char *argv[])if (argc <2 )return COMMAND_ERROR_USAGE ; + rcode =secure_boot_start_unsigned (); +if (rcode) +return rcode ?1 :0 ; + + rcode =1 ; +if (!isdigit (*argv[1 ])) { fd =open (argv[1 ],O_RDONLY );if (fd <0 ) {common/Kconfig +8
-0@@ -21,6 +21,9 @@ config HAS_KALLSYMS config HAS_MODULES bool +config HAS_SECURE_BOOT + bool + config HAS_CACHE bool help@@ -184,6 +187,11 @@ config NVVAR while global variables can be changed during runtime without changing the default. +config SECURE_BOOT_TIMEOUT + prompt "Secure Boot unsigned boot timeout" + int + default 3 + menu "memory layout" source "pbl/Kconfig"common/Makefile +1
-0@@ -61,6 +61,7 @@ obj-$(CONFIG_UBIFORMAT) += ubiformat.o obj-$(CONFIG_BAREBOX_UPDATE_IMX_NAND_FCB) += imx-bbu-nand-fcb.o obj-$(CONFIG_CONSOLE_RATP) += ratp.o obj-$(CONFIG_BOOT) += boot.o +obj-$(CONFIG_HAS_SECURE_BOOT) += secure_boot.o quiet_cmd_pwd_h = PWDH $@ ifdef CONFIG_PASSWORDcommon/bootm.c +1
-0@@ -23,6 +23,7 @@#include <environment.h> #include <linux/stat.h> #include <magicvar.h> +#include <secure_boot.h> static LIST_HEAD (handler_list);@@ -625,6 +626,12 @@ int bootm_boot(struct bootm_data *bootm_data)printf ("Passing control to %s handler\n" , handler->name); }Quoted 9 lines
common/bootm.c int bootm_boot(struct bootm_data *bootm_data) · line 633
Quoted 5 lines
common/bootm.c +5
-0+if (!handler->is_secure_supported &&is_secure_mode ()) { + ret =secure_boot_start_unsigned (); +if (ret) + goto err_out; + }We already have
CONFIG_BOOTM_FORCE_SIGNED_IMAGESwhich admittedly is not the most generic implementation, but in the end we shouldn't have two different ways how secure boot is integrated in the bootm code.Did not seen it
Quoted 7 lines
I check it and this is only for BOOTM as we have go command too
that need to call image check too
and on efi this is not done at config time but runtime
and this is really FIT image oriented :(
You have the handler->is_secure_supported variable. This could be implemented by the FIT image support aswell. Also we have the decision if we want to boot unsigned images. Right now this is done in the data->verify variable. We can force the decision in Kconfig using CONFIG_BOOTM_FORCE_SIGNED_IMAGES or we can fill in data->verify before booting.
Quoted 3 lines
Can we have one for EFI sperately first and then merge them as this will need a lot of testing and checking to ensure we break nothing
No. It's just too confusing to implement two different secure boot ways in the same code and I give nothing to the promise that this will be cleaned up later.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 5/5 efi: enable sercure boot support
In reply to Jean-Christophe PLAGNIOL-VILLARDThis will ensure that we just start secured binary without user confirmation
But for now on we only support EFI correctly signed image to start Later will allow both.
--- arch/x86/Kconfig | 1 + common/efi/efi-image.c | 1 + drivers/efi/efi-device.c | 9 +++++++++ 3 files changed, 11 insertions(+)
arch/x86/Kconfig +1 -0
@@ -78,6 +78,7 @@ choice select EFI_DEVICEPATH select PRINTF_UUID select CLOCKSOURCE_EFI_X86 + select HAS_SECURE_BOOT config X86_BIOS_BRINGUP bool "16 bit BIOS"
common/efi/efi-image.c +1 -0
@@ -270,6 +270,7 @@ static int do_bootm_efi(struct image_data *data)static struct image_handler efi_handle_tr = { .name ="EFI Application" , .bootm = do_bootm_efi, + .is_secure_supported =1 , .filetype = filetype_exe, };
drivers/efi/efi-device.c +9 -0
@@ -26,6 +26,7 @@#include <linux/sizes.h> #include <wchar.h> #include <init.h> +#include <secure_boot.h> #include <efi.h> #include <efi/efi.h> #include <efi/efi-device.h>
@@ -382,6 +383,14 @@ static int efi_is_setup_mode(void)return ret !=0 ; } +int is_secure_mode (void ) +{ +int secure_boot =efi_is_secure_boot (); +int setup_mode =efi_is_setup_mode (); + +return secure_boot & !setup_mode; +} +static int efi_init_devices (void ) {char *fw_vendor =NULL ;
Signature · 7 lines
2.11.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox