Enable Automatic Disk Unlock with TPM2 on ieee1275
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
Stefan Berger (2):
tss2: Adjust bit fields for big endian targets
ieee1275: Add TCG2 driver for ieee1275 PowerPC firmware
grub-core/Makefile.core.def | 3 + grub-core/commands/ieee1275/ibmvtpm.c | 46 +------ grub-core/lib/ieee1275/tcg2.c | 167 ++++++++++++++++++++++++++ grub-core/lib/tss2/tss2_structs.h | 38 ++++++ include/grub/ieee1275/tpm.h | 31 +++++ 5 files changed, 243 insertions(+), 42 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 1/2 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
Re: [PATCH 1/2] tss2: Adjust bit fields for big endian targets
Quoted 4 lines · Stefan Berger
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.
Signed-off-by Stefan Berger <[email protected]>
Thanks for fixing the endianness of the TPMA structs!
Quoted 90 lines
--- 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 · 1 line
2.25.1
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 2/2 ieee1275: 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 common initialization functions from the ibmvtpm driver module into the new built-in TCG2 driver. Make them available to the ibmvtpm driver as public functions and variables.
The firmware support is readily available on pSeries platforms. For SLOF the new API calls have been recently merged upstream and will become available after QEMU 9.2.
--- grub-core/Makefile.core.def | 3 + grub-core/commands/ieee1275/ibmvtpm.c | 46 +------ grub-core/lib/ieee1275/tcg2.c | 167 ++++++++++++++++++++++++++ include/grub/ieee1275/tpm.h | 31 +++++ 4 files changed, 205 insertions(+), 42 deletions(-) create mode 100644 grub-core/lib/ieee1275/tcg2.c create mode 100644 include/grub/ieee1275/tpm.h
grub-core/Makefile.core.def +3 -0
@@ -2575,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'; };
@@ -2589,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'; };
grub-core/commands/ieee1275/ibmvtpm.c +4 -42
71 lines not on this page · raw message
grub-core/lib/ieee1275/tcg2.c new file +167 -0
167 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; + +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
Re: [PATCH 2/2] ieee1275: Add TCG2 driver for ieee1275 PowerPC firmware
Quoted 164 lines · Stefan Berger
Follow 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 common initialization functions from the ibmvtpm driver module into the new built-in TCG2 driver. Make them available to the ibmvtpm driver as public functions and variables.
The firmware support is readily available on pSeries platforms. For SLOF the new API calls have been recently merged upstream and will become available after QEMU 9.2.
Signed-off-by Stefan Berger <[email protected]>--- grub-core/Makefile.core.def | 3 + grub-core/commands/ieee1275/ibmvtpm.c | 46 +------ grub-core/lib/ieee1275/tcg2.c | 167 ++++++++++++++++++++++++++ include/grub/ieee1275/tpm.h | 31 +++++ 4 files changed, 205 insertions(+), 42 deletions(-) create mode 100644 grub-core/lib/ieee1275/tcg2.c create mode 100644 include/grub/ieee1275/tpm.hgrub-core/Makefile.core.def +3
-0@@ -2575,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'; };@@ -2589,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'; };grub-core/commands/ieee1275/ibmvtpm.c +4
-42@@ -23,48 +23,10 @@#include <grub/types.h> #include <grub/tpm.h> #include <grub/ieee1275/ieee1275.h> +#include <grub/ieee1275/tpm.h> #include <grub/mm.h> #include <grub/misc.h> -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 ) -{ -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" )) - tpm_version =2 ; -} - -static grub_err_t -tpm_init (void ) -{ -static int init_success =0 ; - -if (!init_success) - { -if (grub_ieee1275_open ("/vdevice/vtpm" , &tpm_ihandle) <0 ) - { - tpm_ihandle =IEEE1275_IHANDLE_INVALID ; -return GRUB_ERR_UNKNOWN_DEVICE ; - } - - init_success =1 ; - -tpm_get_tpm_version (); - } - -return GRUB_ERR_NONE ; -} - static int ibmvtpm_2hash_ext_log (grub_uint8_t pcrindex, grub_uint32_t eventtype,@@ -90,7 +52,7 @@ ibmvtpm_2hash_ext_log (grub_uint8_t pcrindex,INIT_IEEE1275_COMMON (&args.common,"call-method" ,8 ,2 ); args.method = (grub_ieee1275_cell_t )"2hash-ext-log" ; - args.ihandle = tpm_ihandle; + args.ihandle = grub_ieee1275_tpm_ihandle; args.pcrindex = pcrindex; args.eventtype = eventtype; args.description = (grub_ieee1275_cell_t ) description;@@ -138,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 (tpm_version ==2 ) +if (grub_ieee1275_tpm_version ==2 )return tpm2_log_event (buf, size, pcr, description);return GRUB_ERR_NONE ;@@ -151,5 +113,5 @@ grub_tpm_present (void)* Call tpm_init() "late" rather than from GRUB_MOD_INIT() so that device nodes * can be found. */ -return tpm_init () ==GRUB_ERR_NONE ; +return grub_ieee1275_tpm_init () ==GRUB_ERR_NONE ; }grub-core/lib/ieee1275/tcg2.c new file +33
-0@@ -0,0 +1,167 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 IBM Corporation +* Copyright (C) 2024 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/>. +*/ + +#include <grub/types.h> +#include <grub/tpm.h> +#include <grub/ieee1275/tpm.h> +#include <grub/mm.h> +#include <grub/misc.h> + +#include <tcg2.h> + +grub_ieee1275_ihandle_t grub_ieee1275_tpm_ihandle; +grub_uint8_t grub_ieee1275_tpm_version; + +#define IEEE1275_IHANDLE_INVALID ((grub_ieee1275_ihandle_t) 0) + +static void
grub-core/lib/ieee1275/tcg2.c line 43
Quoted 10 lines
grub-core/lib/ieee1275/tcg2.c new file +10
-0+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 ;
I think this should be a part of the grub_ieee1275_tpm_init()...
Quoted 8 lines
grub-core/lib/ieee1275/tcg2.c new file +8
-0+} + +grub_err_t +grub_ieee1275_tpm_init (void ) +{ +static int init_success =0 ; + +if (!init_success)
grub-core/lib/ieee1275/tcg2.c line 61
Quoted 10 lines
grub-core/lib/ieee1275/tcg2.c new file +10
-0+ { +if (grub_ieee1275_open ("/vdevice/vtpm" , &grub_ieee1275_tpm_ihandle) <0 ) + { + grub_ieee1275_tpm_ihandle =IEEE1275_IHANDLE_INVALID ; +return GRUB_ERR_UNKNOWN_DEVICE ; + } + + init_success =1 ; + +tpm_get_tpm_version ();
... and probably the grub_ieee1275_tpm_init() should fail if TPM != 2.0...
If you agree with my suggestion you should do move and code change in separate patches.
grub-core/lib/ieee1275/tcg2.c line 68
Quoted 7 lines
grub-core/lib/ieee1275/tcg2.c new file +7
-0+ } + +return GRUB_ERR_NONE ; +} + +grub_err_t +grub_tcg2_get_max_output_size (grub_size_t *size)
This function seems unused. If it is true please drop it.
Quoted 39 lines
grub-core/lib/ieee1275/tcg2.c new file +39
-0+{ +struct tpm_get_maximum_cmd_size + { +struct grub_ieee1275_common_hdr common; +grub_ieee1275_cell_t method; +grub_ieee1275_cell_t ihandle; +grub_ieee1275_cell_t catch_result; +grub_ieee1275_cell_t size; + }; +struct tpm_get_maximum_cmd_size args; +static int error_displayed =0 ; +grub_err_t err; + + err =grub_ieee1275_tpm_init (); +if (err !=GRUB_ERR_NONE ) +return err; + +INIT_IEEE1275_COMMON (&args.common,"call-method" ,2 ,2 ); + args.method = (grub_ieee1275_cell_t )"get-maximum-cmd-size" ; + args.ihandle = grub_ieee1275_tpm_ihandle; + +if (IEEE1275_CALL_ENTRY_FN (&args) ==-1 ) +return GRUB_ERR_INVALID_COMMAND ; + +/* +* catch_result is set if firmware does not support get-maximum-cmd-size +* rc is GRUB_IEEE1275_CELL_FALSE (0) on failure +*/ +if (args.catch_result) + { +if (!error_displayed) + { + error_displayed++; +return grub_error (GRUB_ERR_BAD_DEVICE , +"get-maximum-cmd-size failed: Firmware is likely too old.\n" ); + } +return GRUB_ERR_INVALID_COMMAND ; + } +
grub-core/lib/ieee1275/tcg2.c line 117
Quoted 10 lines
grub-core/lib/ieee1275/tcg2.c new file +10
-0+ *size = args.size; + +return GRUB_ERR_NONE ; +} + +grub_err_t +grub_tcg2_submit_command (grub_size_t input_size, +grub_uint8_t *input, +grub_size_t output_size, +grub_uint8_t *output)
I think you should separate this function addition from earlier code shuffling and update, i.e, I want separate patch for it.
Quoted 75 lines
grub-core/lib/ieee1275/tcg2.c new file +50
-0+{ +struct tpm_pass_through_to_tpm + { +struct grub_ieee1275_common_hdr common; +grub_ieee1275_cell_t method; +grub_ieee1275_cell_t ihandle; +grub_ieee1275_cell_t buf_size; +grub_ieee1275_cell_t buf_addr; +grub_ieee1275_cell_t catch_result; +grub_ieee1275_cell_t resp_size; + }; +struct tpm_pass_through_to_tpm args; +static int error_displayed =0 ; +grub_err_t err; + +if (input_size ==0 || input ==NULL || + output_size ==0 || output ==NULL ) +return GRUB_ERR_BAD_ARGUMENT ; + + err =grub_ieee1275_tpm_init (); +if (err !=GRUB_ERR_NONE ) +return err; + +INIT_IEEE1275_COMMON (&args.common,"call-method" ,4 ,2 ); + args.method = (grub_ieee1275_cell_t )"pass-through-to-tpm" ; + args.ihandle = grub_ieee1275_tpm_ihandle; + args.buf_size = (grub_ieee1275_cell_t ) input_size; + args.buf_addr = (grub_ieee1275_cell_t ) input; + +if (IEEE1275_CALL_ENTRY_FN (&args) ==-1 ) +return GRUB_ERR_INVALID_COMMAND ; + +/* +* catch_result is set if firmware does not support pass-through-to-tpm +*/ +if (args.catch_result) + { +if (!error_displayed) + { + error_displayed++; +return grub_error (GRUB_ERR_BAD_DEVICE , +"pass-through-to-tpm failed: Firmware is likely too old.\n" ); + } +return GRUB_ERR_INVALID_COMMAND ; + } + +grub_memcpy (output, input, args.resp_size); + +return GRUB_ERR_NONE ; +}include/grub/ieee1275/tpm.h new file +19
-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
include/grub/ieee1275/tpm.h line 29
Quoted 10 lines
include/grub/ieee1275/tpm.h new file +10
-0+#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; + +grub_err_t grub_ieee1275_tpm_init (void );
extern please...
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 2/2] ieee1275: Add TCG2 driver for ieee1275 PowerPC firmware
Quoted 98 lines · Daniel Kiper
Quoted 63 lines · Stefan Berger
Follow 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 common initialization functions from the ibmvtpm driver module into the new built-in TCG2 driver. Make them available to the ibmvtpm driver as public functions and variables.
The firmware support is readily available on pSeries platforms. For SLOF the new API calls have been recently merged upstream and will become available after QEMU 9.2.
Signed-off-by Stefan Berger <[email protected]>--- grub-core/Makefile.core.def | 3 + grub-core/commands/ieee1275/ibmvtpm.c | 46 +------ grub-core/lib/ieee1275/tcg2.c | 167 ++++++++++++++++++++++++++ include/grub/ieee1275/tpm.h | 31 +++++ 4 files changed, 205 insertions(+), 42 deletions(-)create mode 100644
grub-core/lib/ieee1275/tcg2.ccreate mode 100644include/grub/ieee1275/tpm.hgrub-core/lib/ieee1275/tcg2.c new file +33
-0@@ -0,0 +1,167 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 IBM Corporation +* Copyright (C) 2024 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/>. +*/ + +#include <grub/types.h> +#include <grub/tpm.h> +#include <grub/ieee1275/tpm.h> +#include <grub/mm.h> +#include <grub/misc.h> + +#include <tcg2.h> + +grub_ieee1275_ihandle_t grub_ieee1275_tpm_ihandle; +grub_uint8_t grub_ieee1275_tpm_version; + +#define IEEE1275_IHANDLE_INVALID ((grub_ieee1275_ihandle_t) 0) + +static voidgrub-core/lib/ieee1275/tcg2.c line 43
Quoted 10 lines
grub-core/lib/ieee1275/tcg2.c new file +10
-0+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 ;I think this should be a part of the
grub_ieee1275_tpm_init()...Quoted 8 lines
grub-core/lib/ieee1275/tcg2.c new file +8
-0+} + +grub_err_t +grub_ieee1275_tpm_init (void ) +{ +static int init_success =0 ; + +if (!init_success)grub-core/lib/ieee1275/tcg2.c line 61
Quoted 10 lines
grub-core/lib/ieee1275/tcg2.c new file +10
-0+ { +if (grub_ieee1275_open ("/vdevice/vtpm" , &grub_ieee1275_tpm_ihandle) <0 ) + { + grub_ieee1275_tpm_ihandle =IEEE1275_IHANDLE_INVALID ; +return GRUB_ERR_UNKNOWN_DEVICE ; + } + + init_success =1 ; + +tpm_get_tpm_version ();... and probably the
grub_ieee1275_tpm_init()should fail if TPM != 2.0...
Quoted 2 lines
If you agree with my suggestion you should do move and code change in separate patches.
Ok, I will modify it to the following patches
- move the code and it will look like this then
- move tpm_get_tpm_version into grub_ieee1265_tpm_init
- add the 2 new interface functions needed to implement the same interface the upcoming EFI TCG2 driver suggests
Quoted 10 lines
grub-core/lib/ieee1275/tcg2.c line 68
Quoted 8 lines
grub-core/lib/ieee1275/tcg2.c new file +7
-0+ } + +return GRUB_ERR_NONE ; +} + +grub_err_t +grub_tcg2_get_max_output_size (grub_size_t *size)This function seems unused. If it is true please drop it.
It will be needed by this patch here: https://lore.kernel.org/grub-devel/[email protected]/T/#u
It implements the interface described in this new file here:
grub-core/lib/tss2/tcg2.h new file +0 -0
[...]
+extern grub_err_t +grub_tcg2_get_max_output_size (grub_size_t *size); +
+extern grub_err_t +grub_tcg2_submit_command (grub_size_t input_size,
+ grub_uint8_t *input, + grub_size_t output_size, + grub_uint8_t *output);
Quoted 45 lines
Quoted 45 lines
grub-core/lib/ieee1275/tcg2.c new file +44
-0+{ +struct tpm_get_maximum_cmd_size + { +struct grub_ieee1275_common_hdr common; +grub_ieee1275_cell_t method; +grub_ieee1275_cell_t ihandle; +grub_ieee1275_cell_t catch_result; +grub_ieee1275_cell_t size; + }; +struct tpm_get_maximum_cmd_size args; +static int error_displayed =0 ; +grub_err_t err; + + err =grub_ieee1275_tpm_init (); +if (err !=GRUB_ERR_NONE ) +return err; + +INIT_IEEE1275_COMMON (&args.common,"call-method" ,2 ,2 ); + args.method = (grub_ieee1275_cell_t )"get-maximum-cmd-size" ; + args.ihandle = grub_ieee1275_tpm_ihandle; + +if (IEEE1275_CALL_ENTRY_FN (&args) ==-1 ) +return GRUB_ERR_INVALID_COMMAND ; + +/* +* catch_result is set if firmware does not support get-maximum-cmd-size +* rc is GRUB_IEEE1275_CELL_FALSE (0) on failure +*/ +if (args.catch_result) + { +if (!error_displayed) + { + error_displayed++; +return grub_error (GRUB_ERR_BAD_DEVICE , +"get-maximum-cmd-size failed: Firmware is likely too old.\n" ); + } +return GRUB_ERR_INVALID_COMMAND ; + } + + *size = args.size; + +return GRUB_ERR_NONE ; +} +
Quoted 8 lines
grub-core/lib/ieee1275/tcg2.c line 117
Quoted 5 lines
grub-core/lib/ieee1275/tcg2.c new file +5
-0+grub_err_t +grub_tcg2_submit_command (grub_size_t input_size, +grub_uint8_t *input, +grub_size_t output_size, +grub_uint8_t *output)I think you should separate this function addition from earlier code shuffling and update, i.e, I want separate patch for it.
Ok, I will separate it out.
Quoted 89 lines
Quoted 76 lines
grub-core/lib/ieee1275/tcg2.c new file +50
-0+{ +struct tpm_pass_through_to_tpm + { +struct grub_ieee1275_common_hdr common; +grub_ieee1275_cell_t method; +grub_ieee1275_cell_t ihandle; +grub_ieee1275_cell_t buf_size; +grub_ieee1275_cell_t buf_addr; +grub_ieee1275_cell_t catch_result; +grub_ieee1275_cell_t resp_size; + }; +struct tpm_pass_through_to_tpm args; +static int error_displayed =0 ; +grub_err_t err; + +if (input_size ==0 || input ==NULL || + output_size ==0 || output ==NULL ) +return GRUB_ERR_BAD_ARGUMENT ; + + err =grub_ieee1275_tpm_init (); +if (err !=GRUB_ERR_NONE ) +return err; + +INIT_IEEE1275_COMMON (&args.common,"call-method" ,4 ,2 ); + args.method = (grub_ieee1275_cell_t )"pass-through-to-tpm" ; + args.ihandle = grub_ieee1275_tpm_ihandle; + args.buf_size = (grub_ieee1275_cell_t ) input_size; + args.buf_addr = (grub_ieee1275_cell_t ) input; + +if (IEEE1275_CALL_ENTRY_FN (&args) ==-1 ) +return GRUB_ERR_INVALID_COMMAND ; + +/* +* catch_result is set if firmware does not support pass-through-to-tpm +*/ +if (args.catch_result) + { +if (!error_displayed) + { + error_displayed++; +return grub_error (GRUB_ERR_BAD_DEVICE , +"pass-through-to-tpm failed: Firmware is likely too old.\n" ); + } +return GRUB_ERR_INVALID_COMMAND ; + } + +grub_memcpy (output, input, args.resp_size); + +return GRUB_ERR_NONE ; +}include/grub/ieee1275/tpm.h new file +19
-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 include/grub/ieee1275/tpm.h line 29
Quoted 10 lines
include/grub/ieee1275/tpm.h new file +10
-0+#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; + +grub_err_t grub_ieee1275_tpm_init (void );extern please...
Quoted 6 lines
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel