x86/boot: Add the secdata section to the setup header
RFC PATCH 1/1 x86/boot: Add the secdata section to the setup header
This is a different approach to replace my previous implementation of Security Version(*). Instead of using the fields in the PE/COFF header, this commit adds secdata_offset in the setup header for the file offset of secdata. Currently, the secdata section contains the signer's name, the distro version, and the security version as defined in the wiki page. Since we don't rely on the PE/COFF header anymore, the size of signer is increased to 8 bytes to store more characters.
Since this is just a tentative patch, I haven't started the other parts (shim and mokutil) yet, and it's flexible to change. Any comment and suggestion are welcome.
(*) https://github.com/lcp/shim/wiki/Security-Version
--- arch/x86/Kconfig | 14 ++++++++++++++ arch/x86/boot/header.S | 15 ++++++++++++++- arch/x86/boot/setup.ld | 1 + arch/x86/boot/tools/build.c | 11 +++++++++++ arch/x86/include/uapi/asm/bootparam.h | 1 + 5 files changed, 41 insertions(+), 1 deletion(-)
arch/x86/Kconfig +14 -0
@@ -1817,6 +1817,20 @@ config EFI_MIXED If unsure, say N. +config SEC_SIGNER + string "The signer name" + default "none" + +config SEC_DISTRO + int "The distro version" + default 0 + range 0 65535 + +config SEC_VERSION + int "The security version" + default 0 + range 0 65535 + config SECCOMP def_bool y prompt "Enable seccomp to safely compute untrusted bytecode"
arch/x86/boot/header.S +14 -1
@@ -301,7 +301,7 @@ _start: # Part 2 of the header, from the old setup.S .ascii "HdrS" # header signature - .word 0x020d # header version number (>= 0x0105) + .word 0x020e # header version number (>= 0x0105) # or else old loadlin-1.5 will fail) .globl realmode_swtch realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
@@ -552,6 +552,7 @@ pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr init_size: .long INIT_SIZE # kernel initialization size handover_offset: .long 0 # Filled in by build.c +secdata_offset: .long secdata_start # End of setup header #####################################################
@@ -629,3 +630,15 @@ die: setup_corrupt: .byte 7 .string "No setup signature found...\n" + + .section ".secdata", "a" +secdata_start: +sec_length: + .long secdata_end - secdata_start +sec_signer: + .quad 0 # Filled by build.c +sec_distro: + .word CONFIG_SEC_DISTRO +sec_version: + .word CONFIG_SEC_VERSION +secdata_end:
arch/x86/boot/setup.ld +1 -0
@@ -18,6 +18,7 @@ SECTIONS .entrytext : { *(.entrytext) } .inittext : { *(.inittext) } .initdata : { *(.initdata) } + .secdata : { *(.secdata) } __end_init = .; .text : { *(.text) }
arch/x86/boot/tools/build.c +11 -0
@@ -287,6 +287,15 @@ static inline int reserve_pecoff_reloc_section(int c) }#endif /* CONFIG_EFI_STUB */ +static void security_fields_update (void ) +{ +unsigned int security_offset; +char *dest; + + security_offset =get_unaligned_le32 (&buf[0x268 ]); + dest = (char *)&buf[security_offset +4 ]; +strncpy (dest,CONFIG_SEC_SIGNER ,8 ); +}/* * Parse zoffset.h and find the entry points. We could just #include zoffset.h
@@ -401,6 +410,8 @@ int main(int argc, char ** argv)efi_stub_entry_update (); +security_fields_update (); + crc =partial_crc32 (buf, i, crc);if (fwrite (buf,1 , i, dest) != i)die ("Writing setup failed" );
arch/x86/include/uapi/asm/bootparam.h +1 -0
@@ -85,6 +85,7 @@ struct setup_header {__u64 pref_address;__u32 init_size;__u32 handover_offset; +__u32 secdata_offset; } __attribute__((packed));struct sys_desc_table {
Signature · 1 line
2.12.2
[email protected]
reviewerQuoted 143 lines · Gary Lin
This is a different approach to replace my previous implementation of Security
Version(*). Instead of using the fields in the PE/COFF header, this commit addssecdata_offsetin the setup header for the file offset of secdata. Currently, the secdata section contains the signer's name, the distro version, and the security version as defined in the wiki page.
Since we don't rely on the PE/COFF header anymore, the size of signer is
increased to 8 bytes to store more characters.Since this is just a tentative patch, I haven't started the other parts (shim and mokutil) yet, and it's flexible to change. Any comment and suggestion are welcome.
(*) https://github.com/lcp/shim/wiki/Security-Version
Cc Ard Biesheuvel <[email protected]>Cc "H. Peter Anvin" <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Joey Lee <[email protected]>Signed-off-by Gary Lin <[email protected]>---
arch/x86/Kconfig | 14 ++++++++++++++ arch/x86/boot/header.S | 15 ++++++++++++++- arch/x86/boot/setup.ld | 1 + arch/x86/boot/tools/build.c | 11 +++++++++++ arch/x86/include/uapi/asm/bootparam.h | 1 + 5 files changed, 41 insertions(+), 1 deletion(-)arch/x86/Kconfig +14
-0@@ -1817,6 +1817,20 @@ config EFI_MIXED If unsure, say N. +config SEC_SIGNER + string "The signer name" + default "none" + +config SEC_DISTRO + int "The distro version" + default 0 + range 0 65535 + +config SEC_VERSION + int "The security version" + default 0 + range 0 65535 +config SECCOMP
def_booly
prompt "Enable seccomp to safely compute untrusted bytecode"arch/x86/boot/header.S +1
-1@@ -301,7 +301,7 @@ _start: # Part 2 of the header, from the old setup.S .ascii "HdrS" # header signature - .word 0x020d # header version number (>= 0x0105) + .word 0x020e # header version number (>= 0x0105) # or else old loadlin-1.5 will fail) .globl realmode_swtch
realmode_swtch: .word 0, 0 #default_switch, SETUPSEGarch/x86/boot/header.S +0
-0@@ -552,6 +552,7 @@ pref_address: .quad LOAD_PHYSICAL_ADDR # preferredload addr
init_size: .longINIT_SIZE# kernel initialization sizehandover_offset: .long 0 # Filled in bybuild.c
+secdata_offset: .longsecdata_start# End of setup header
#####################################################arch/x86/boot/header.S +0
-0@@ -629,3 +630,15 @@ die:
setup_corrupt:.byte 7 .string "No setup signature found...\n"arch/x86/boot/header.S +12
-0+ + .section ".secdata", "a" +secdata_start: +sec_length: + .long secdata_end - secdata_start +sec_signer: + .quad 0 # Filled by build.c +sec_distro: + .word CONFIG_SEC_DISTRO +sec_version: + .word CONFIG_SEC_VERSION +secdata_end:arch/x86/boot/setup.ld +1
-0@@ -18,6 +18,7 @@ SECTIONS .entrytext : { *(.entrytext) } .inittext : { *(.inittext) } .initdata : { *(.initdata) } + .secdata : { *(.secdata) } __end_init = .; .text : { *(.text) }arch/x86/boot/tools/build.c +9
-0@@ -287,6 +287,15 @@ static inline int reserve_pecoff_reloc_section(int c) }#endif /* CONFIG_EFI_STUB */ +static void security_fields_update (void ) +{ +unsigned int security_offset; +char *dest; + + security_offset =get_unaligned_le32 (&buf[0x268 ]); + dest = (char *)&buf[security_offset +4 ]; +strncpy (dest,CONFIG_SEC_SIGNER ,8 ); +}/* * Parse
zoffset.hand find the entry points. We could just #includezoffset.harch/x86/boot/tools/build.c +2
-0@@ -401,6 +410,8 @@ int main(int argc, char ** argv)efi_stub_entry_update (); +security_fields_update (); + crc =partial_crc32 (buf, i, crc);if (fwrite (buf,1 , i, dest) != i)die ("Writing setup failed" );arch/x86/include/uapi/asm/bootparam.h +0
-0
arch/x86/include/uapi/asm/bootparam.h struct setup_header { · line 91
Quoted 7 lines
arch/x86/include/uapi/asm/bootparam.h +1
-0@@ -85,6 +85,7 @@ struct setup_header {__u64 pref_address;__u32 init_size;__u32 handover_offset; +__u32 secdata_offset; } __attribute__((packed));struct sys_desc_table {
There is no need to burn a 4-byte field if this is inside the setup area, as that is limited to ~32K anyway. Since this structure is a static ABI, it should have a way to grow it (a length field is usually a good choice.)
What are the semantics of these fields? If they are supposed to be distribution-independent, they need semantics defined, otherwise they might better be a distro-specific use field.
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Quoted 150 lines · On Sat, May 06, 2017 at 01:12:10AM -0700, [email protected] wrote:
Quoted 149 lines · Gary Lin
This is a different approach to replace my previous implementation of Security
Version(*). Instead of using the fields in the PE/COFF header, this commit addssecdata_offsetin the setup header for the file offset of secdata. Currently, the secdata section contains the signer's name, the distro version, and the security version as defined in the wiki page.
Since we don't rely on the PE/COFF header anymore, the size of signer is
increased to 8 bytes to store more characters.Since this is just a tentative patch, I haven't started the other parts (shim and mokutil) yet, and it's flexible to change. Any comment and suggestion are welcome.
(*) https://github.com/lcp/shim/wiki/Security-Version
Cc Ard Biesheuvel <[email protected]>Cc "H. Peter Anvin" <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Joey Lee <[email protected]>Signed-off-by Gary Lin <[email protected]>---
arch/x86/Kconfig | 14 ++++++++++++++ arch/x86/boot/header.S | 15 ++++++++++++++- arch/x86/boot/setup.ld | 1 + arch/x86/boot/tools/build.c | 11 +++++++++++ arch/x86/include/uapi/asm/bootparam.h | 1 + 5 files changed, 41 insertions(+), 1 deletion(-)arch/x86/Kconfig +14
-0@@ -1817,6 +1817,20 @@ config EFI_MIXED If unsure, say N. +config SEC_SIGNER + string "The signer name" + default "none" + +config SEC_DISTRO + int "The distro version" + default 0 + range 0 65535 + +config SEC_VERSION + int "The security version" + default 0 + range 0 65535 +config SECCOMP
def_booly
prompt "Enable seccomp to safely compute untrusted bytecode"arch/x86/boot/header.S +1
-1@@ -301,7 +301,7 @@ _start: # Part 2 of the header, from the old setup.S .ascii "HdrS" # header signature - .word 0x020d # header version number (>= 0x0105) + .word 0x020e # header version number (>= 0x0105) # or else old loadlin-1.5 will fail) .globl realmode_swtch
realmode_swtch: .word 0, 0 #default_switch, SETUPSEGarch/x86/boot/header.S +0
-0@@ -552,6 +552,7 @@ pref_address: .quad LOAD_PHYSICAL_ADDR # preferredload addr
init_size: .longINIT_SIZE# kernel initialization sizehandover_offset: .long 0 # Filled in bybuild.c
+secdata_offset: .longsecdata_start# End of setup header
#####################################################arch/x86/boot/header.S +0
-0@@ -629,3 +630,15 @@ die:
setup_corrupt:.byte 7 .string "No setup signature found...\n"arch/x86/boot/header.S +12
-0+ + .section ".secdata", "a" +secdata_start: +sec_length: + .long secdata_end - secdata_start +sec_signer: + .quad 0 # Filled by build.c +sec_distro: + .word CONFIG_SEC_DISTRO +sec_version: + .word CONFIG_SEC_VERSION +secdata_end:arch/x86/boot/setup.ld +1
-0@@ -18,6 +18,7 @@ SECTIONS .entrytext : { *(.entrytext) } .inittext : { *(.inittext) } .initdata : { *(.initdata) } + .secdata : { *(.secdata) } __end_init = .; .text : { *(.text) }arch/x86/boot/tools/build.c +9
-0@@ -287,6 +287,15 @@ static inline int reserve_pecoff_reloc_section(int c) }#endif /* CONFIG_EFI_STUB */ +static void security_fields_update (void ) +{ +unsigned int security_offset; +char *dest; + + security_offset =get_unaligned_le32 (&buf[0x268 ]); + dest = (char *)&buf[security_offset +4 ]; +strncpy (dest,CONFIG_SEC_SIGNER ,8 ); +}/* * Parse
zoffset.hand find the entry points. We could just #includezoffset.harch/x86/boot/tools/build.c +2
-0@@ -401,6 +410,8 @@ int main(int argc, char ** argv)efi_stub_entry_update (); +security_fields_update (); + crc =partial_crc32 (buf, i, crc);if (fwrite (buf,1 , i, dest) != i)die ("Writing setup failed" );arch/x86/include/uapi/asm/bootparam.h +1
-0@@ -85,6 +85,7 @@ struct setup_header {__u64 pref_address;__u32 init_size;__u32 handover_offset; +__u32 secdata_offset; } __attribute__((packed));
Quoted 3 lines
arch/x86/include/uapi/asm/bootparam.h struct setup_header { · line 91
Quoted 1 line
arch/x86/include/uapi/asm/bootparam.h +0
-0struct sys_desc_table {There is no need to burn a 4-byte field if this is inside the setup area, as that is limited to ~32K anyway.
Right, 2-byte is enough for secdata_offset.
Quoted 2 lines
Since this structure is a static ABI, it should have a way to grow it (a length field is usually a good choice.)
sec_length serves for the purpose. It's the length of the secdata section, so we can use it to determine if there is a new field.
Quoted 2 lines
What are the semantics of these fields? If they are supposed to be distribution-independent, they need semantics defined, otherwise they might better be a distro-specific use field.
They are all distro-specific.
sec_signer is basically the distro name. sec_distro is the distro version. sec_version is the "Security Version" defined by the distro. If grub2 is booting a "less-secure" kernel, i.e. a kernel with a lower Security Version, a warning will show to notify the user.
Cheers,
Gary Lin
Quoted 75 lines · Gary Lin
This is a different approach to replace my previous implementation of Security
Version(*). Instead of using the fields in the PE/COFF header, this commit addssecdata_offsetin the setup header for the file offset of secdata. Currently, the secdata section contains the signer's name, the distro version, and the security version as defined in the wiki page. Since we don't rely on the PE/COFF header anymore, the size of signer is increased to 8 bytes to store more characters.Since this is just a tentative patch, I haven't started the other parts (shim and mokutil) yet, and it's flexible to change. Any comment and suggestion are welcome.
(*) https://github.com/lcp/shim/wiki/Security-Version
Cc Ard Biesheuvel <[email protected]>Cc "H. Peter Anvin" <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Joey Lee <[email protected]>Signed-off-by Gary Lin <[email protected]>--- arch/x86/Kconfig | 14 ++++++++++++++ arch/x86/boot/header.S | 15 ++++++++++++++- arch/x86/boot/setup.ld | 1 + arch/x86/boot/tools/build.c | 11 +++++++++++ arch/x86/include/uapi/asm/bootparam.h | 1 + 5 files changed, 41 insertions(+), 1 deletion(-)arch/x86/Kconfig +14
-0@@ -1817,6 +1817,20 @@ config EFI_MIXED If unsure, say N. +config SEC_SIGNER + string "The signer name" + default "none" + +config SEC_DISTRO + int "The distro version" + default 0 + range 0 65535 + +config SEC_VERSION + int "The security version" + default 0 + range 0 65535 + config SECCOMP def_bool y prompt "Enable seccomp to safely compute untrusted bytecode"arch/x86/boot/header.S +2
-1@@ -301,7 +301,7 @@ _start: # Part 2 of the header, from the old setup.S .ascii "HdrS" # header signature - .word 0x020d # header version number (>= 0x0105) + .word 0x020e # header version number (>= 0x0105) # or else old loadlin-1.5 will fail) .globl realmode_swtch realmode_swtch: .word 0, 0 # default_switch, SETUPSEG@@ -552,6 +552,7 @@ pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr init_size: .long INIT_SIZE # kernel initialization size handover_offset: .long 0 # Filled in by build.c +secdata_offset: .long secdata_start # End of setup header #####################################################
arch/x86/boot/header.S die: · line 639
Quoted 10 lines
arch/x86/boot/header.S +7
-0@@ -629,3 +630,15 @@ die: setup_corrupt: .byte 7 .string "No setup signature found...\n" + + .section ".secdata", "a" +secdata_start: +sec_length: + .long secdata_end - secdata_start +sec_signer: + .quad 0 # Filled by build.c
A more flexible way to do this would be to make sec_signer an offset to a null-terminated string. That way it can be any length, and you wouldn't need the build tool hack.
--
Brian Gerst
[email protected]
reviewerQuoted 105 lines · Brian Gerst
Quoted 2 lines · Gary Lin
This is a different approach to replace my previous implementation of Security
Version(*). Instead of using the fields in the PE/COFFheader,
Quoted 1 line
this commit adds
secdata_offsetin the setup header for the fileoffset
Quoted 1 line
of secdata. Currently, the secdata section contains the signer's
name,
Quoted 1 line
the distro version, and the security version as defined in the wiki
page.
Quoted 1 line
Since we don't rely on the PE/COFF header anymore, the size of signer
is
Quoted 3 lines
increased to 8 bytes to store more characters.
Since this is just a tentative patch, I haven't started the other
parts
Quoted 49 lines
(shim and mokutil) yet, and it's flexible to change. Any comment and suggestion are welcome.
(*) https://github.com/lcp/shim/wiki/Security-Version
Cc Ard Biesheuvel <[email protected]>Cc "H. Peter Anvin" <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Joey Lee <[email protected]>Signed-off-by Gary Lin <[email protected]>--- arch/x86/Kconfig | 14 ++++++++++++++ arch/x86/boot/header.S | 15 ++++++++++++++- arch/x86/boot/setup.ld | 1 + arch/x86/boot/tools/build.c | 11 +++++++++++ arch/x86/include/uapi/asm/bootparam.h | 1 + 5 files changed, 41 insertions(+), 1 deletion(-)arch/x86/Kconfig +14
-0@@ -1817,6 +1817,20 @@ config EFI_MIXED If unsure, say N. +config SEC_SIGNER + string "The signer name" + default "none" + +config SEC_DISTRO + int "The distro version" + default 0 + range 0 65535 + +config SEC_VERSION + int "The security version" + default 0 + range 0 65535 + config SECCOMP def_bool y prompt "Enable seccomp to safely compute untrusted bytecode"arch/x86/boot/header.S +0
-0arch/x86/boot/header.S _start: · line 304
Quoted 4 lines
arch/x86/boot/header.S +0
-1@@ -301,7 +301,7 @@ _start: # Part 2 of the header, from the old setup.S .ascii "HdrS" # header signature - .word 0x020d # header version number (>=
0x0105)arch/x86/boot/header.S _start: · line 304
Quoted 1 line
arch/x86/boot/header.S +1
-0+ .word 0x020e # header version number (>=
0x0105)arch/x86/boot/header.S _start: · line 305
Quoted 1 line
arch/x86/boot/header.S +0
-0# or else old loadlin-1.5will fail)
arch/x86/boot/header.S _start: · line 307
Quoted 2 lines
arch/x86/boot/header.S +0
-0.globl realmode_swtch realmode_swtch: .word 0, 0 # default_switch,SETUPSEG
arch/x86/boot/header.S pref_address: .quad
Quoted 1 line
arch/x86/boot/header.S +0
-0@@ -552,6 +552,7 @@ pref_address: .quad
LOAD_PHYSICAL_ADDR# preferred load addrarch/x86/boot/header.S pref_address: .quad · line 552
Quoted 2 lines
arch/x86/boot/header.S +0
-0init_size: .long INIT_SIZE # kernelinitialization size
arch/x86/boot/header.S pref_address: .quad · line 553
Quoted 1 line
arch/x86/boot/header.S +0
-0handover_offset: .long 0 # Filled in by
build.carch/x86/boot/header.S pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
Quoted 3 lines
arch/x86/boot/header.S +1
-0+secdata_offset: .long secdata_start # End of setup header#####################################################
arch/x86/boot/header.S die: · line 639
Quoted 12 lines
arch/x86/boot/header.S +7
-0@@ -629,3 +630,15 @@ die: setup_corrupt: .byte 7 .string "No setup signature found...\n" + + .section ".secdata", "a" +secdata_start: +sec_length: + .long secdata_end - secdata_start +sec_signer: + .quad 0 # Filled by build.cA more flexible way to do this would be to make
sec_signeran offset to a null-terminated string. That way it can be any length, and you wouldn't need the build tool hack.
Quoted 2 lines
--
Brian Gerst
Also, there is no fundamental reason this has to be a fixed structure; it could directly contain variable width entries as long as it remains parsable.
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Quoted 75 lines · Brian Gerst
Quoted 74 lines · Gary Lin
This is a different approach to replace my previous implementation of Security
Version(*). Instead of using the fields in the PE/COFF header, this commit addssecdata_offsetin the setup header for the file offset of secdata. Currently, the secdata section contains the signer's name, the distro version, and the security version as defined in the wiki page. Since we don't rely on the PE/COFF header anymore, the size of signer is increased to 8 bytes to store more characters.Since this is just a tentative patch, I haven't started the other parts (shim and mokutil) yet, and it's flexible to change. Any comment and suggestion are welcome.
(*) https://github.com/lcp/shim/wiki/Security-Version
Cc Ard Biesheuvel <[email protected]>Cc "H. Peter Anvin" <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Joey Lee <[email protected]>Signed-off-by Gary Lin <[email protected]>--- arch/x86/Kconfig | 14 ++++++++++++++ arch/x86/boot/header.S | 15 ++++++++++++++- arch/x86/boot/setup.ld | 1 + arch/x86/boot/tools/build.c | 11 +++++++++++ arch/x86/include/uapi/asm/bootparam.h | 1 + 5 files changed, 41 insertions(+), 1 deletion(-)arch/x86/Kconfig +14
-0@@ -1817,6 +1817,20 @@ config EFI_MIXED If unsure, say N. +config SEC_SIGNER + string "The signer name" + default "none" + +config SEC_DISTRO + int "The distro version" + default 0 + range 0 65535 + +config SEC_VERSION + int "The security version" + default 0 + range 0 65535 + config SECCOMP def_bool y prompt "Enable seccomp to safely compute untrusted bytecode"arch/x86/boot/header.S +2
-1@@ -301,7 +301,7 @@ _start: # Part 2 of the header, from the old setup.S .ascii "HdrS" # header signature - .word 0x020d # header version number (>= 0x0105) + .word 0x020e # header version number (>= 0x0105) # or else old loadlin-1.5 will fail) .globl realmode_swtch realmode_swtch: .word 0, 0 # default_switch, SETUPSEG@@ -552,6 +552,7 @@ pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr init_size: .long INIT_SIZE # kernel initialization size handover_offset: .long 0 # Filled in by build.c +secdata_offset: .long secdata_start # End of setup header #####################################################
Quoted 16 lines
arch/x86/boot/header.S die: · line 639
Quoted 11 lines
arch/x86/boot/header.S +7
-0@@ -629,3 +630,15 @@ die: setup_corrupt: .byte 7 .string "No setup signature found...\n" + + .section ".secdata", "a" +secdata_start: +sec_length: + .long secdata_end - secdata_start +sec_signer: + .quad 0 # Filled by build.cA more flexible way to do this would be to make
sec_signeran offset to a null-terminated string. That way it can be any length, and you wouldn't need the build tool hack.
I was thinking about making sec_signer a variable length string and decided to make sec_signer fixed since it's easier to match 2 fixed size variables (just convert them to u32 or u64). Besides, I also want to limit the size of sec_signer because the list of security version will be stored in the NVRAM which is quite limited (Is it possible to limit the length of a string in kconfig?).
If the variable size string makes more sense, I'll update that in v2.
Thanks,
Gary Lin