Enable Automatic Disk Unlock with TPM2 on ieee1275
v2 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
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 (5):
tss2: Adjust bit fields for big endian targets ieee1275/ibmvtpm: Move initializaton functions to TCG2 driver 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 | 156 ++++++++++++++++++++++++++ grub-core/lib/tss2/tss2_structs.h | 38 +++++++ include/grub/ieee1275/tpm.h | 32 ++++++ 5 files changed, 233 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 v2 1/5 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 v2 1/5] tss2: Adjust bit fields for big endian targets
Quoted 5 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]>Reviewed-by Gary Lin <[email protected]>
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v2 2/5 ieee1275/ibmvtpm: Move initializaton functions to TCG2 driver
In reply to Stefan BergerMove common initialization functions from the ibmvtpm driver module into the new TCG2 driver that will be turned into a built-in driver soon. Already 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 | 46 ++------------------ grub-core/lib/ieee1275/tcg2.c | 61 +++++++++++++++++++++++++++ include/grub/ieee1275/tpm.h | 33 +++++++++++++++ 4 files changed, 99 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 +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 -42
71 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 +33 -0
@@ -0,0 +1,33 @@ +/* +* 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> + +#define IEEE1275_IHANDLE_INVALID ((grub_ieee1275_ihandle_t) 0) + +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
Re: [PATCH v2 2/5] ieee1275/ibmvtpm: Move initializaton functions to TCG2 driver
Quoted 2 lines · Stefan Berger
Move common initialization functions from the ibmvtpm driver module into the new TCG2 driver that will be turned into a built-in driver soon.
The "built-in driver" phrase is confusing here. I think you should say the code will be moved to tss2 module in subsequent patch. Same thing should be fixed in the patch #4.
Quoted 193 lines
Already make the functions available to the ibmvtpm driver as public functions and variables.
Signed-off-by Stefan Berger <[email protected]>--- grub-core/Makefile.core.def | 1 + grub-core/commands/ieee1275/ibmvtpm.c | 46 ++------------------ grub-core/lib/ieee1275/tcg2.c | 61 +++++++++++++++++++++++++++ include/grub/ieee1275/tpm.h | 33 +++++++++++++++ 4 files changed, 99 insertions(+), 42 deletions(-) create mode 100644 grub-core/lib/ieee1275/tcg2.c create mode 100644 include/grub/ieee1275/tpm.hgrub-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
-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 +61
-0@@ -0,0 +1,61 @@ +/* +* 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> + +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_err_t +grub_ieee1275_tpm_init (void ) +{ +static int init_success =0 ; + +if (!init_success) + { +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 (); + } + +return GRUB_ERR_NONE ; +}include/grub/ieee1275/tpm.h new file +16
-0@@ -0,0 +1,33 @@ +/* +* 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/>.
include/grub/ieee1275/tpm.h line 26
Quoted 10 lines
include/grub/ieee1275/tpm.h new file +10
-0+*/ + +#ifndef GRUB_IEEE1275_TPM_HEADER +#define GRUB_IEEE1275_TPM_HEADER 1 + +#include <grub/err.h> +#include <grub/types.h> +#include <grub/ieee1275/ieee1275.h> + +#define IEEE1275_IHANDLE_INVALID ((grub_ieee1275_ihandle_t) 0)
The name is too generic or if it is really generic thing for IEEE 1275 platforms then it should be moved to more generic place. And I do not mention it should be prefixed with "GRUB_"...
Otherwise patch LGTM. If you fix these minor issues you can add
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v2 3/5 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. 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 | 43 +++++++++++---------------- include/grub/ieee1275/tpm.h | 1 - 3 files changed, 18 insertions(+), 28 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 !=IEEE1275_IHANDLE_INVALID )return tpm2_log_event (buf, size, pcr, description);return GRUB_ERR_NONE ;
grub-core/lib/ieee1275/tcg2.c +17 -26
56 lines not on this page · raw message
include/grub/ieee1275/tpm.h +0 -1
@@ -26,7 +26,6 @@#define IEEE1275_IHANDLE_INVALID ((grub_ieee1275_ihandle_t) 0)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
Re: [PATCH v2 3/5] ieee1275/tcg2: Refactor grub_ieee1275_tpm_init
Quoted 1 line · Stefan Berger
Move
tpm_get_tpm_versionintogrub_ieee1275_tpm_initand invalidate
s/tpm_get_tpm_version/tpm_get_tpm_version()/ s/grub_ieee1275_tpm_init/grub_ieee1275_tpm_init()/
Quoted 2 lines
grub_ieee1275_tpm_ihandlein case no TPM 2 could be detected. Try the initialization only once. Use thegrub_ieee1275_tpm_ihandleas
Could you explain why you change logic here? I am not against that but I think it should be clarified why...
Quoted 44 lines
indicator for an available TPM instead of
grub_ieee1275_tpm_version, which can now be removed.Signed-off-by Stefan Berger <[email protected]>--- grub-core/commands/ieee1275/ibmvtpm.c | 2 +- grub-core/lib/ieee1275/tcg2.c | 43 +++++++++++---------------- include/grub/ieee1275/tpm.h | 1 - 3 files changed, 18 insertions(+), 28 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 !=IEEE1275_IHANDLE_INVALID )return tpm2_log_event (buf, size, pcr, description);return GRUB_ERR_NONE ;grub-core/lib/ieee1275/tcg2.c +0
-13@@ -23,39 +23,30 @@#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-core/lib/ieee1275/tcg2.c line 32
Quoted 10 lines
grub-core/lib/ieee1275/tcg2.c +3
-3- grub_ieee1275_tpm_version =2 ; -} +grub_ieee1275_ihandle_t grub_ieee1275_tpm_ihandle =IEEE1275_IHANDLE_INVALID ;grub_err_t grub_ieee1275_tpm_init (void ) { -static int init_success =0 ; +grub_ieee1275_phandle_t vtpm; +static int init_tried =0 ;
We have a bool in the GRUB. Please use it...
Quoted 8 lines
grub-core/lib/ieee1275/tcg2.c +2
-4+char buffer[20 ]; -if (!init_success) +if (!init_tried) { -if (grub_ieee1275_open ("/vdevice/vtpm" , &grub_ieee1275_tpm_ihandle) <0 ) - { - grub_ieee1275_tpm_ihandle =IEEE1275_IHANDLE_INVALID ;
grub-core/lib/ieee1275/tcg2.c line 40
Quoted 10 lines
grub-core/lib/ieee1275/tcg2.c +4
-6-return GRUB_ERR_UNKNOWN_DEVICE ; - } - - init_success =1 ; - -tpm_get_tpm_version (); + init_tried =1 ; + + if (grub_ieee1275_open ("/vdevice/vtpm", + &grub_ieee1275_tpm_ihandle) < 0 ||
You do not need wrap this line...
grub-core/lib/ieee1275/tcg2.c line 43
Quoted 3 lines
grub-core/lib/ieee1275/tcg2.c +3
-0+grub_ieee1275_finddevice ("/vdevice/vtpm" , &vtpm) || +grub_ieee1275_get_property (vtpm,"compatible" , buffer, + sizeof (buffer), NULL) ||
Same here...
grub-core/lib/ieee1275/tcg2.c line 44
Quoted 1 line
grub-core/lib/ieee1275/tcg2.c +1
-0+ grub_strcmp (buffer, "IBM,vtpm20"))
Should not you call grub_ieee1275_close() before invalidating grub_ieee1275_tpm_ihandle?
grub-core/lib/ieee1275/tcg2.c line 52
Quoted 8 lines
grub-core/lib/ieee1275/tcg2.c +4
-0+ grub_ieee1275_tpm_ihandle =IEEE1275_IHANDLE_INVALID ; } +if (grub_ieee1275_tpm_ihandle ==IEEE1275_IHANDLE_INVALID ) +return GRUB_ERR_UNKNOWN_DEVICE ; +return GRUB_ERR_NONE ; }
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v2 3/5] ieee1275/tcg2: Refactor grub_ieee1275_tpm_init
Quoted 11 lines · Daniel Kiper
Quoted 1 line · Stefan Berger
Move
tpm_get_tpm_versionintogrub_ieee1275_tpm_initand invalidates/tpm_get_tpm_version/tpm_get_tpm_version()/ s/grub_ieee1275_tpm_init/grub_ieee1275_tpm_init()/
Quoted 2 lines
grub_ieee1275_tpm_ihandlein case no TPM 2 could be detected. Try the initialization only once. Use thegrub_ieee1275_tpm_ihandleasCould you explain why you change logic here? I am not against that but I think it should be clarified why...
Ok, will do. It's basically to ensure that grub_tpm_present() always returns the same result for this here:
GRUB_MOD_INIT (tpm)
{
/*
* Even though this now calls ibmvtpm's grub_tpm_present() fromGRUB_MOD_INIT(),
* it does seem to call it late enough in the initialization sequence so
* that whatever discovered "device nodes" before this GRUB_MOD_INIT() is
* called, enables the ibmvtpm driver to see the device nodes. */
if (!grub_tpm_present())
return;
grub_verifier_register (&grub_tpm_verifier);
}
GRUB_MOD_FINI (tpm)
{
if (!grub_tpm_present())
return;
grub_verifier_unregister (&grub_tpm_verifier);
}
Quoted 101 lines
Quoted 45 lines
indicator for an available TPM instead of
grub_ieee1275_tpm_version, which can now be removed.Signed-off-by Stefan Berger <[email protected]>--- grub-core/commands/ieee1275/ibmvtpm.c | 2 +- grub-core/lib/ieee1275/tcg2.c | 43 +++++++++++---------------- include/grub/ieee1275/tpm.h | 1 - 3 files changed, 18 insertions(+), 28 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 !=IEEE1275_IHANDLE_INVALID )return tpm2_log_event (buf, size, pcr, description);return GRUB_ERR_NONE ;grub-core/lib/ieee1275/tcg2.c +0
-13@@ -23,39 +23,30 @@#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-core/lib/ieee1275/tcg2.c line 32
Quoted 10 lines
grub-core/lib/ieee1275/tcg2.c +3
-3- grub_ieee1275_tpm_version =2 ; -} +grub_ieee1275_ihandle_t grub_ieee1275_tpm_ihandle =IEEE1275_IHANDLE_INVALID ;grub_err_t grub_ieee1275_tpm_init (void ) { -static int init_success =0 ; +grub_ieee1275_phandle_t vtpm; +static int init_tried =0 ;We have a bool in the GRUB. Please use it...
Quoted 8 lines
grub-core/lib/ieee1275/tcg2.c +2
-4+char buffer[20 ]; -if (!init_success) +if (!init_tried) { -if (grub_ieee1275_open ("/vdevice/vtpm" , &grub_ieee1275_tpm_ihandle) <0 ) - { - grub_ieee1275_tpm_ihandle =IEEE1275_IHANDLE_INVALID ;grub-core/lib/ieee1275/tcg2.c line 40
Quoted 10 lines
grub-core/lib/ieee1275/tcg2.c +4
-6-return GRUB_ERR_UNKNOWN_DEVICE ; - } - - init_success =1 ; - -tpm_get_tpm_version (); + init_tried =1 ; + + if (grub_ieee1275_open ("/vdevice/vtpm", + &grub_ieee1275_tpm_ihandle) < 0 ||You do not need wrap this line...
grub-core/lib/ieee1275/tcg2.c line 43
Quoted 3 lines
grub-core/lib/ieee1275/tcg2.c +3
-0+grub_ieee1275_finddevice ("/vdevice/vtpm" , &vtpm) || +grub_ieee1275_get_property (vtpm,"compatible" , buffer, + sizeof (buffer), NULL) ||Same here...
grub-core/lib/ieee1275/tcg2.c line 44
Quoted 1 line
grub-core/lib/ieee1275/tcg2.c +1
-0+ grub_strcmp (buffer, "IBM,vtpm20"))Should not you call
grub_ieee1275_close()before invalidatinggrub_ieee1275_tpm_ihandle?grub-core/lib/ieee1275/tcg2.c line 52
Quoted 8 lines
grub-core/lib/ieee1275/tcg2.c +4
-0+ grub_ieee1275_tpm_ihandle =IEEE1275_IHANDLE_INVALID ; } +if (grub_ieee1275_tpm_ihandle ==IEEE1275_IHANDLE_INVALID ) +return GRUB_ERR_UNKNOWN_DEVICE ; +return GRUB_ERR_NONE ; }Daniel
Quoted 4 lines
_______________________________________________
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
PATCH v2 4/5 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. Convert the tcg2 driver code now to a built-in 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
Re: [PATCH v2 4/5] ieee1275/tcg2: Add TCG2 driver for ieee1275 PowerPC firmware
Quoted 5 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. Convert the tcg2 driver code now to a built-in driver.
The "built-in driver" phrase should not be used in that context. I explained it in the patch #2.
Quoted 50 lines
Signed-off-by Stefan Berger <[email protected]>--- 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 +6
-0@@ -23,6 +23,8 @@#include <grub/mm.h> #include <grub/misc.h> +#include <tcg2.h> +grub_ieee1275_ihandle_t grub_ieee1275_tpm_ihandle =IEEE1275_IHANDLE_INVALID ; grub_err_t@@ -50,3 +52,105 @@ grub_ieee1275_tpm_init (void)return GRUB_ERR_NONE ; } + +grub_err_t +grub_tcg2_get_max_output_size (grub_size_t *size) +{
grub-core/lib/ieee1275/tcg2.c grub_ieee1275_tpm_init (void) · line 68
Quoted 10 lines
grub-core/lib/ieee1275/tcg2.c +10
-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 ;
Bool please...
Quoted 41 lines
grub-core/lib/ieee1275/tcg2.c +41
-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 ; +} + +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) +{ +struct tpm_pass_through_to_tpm + {
grub-core/lib/ieee1275/tcg2.c grub_ieee1275_tpm_init (void) · line 119
Quoted 10 lines
grub-core/lib/ieee1275/tcg2.c +10
-0+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 ;
Ditto...
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v2 5/5 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
Re: [PATCH v2 5/5] tpm2_key_protector: Enable build for powerpc_ieee1275
Quoted 1 line · Stefan Berger
Signed-off-by Stefan Berger <[email protected]>
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 10 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,
Stefanv2:
- Applied Gary's R-b tag to 1/5
I think Gary would be OK with #1 but #2 - #5 should be confirmed by him...
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel