Enable Automatic Disk Unlock with TPM2 on ieee1275
v3 cover Enable Automatic Disk Unlock with TPM2 on ieee1275
This series of patches enables the 'Automatic Disk Unlock with TPM2' support for ieee1275 PowerPC platforms. It adds a TCG2 driver for this platform, which has the same API as the one for EFI. Further, it adjusts the definition of TPM 2 related bit fields for big endian targets.
Regards,
Stefan
v3:
- Applied Daniel's R-b tags
- Added patches 2 & 3/7 for cleaning up of IEEE1275_IHANDLE_INVALID
- Using bools instead of ints
- Fixed commit messages
v2:
- Applied Gary's R-b tag to 1/5
- Split v1 2/2 into 4 patches
- Refactoring of grub_ieee1275_tpm_init
Stefan Berger (7):
tss2: Adjust bit fields for big endian targets ieee1275/serial: Cast 0 to proper type
ieee1275: Consolidate repeated definitions of IEEE1275_IHANDLE_INVALID ieee1275/ibmvpm: Move TPM initializaton functions to own file ieee1275/tcg2: Refactor grub_ieee1275_tpm_init ieee1275/tcg2: Add TCG2 driver for ieee1275 PowerPC firmware
tpm2_key_protector: Enable build for powerpc_ieee1275
grub-core/Makefile.core.def | 3 + grub-core/commands/ieee1275/ibmvtpm.c | 46 +------- grub-core/lib/ieee1275/tcg2.c | 159 ++++++++++++++++++++++++++ grub-core/lib/tss2/tss2_structs.h | 38 ++++++ grub-core/term/ieee1275/serial.c | 8 +- include/grub/ieee1275/ieee1275.h | 1 + include/grub/ieee1275/tpm.h | 30 +++++ 7 files changed, 238 insertions(+), 47 deletions(-) create mode 100644 grub-core/lib/ieee1275/tcg2.c create mode 100644 include/grub/ieee1275/tpm.h
Signature · 7 lines
2.25.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v3 1/7 tss2: Adjust bit fields for big endian targets
The TPM bit fields need to be in reverse order for big endian targets, such as ieee1275 PowerPC platforms that run grub in big endian mode.
--- grub-core/lib/tss2/tss2_structs.h | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
grub-core/lib/tss2/tss2_structs.h +38 -0
@@ -147,6 +147,15 @@ typedef TPM2B_DIGEST_t TPM2B_NONCE_t;/* TPMA_SESSION Structure */ struct TPMA_SESSION { +#ifdef GRUB_TARGET_WORDS_BIGENDIAN +grub_uint8_t audit:1 ; +grub_uint8_t encrypt:1 ; +grub_uint8_t decrypt:1 ; +grub_uint8_t reserved:2 ; +grub_uint8_t auditReset:1 ; +grub_uint8_t auditExclusive:1 ; +grub_uint8_t continueSession:1 ; +#else grub_uint8_t continueSession:1 ;grub_uint8_t auditExclusive:1 ;grub_uint8_t auditReset:1 ;
@@ -154,6 +163,7 @@ struct TPMA_SESSION grub_uint8_t decrypt:1; grub_uint8_t encrypt:1; grub_uint8_t audit:1; +#endif };typedef struct TPMA_SESSION TPMA_SESSION_t ;
@@ -206,6 +216,24 @@ typedef struct TPM2B_SENSITIVE_CREATE TPM2B_SENSITIVE_CREATE_t;/* TPMA_OBJECT Structure */ struct TPMA_OBJECT { +#ifdef GRUB_TARGET_WORDS_BIGENDIAN +grub_uint32_t reserved5:13 ; +grub_uint32_t sign:1 ; +grub_uint32_t decrypt:1 ; +grub_uint32_t restricted:1 ; +grub_uint32_t reserved4:4 ; +grub_uint32_t encryptedDuplication:1 ; +grub_uint32_t noDA:1 ; +grub_uint32_t reserved3:2 ; +grub_uint32_t adminWithPolicy:1 ; +grub_uint32_t userWithAuth:1 ; +grub_uint32_t sensitiveDataOrigin:1 ; +grub_uint32_t fixedParent:1 ; +grub_uint32_t reserved2:1 ; +grub_uint32_t stClear:1 ; +grub_uint32_t fixedTPM:1 ; +grub_uint32_t reserved1:1 ; +#else grub_uint32_t reserved1:1 ;grub_uint32_t fixedTPM:1 ;grub_uint32_t stClear:1 ;
@@ -222,6 +250,7 @@ struct TPMA_OBJECT grub_uint32_t decrypt:1; grub_uint32_t sign:1; grub_uint32_t reserved5:13; +#endif };typedef struct TPMA_OBJECT TPMA_OBJECT_t ;
@@ -516,12 +545,21 @@ typedef struct TPM2B_DATA TPM2B_DATA_t;/* TPMA_LOCALITY Structure */ struct TPMA_LOCALITY { +#ifdef GRUB_TARGET_WORDS_BIGENDIAN +grub_uint8_t Extended:3 ; +grub_uint8_t TPM_LOC_FOUR:1 ; +grub_uint8_t TPM_LOC_THREE:1 ; +grub_uint8_t TPM_LOC_TWO:1 ; +grub_uint8_t TPM_LOC_ONE:1 ; +grub_uint8_t TPM_LOC_ZERO:1 ; +#else grub_uint8_t TPM_LOC_ZERO:1 ;grub_uint8_t TPM_LOC_ONE:1 ;grub_uint8_t TPM_LOC_TWO:1 ;grub_uint8_t TPM_LOC_THREE:1 ;grub_uint8_t TPM_LOC_FOUR:1 ;grub_uint8_t Extended:3 ; +#endif };typedef struct TPMA_LOCALITY TPMA_LOCALITY_t ;
Signature · 7 lines
2.25.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v3 2/7 ieee1275/serial: Cast 0 to proper type
In reply to Stefan BergerCast 0 to proper type grub_ieee1275_ihandle_t. This type is used for struct grub_serial_port's handle that assigns or compares with IEEE1275_IHANDLE_INVALID.
--- grub-core/term/ieee1275/serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/term/ieee1275/serial.c +1 -1
@@ -25,7 +25,7 @@#include <grub/i18n.h> #include <grub/ieee1275/console.h> -#define IEEE1275_IHANDLE_INVALID ((grub_ieee1275_cell_t) 0) +#define IEEE1275_IHANDLE_INVALID ((grub_ieee1275_ihandle_t) 0)struct ofserial_hash_ent {
Signature · 7 lines
2.25.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v3 3/7 ieee1275: Consolidate repeated definitions of IEEE1275_IHANDLE_INVALID
In reply to Stefan BergerConsoldiate repeated definitions of IEEE1275_IHANDLE_INVALID that are cast to the type grub_ieee1275_ihandle_t.
--- grub-core/commands/ieee1275/ibmvtpm.c | 4 +--- grub-core/term/ieee1275/serial.c | 8 +++----- include/grub/ieee1275/ieee1275.h | 1 + 3 files changed, 5 insertions(+), 8 deletions(-)
grub-core/commands/ieee1275/ibmvtpm.c +1 -3
@@ -29,8 +29,6 @@static grub_ieee1275_ihandle_t tpm_ihandle;static grub_uint8_t tpm_version; -#define IEEE1275_IHANDLE_INVALID ((grub_ieee1275_ihandle_t) 0) -static void tpm_get_tpm_version (void ) {
@@ -53,7 +51,7 @@ tpm_init (void) {if (grub_ieee1275_open ("/vdevice/vtpm" , &tpm_ihandle) <0 ) { - tpm_ihandle =IEEE1275_IHANDLE_INVALID ; + tpm_ihandle =GRUB_IEEE1275_IHANDLE_INVALID ;return GRUB_ERR_UNKNOWN_DEVICE ; }
grub-core/term/ieee1275/serial.c +3 -5
@@ -25,8 +25,6 @@#include <grub/i18n.h> #include <grub/ieee1275/console.h> -#define IEEE1275_IHANDLE_INVALID ((grub_ieee1275_ihandle_t) 0) -struct ofserial_hash_ent {char *devpath;
@@ -44,7 +42,7 @@ do_real_config (struct grub_serial_port *port)if (grub_ieee1275_open (port->elem->devpath, &port->handle) || port->handle == (grub_ieee1275_ihandle_t) -1 ) - port->handle =IEEE1275_IHANDLE_INVALID ; + port->handle =GRUB_IEEE1275_IHANDLE_INVALID ; port->configured =1 ; }
@@ -58,7 +56,7 @@ serial_hw_fetch (struct grub_serial_port *port)do_real_config (port); -if (port->handle ==IEEE1275_IHANDLE_INVALID ) +if (port->handle ==GRUB_IEEE1275_IHANDLE_INVALID )return -1 ;grub_ieee1275_read (port->handle, &c,1 , &actual);
@@ -76,7 +74,7 @@ serial_hw_put (struct grub_serial_port *port, const int c)do_real_config (port); -if (port->handle ==IEEE1275_IHANDLE_INVALID ) +if (port->handle ==GRUB_IEEE1275_IHANDLE_INVALID )return ;grub_ieee1275_write (port->handle, &c0,1 , &actual);
include/grub/ieee1275/ieee1275.h +1 -0
@@ -60,6 +60,7 @@ struct grub_ieee1275_common_hdrtypedef grub_uint32_t grub_ieee1275_ihandle_t ;typedef grub_uint32_t grub_ieee1275_phandle_t ; +#define GRUB_IEEE1275_IHANDLE_INVALID ((grub_ieee1275_ihandle_t) 0)#define GRUB_IEEE1275_PHANDLE_INVALID ((grub_ieee1275_phandle_t) -1)struct grub_ieee1275_devalias
Signature · 7 lines
2.25.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v3 4/7 ieee1275/ibmvpm: Move TPM initializaton functions to own file
In reply to Stefan BergerMove common initialization functions from the ibmvtpm driver module into tcg2.c that will be moved into the new TCG2 driver in a subsequent patch. Make the functions available to the ibmvtpm driver as public functions and variables.
--- grub-core/Makefile.core.def | 1 + grub-core/commands/ieee1275/ibmvtpm.c | 44 ++----------------- grub-core/lib/ieee1275/tcg2.c | 61 +++++++++++++++++++++++++++ include/grub/ieee1275/tpm.h | 31 ++++++++++++++ 4 files changed, 97 insertions(+), 40 deletions(-) create mode 100644 grub-core/lib/ieee1275/tcg2.c create mode 100644 include/grub/ieee1275/tpm.h
grub-core/Makefile.core.def +1 -0
@@ -1155,6 +1155,7 @@ module = { name = tpm; common = commands/tpm.c; ieee1275 = commands/ieee1275/ibmvtpm.c; + ieee1275 = lib/ieee1275/tcg2.c; enable = powerpc_ieee1275; };
grub-core/commands/ieee1275/ibmvtpm.c +4 -40
69 lines not on this page · raw message
grub-core/lib/ieee1275/tcg2.c new file +61 -0
61 lines not on this page · raw message
include/grub/ieee1275/tpm.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2019 Free Software Foundation, Inc. +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRUB_IEEE1275_TPM_HEADER +#define GRUB_IEEE1275_TPM_HEADER 1 + +#include <grub/err.h> +#include <grub/types.h> +#include <grub/ieee1275/ieee1275.h> + +extern grub_ieee1275_ihandle_t grub_ieee1275_tpm_ihandle; +extern grub_uint8_t grub_ieee1275_tpm_version; + +extern grub_err_t grub_ieee1275_tpm_init (void ); + +#endif
Signature · 7 lines
2.25.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v3 5/7 ieee1275/tcg2: Refactor grub_ieee1275_tpm_init
In reply to Stefan BergerMove tpm_get_tpm_version() into grub_ieee1275_tpm_init() and invalidate grub_ieee1275_tpm_ihandle in case no TPM 2 could be detected. Try the initialization only once so that grub_tpm_present() will always return the same result. Use the grub_ieee1275_tpm_ihandle as indicator for an available TPM instead of grub_ieee1275_tpm_version, which can now be removed.
--- grub-core/commands/ieee1275/ibmvtpm.c | 2 +- grub-core/lib/ieee1275/tcg2.c | 40 ++++++++++++--------------- include/grub/ieee1275/tpm.h | 1 - 3 files changed, 18 insertions(+), 25 deletions(-)
grub-core/commands/ieee1275/ibmvtpm.c +1 -1
@@ -100,7 +100,7 @@ grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr,grub_dprintf ("tpm" ,"log_event, pcr = %d, size = 0x%" PRIxGRUB_SIZE", %s\n" , pcr, size, description); -if (grub_ieee1275_tpm_version ==2 ) +if (grub_ieee1275_tpm_ihandle !=GRUB_IEEE1275_IHANDLE_INVALID )return tpm2_log_event (buf, size, pcr, description);return GRUB_ERR_NONE ;
grub-core/lib/ieee1275/tcg2.c +17 -23
@@ -23,39 +23,33 @@#include <grub/mm.h> #include <grub/misc.h> -grub_ieee1275_ihandle_t grub_ieee1275_tpm_ihandle; -grub_uint8_t grub_ieee1275_tpm_version; - -static void -tpm_get_tpm_version (void ) -{ -grub_ieee1275_phandle_t vtpm; -char buffer[20 ]; - -if (!grub_ieee1275_finddevice ("/vdevice/vtpm" , &vtpm) && - !grub_ieee1275_get_property (vtpm,"compatible" , buffer, -sizeof (buffer),NULL ) && - !grub_strcmp (buffer,"IBM,vtpm20" )) - grub_ieee1275_tpm_version =2 ; -} +grub_ieee1275_ihandle_t grub_ieee1275_tpm_ihandle =GRUB_IEEE1275_IHANDLE_INVALID ;grub_err_t grub_ieee1275_tpm_init (void ) { -static int init_success =0 ; +static bool init_tried = false; +grub_ieee1275_phandle_t vtpm; +char buffer[20 ]; -if (!init_success) +if (!init_tried) { -if (grub_ieee1275_open ("/vdevice/vtpm" , &grub_ieee1275_tpm_ihandle) <0 ) + init_tried =1 ; + +if (grub_ieee1275_open ("/vdevice/vtpm" , &grub_ieee1275_tpm_ihandle) <0 || +grub_ieee1275_finddevice ("/vdevice/vtpm" , &vtpm) || +grub_ieee1275_get_property (vtpm,"compatible" , buffer,sizeof (buffer),NULL ) || +grub_strcmp (buffer,"IBM,vtpm20" )) { +if (grub_ieee1275_tpm_ihandle !=GRUB_IEEE1275_IHANDLE_INVALID ) +grub_ieee1275_close (grub_ieee1275_tpm_ihandle); + grub_ieee1275_tpm_ihandle =GRUB_IEEE1275_IHANDLE_INVALID ; -return GRUB_ERR_UNKNOWN_DEVICE ; } - - init_success =1 ; - -tpm_get_tpm_version (); } +if (grub_ieee1275_tpm_ihandle ==GRUB_IEEE1275_IHANDLE_INVALID ) +return GRUB_ERR_UNKNOWN_DEVICE ; +return GRUB_ERR_NONE ; }
include/grub/ieee1275/tpm.h +0 -1
@@ -24,7 +24,6 @@#include <grub/ieee1275/ieee1275.h> extern grub_ieee1275_ihandle_t grub_ieee1275_tpm_ihandle; -extern grub_uint8_t grub_ieee1275_tpm_version;extern grub_err_t grub_ieee1275_tpm_init (void );
Signature · 7 lines
2.25.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v3 6/7 ieee1275/tcg2: Add TCG2 driver for ieee1275 PowerPC firmware
In reply to Stefan BergerFollow recent extensions of EFI support providing a TCG2 driver with a public API for getting the maximum TPM command size and passing a TPM command through to the TPM 2. Implement this functionality using ieee1275 PowerPC firmware API calls. Move tcg2.c into the TCG2 driver.
--- grub-core/Makefile.core.def | 3 +- grub-core/lib/ieee1275/tcg2.c | 104 ++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-)
grub-core/Makefile.core.def +2 -1
@@ -1155,7 +1155,6 @@ module = { name = tpm; common = commands/tpm.c; ieee1275 = commands/ieee1275/ibmvtpm.c; - ieee1275 = lib/ieee1275/tcg2.c; enable = powerpc_ieee1275; };
@@ -2576,8 +2575,10 @@ module = { common = lib/tss2/tss2.c; efi = lib/efi/tcg2.c; emu = lib/tss2/tcg2_emu.c; + powerpc_ieee1275 = lib/ieee1275/tcg2.c; enable = efi; enable = emu; + enable = powerpc_ieee1275; cppflags = '-I$(srcdir)/lib/tss2'; };
grub-core/lib/ieee1275/tcg2.c +104 -0
113 lines not on this page · raw message
Signature · 7 lines
2.25.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v3 7/7 tpm2_key_protector: Enable build for powerpc_ieee1275
In reply to Stefan Berger--- grub-core/Makefile.core.def | 1 + 1 file changed, 1 insertion(+)
grub-core/Makefile.core.def +1 -0
@@ -2591,6 +2591,7 @@ module = { /* The plaform support of tpm2_key_protector depends on the tcg2 implementation in tss2. */ enable = efi; enable = emu; + enable = powerpc_ieee1275; cppflags = '-I$(srcdir)/lib/tss2 -I$(srcdir)/lib/libtasn1-grub'; };
Signature · 7 lines
2.25.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 20 lines · Stefan Berger
This series of patches enables the 'Automatic Disk Unlock with TPM2' support for ieee1275 PowerPC platforms. It adds a TCG2 driver for this platform, which has the same API as the one for EFI. Further, it adjusts the definition of TPM 2 related bit fields for big endian targets.
Regards,
Stefanv3:
- Applied Daniel's R-b tags
- Added patches 2 & 3/7 for cleaning up ofIEEE1275_IHANDLE_INVALID
- Using bools instead of ints
- Fixed commit messagesv2:
- Applied Gary's R-b tag to 1/5
- Split v1 2/2 into 4 patches
- Refactoring ofgrub_ieee1275_tpm_init
Quoted 8 lines
Stefan Berger (7):
tss2: Adjust bit fields for big endian targets ieee1275/serial: Cast 0 to proper type
ieee1275: Consolidate repeated definitions ofIEEE1275_IHANDLE_INVALIDieee1275/ibmvpm: Move TPM initializaton functions to own file ieee1275/tcg2: Refactorgrub_ieee1275_tpm_initieee1275/tcg2: Add TCG2 driver for ieee1275 PowerPC firmware
tpm2_key_protector: Enable build forpowerpc_ieee1275
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 5 lines · Stefan Berger
This series of patches enables the 'Automatic Disk Unlock with TPM2' support for ieee1275 PowerPC platforms. It adds a TCG2 driver for this platform, which has the same API as the one for EFI. Further, it adjusts the definition of TPM 2 related bit fields for big endian targets.
Thanks for extending TPM2 support to ppc64!
Quoted 24 lines
Regards,
Stefanv3:
- Applied Daniel's R-b tags
- Added patches 2 & 3/7 for cleaning up ofIEEE1275_IHANDLE_INVALID
- Using bools instead of ints
- Fixed commit messagesv2:
- Applied Gary's R-b tag to 1/5
- Split v1 2/2 into 4 patches
- Refactoring ofgrub_ieee1275_tpm_initStefan Berger (7):
tss2: Adjust bit fields for big endian targets ieee1275/serial: Cast 0 to proper type
ieee1275: Consolidate repeated definitions ofIEEE1275_IHANDLE_INVALIDieee1275/ibmvpm: Move TPM initializaton functions to own file ieee1275/tcg2: Refactorgrub_ieee1275_tpm_initieee1275/tcg2: Add TCG2 driver for ieee1275 PowerPC firmware
tpm2_key_protector: Enable build forpowerpc_ieee1275
Quoted 14 lines
grub-core/Makefile.core.def | 3 + grub-core/commands/ieee1275/ibmvtpm.c | 46 +------- grub-core/lib/ieee1275/tcg2.c | 159 ++++++++++++++++++++++++++ grub-core/lib/tss2/tss2_structs.h | 38 ++++++ grub-core/term/ieee1275/serial.c | 8 +- include/grub/ieee1275/ieee1275.h | 1 + include/grub/ieee1275/tpm.h | 30 +++++ 7 files changed, 238 insertions(+), 47 deletions(-) create mode 100644 grub-core/lib/ieee1275/tcg2.c create mode 100644 include/grub/ieee1275/tpm.hSignature · 1 line
2.25.1
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel