Preserve TPM log across kexec
Subsystems (4)
v2 cover Preserve TPM log across kexec
This series resolves an issue on PowerVM and KVM on Power where the memory the TPM log was held in may become inaccessible or corrupted after a kexec soft reboot. The solution on these two platforms is to store the whole log in the device tree because the device tree is preserved across a kexec with either of the two kexec syscalls.
Regards,
Stefan
v2:
- Added DT bindings patch (2/3)
- Reformulated commit messages and addded Fixes tags
- Follow Michael's suggestion on prom_init patch (1/3)
Stefan Berger (3):
powerpc/prom_init: Replace linux,sml-base/sml-size with linux,sml-log
dt-bindings: tpm: Add linux,sml-log to ibm,vtpm.yaml
tpm: of: If available use linux,sml-log to get the log and its size
.../devicetree/bindings/tpm/ibm,vtpm.yaml | 20 +++++++++-- .../devicetree/bindings/tpm/tpm-common.yaml | 14 +++++++- arch/powerpc/kernel/prom_init.c | 27 +++++++++----- drivers/char/tpm/eventlog/of.c | 36 ++++++------------- 4 files changed, 61 insertions(+), 36 deletions(-)
Signature · 1 line
2.43.0
RFC PATCH v2 1/3 powerpc/prom_init: Replace linux,sml-base/sml-size with linux,sml-log
linux,sml-base holds the address of a buffer with the TPM log. This buffer may become invalid after a kexec. To avoid accessing an invalid address or corrupted buffer, embed the whole TPM log in the device tree property linux,sml-log. This helps to protect the log since it is properly carried across a kexec soft reboot with both of the kexec syscalls.
Avoid having the firmware ingest the whole TPM log when calling prom_setprop but only create the linux,sml-log property as a place holder. Insert the actual TPM log during the tree flattening phase.
--- arch/powerpc/kernel/prom_init.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
arch/powerpc/kernel/prom_init.c +19 -8
@@ -211,6 +211,8 @@ static cell_t __prombss regbuf[1024]; static bool __prombss rtas_has_query_cpu_stopped; +static u64 __prombss sml_base; +static u32 __prombss sml_size;/* * Error results ... some OF calls will return "-1" on error, some
@@ -1954,17 +1956,15 @@ static void __init prom_instantiate_sml(void) }prom_printf (" done\n" ); -reserve_mem (base, size); - -prom_setprop (ibmvtpm_node,"/vdevice/vtpm" ,"linux,sml-base" , - &base,sizeof (base)); -prom_setprop (ibmvtpm_node,"/vdevice/vtpm" ,"linux,sml-size" , - &size,sizeof (size)); - -prom_debug ("sml base = 0x%llx\n" , base); +/* Add property now, defer adding log to tree flattening phase */ +prom_setprop (ibmvtpm_node,"/vdevice/vtpm" ,"linux,sml-log" , +NULL ,0 );prom_debug ("sml size = 0x%x\n" , size);prom_debug ("prom_instantiate_sml: end...\n" ); + + sml_base = base; + sml_size = size; }/*
@@ -2645,6 +2645,17 @@ static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start, } prev_name = sstart + soff; +if (!prom_strcmp ("linux,sml-log" , pname)) { +/* push property head */ +dt_push_token (OF_DT_PROP , mem_start, mem_end); +dt_push_token (sml_size, mem_start, mem_end); +dt_push_token (soff, mem_start, mem_end); +/* push property content */ + valp =make_room (mem_start, mem_end, sml_size,1 ); +memcpy (valp, (void *)sml_base, sml_size); + *mem_start =ALIGN (*mem_start,4 ); +continue ; + }/* get length */ l =call_prom ("getproplen" ,2 ,1 , node, pname);
Signature · 1 line
2.43.0
Re: [RFC PATCH v2 1/3] powerpc/prom_init: Replace linux,sml-base/sml-size with linux,sml-log
Le 11/03/2024 à 14:20, Stefan Berger a écrit :
Quoted 57 lines
linux,sml-base holds the address of a buffer with the TPM log. This buffer may become invalid after a kexec. To avoid accessing an invalid address or corrupted buffer, embed the whole TPM log in the device tree property linux,sml-log. This helps to protect the log since it is properly carried across a kexec soft reboot with both of the kexec syscalls.
Avoid having the firmware ingest the whole TPM log when calling
prom_setpropbut only create the linux,sml-log property as a place holder. Insert the actual TPM log during the tree flattening phase.Fixes 4a727429abec ("PPC64: Add support for instantiating SML from Open Firmware")Suggested-by Michael Ellerman <[email protected]>Signed-off-by Stefan Berger <[email protected]>--- arch/powerpc/kernel/prom_init.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)arch/powerpc/kernel/prom_init.c +8
-8@@ -211,6 +211,8 @@ static cell_t __prombss regbuf[1024]; static bool __prombss rtas_has_query_cpu_stopped; +static u64 __prombss sml_base; +static u32 __prombss sml_size;/* * Error results ... some OF calls will return "-1" on error, some @@ -1954,17 +1956,15 @@ static void __init prom_instantiate_sml(void) }prom_printf (" done\n" ); -reserve_mem (base, size); - -prom_setprop (ibmvtpm_node,"/vdevice/vtpm" ,"linux,sml-base" , - &base,sizeof (base)); -prom_setprop (ibmvtpm_node,"/vdevice/vtpm" ,"linux,sml-size" , - &size,sizeof (size)); - -prom_debug ("sml base = 0x%llx\n" , base); +/* Add property now, defer adding log to tree flattening phase */ +prom_setprop (ibmvtpm_node,"/vdevice/vtpm" ,"linux,sml-log" , +NULL ,0 );prom_debug ("sml size = 0x%x\n" , size);prom_debug ("prom_instantiate_sml: end...\n" ); + + sml_base = base; + sml_size = size; }/* @@ -2645,6 +2645,17 @@ static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start, }
arch/powerpc/kernel/prom_init.c static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start, · line 2655
Quoted 10 lines
arch/powerpc/kernel/prom_init.c +8
-0prev_name = sstart + soff; +if (!prom_strcmp ("linux,sml-log" , pname)) { +/* push property head */ +dt_push_token (OF_DT_PROP , mem_start, mem_end); +dt_push_token (sml_size, mem_start, mem_end); +dt_push_token (soff, mem_start, mem_end); +/* push property content */ + valp =make_room (mem_start, mem_end, sml_size,1 ); +memcpy (valp, (void *)sml_base, sml_size);
You can't cast a u64 into a pointer. If sml_base is an address, it must be declared as an unsigned long.
Build with pmac32_defconfig :
CC arch/powerpc/kernel/prom_init.oarch/powerpc/kernel/prom_init.c: In function 'scan_dt_build_struct':arch/powerpc/kernel/prom_init.c:2663:38: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
2663 | memcpy(valp, (void *)sml_base, sml_size);
| ^
cc1: all warnings being treated as errors
make[4]: *** [scripts/Makefile.build:243:arch/powerpc/kernel/prom_init.o] Error 1
Quoted 6 lines
arch/powerpc/kernel/prom_init.c +3
-0+ *mem_start =ALIGN (*mem_start,4 ); +continue ; + }/* get length */ l =call_prom ("getproplen" ,2 ,1 , node, pname);
Re: [RFC PATCH v2 1/3] powerpc/prom_init: Replace linux,sml-base/sml-size with linux,sml-log
Quoted 37 lines · Christophe Leroy
Le 11/03/2024 à 14:20, Stefan Berger a écrit :
Quoted 18 lines
linux,sml-base holds the address of a buffer with the TPM log. This buffer may become invalid after a kexec. To avoid accessing an invalid address or corrupted buffer, embed the whole TPM log in the device tree property linux,sml-log. This helps to protect the log since it is properly carried across a kexec soft reboot with both of the kexec syscalls.
Avoid having the firmware ingest the whole TPM log when calling
prom_setpropbut only create the linux,sml-log property as a place holder. Insert the actual TPM log during the tree flattening phase.Fixes 4a727429abec ("PPC64: Add support for instantiating SML from Open Firmware")Suggested-by Michael Ellerman <[email protected]>Signed-off-by Stefan Berger <[email protected]>---
arch/powerpc/kernel/prom_init.c +0
-0@@ -2645,6 +2645,17 @@ static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start, }arch/powerpc/kernel/prom_init.c static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start, · line 2655
Quoted 10 lines
arch/powerpc/kernel/prom_init.c +8
-0prev_name = sstart + soff; +if (!prom_strcmp ("linux,sml-log" , pname)) { +/* push property head */ +dt_push_token (OF_DT_PROP , mem_start, mem_end); +dt_push_token (sml_size, mem_start, mem_end); +dt_push_token (soff, mem_start, mem_end); +/* push property content */ + valp =make_room (mem_start, mem_end, sml_size,1 ); +memcpy (valp, (void *)sml_base, sml_size);You can't cast a u64 into a pointer. If
sml_baseis an address, it must be declared as an unsigned long.Build with
pmac32_defconfig:
Quoted 9 lines
CC
arch/powerpc/kernel/prom_init.oarch/powerpc/kernel/prom_init.c: In function 'scan_dt_build_struct':arch/powerpc/kernel/prom_init.c:2663:38: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
2663 |memcpy(valp, (void *)sml_base, sml_size);
| ^
cc1: all warnings being treated as errors
make[4]: *** [scripts/Makefile.build:243:arch/powerpc/kernel/prom_init.o] Error 1
Next round will have this block under #ifdef CONFIG_PPC64.
Thanks.
Re: [RFC PATCH v2 1/3] powerpc/prom_init: Replace linux,sml-base/sml-size with linux,sml-log
In reply to Stefan BergerQuoted 23 lines · Stefan Berger
linux,sml-base holds the address of a buffer with the TPM log. This buffer may become invalid after a kexec. To avoid accessing an invalid address or corrupted buffer, embed the whole TPM log in the device tree property linux,sml-log. This helps to protect the log since it is properly carried across a kexec soft reboot with both of the kexec syscalls.
Avoid having the firmware ingest the whole TPM log when calling
prom_setpropbut only create the linux,sml-log property as a place holder. Insert the actual TPM log during the tree flattening phase.Fixes 4a727429abec ("PPC64: Add support for instantiating SML from Open Firmware")Suggested-by Michael Ellerman <[email protected]>Signed-off-by Stefan Berger <[email protected]>--- arch/powerpc/kernel/prom_init.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)arch/powerpc/kernel/prom_init.c +0
-0
arch/powerpc/kernel/prom_init.c static cell_t __prombss regbuf[1024]; · line 215
Quoted 5 lines
arch/powerpc/kernel/prom_init.c +2
-0@@ -211,6 +211,8 @@ static cell_t __prombss regbuf[1024]; static bool __prombss rtas_has_query_cpu_stopped; +static u64 __prombss sml_base; +static u32 __prombss sml_size;
Should inside an #ifdef CONFIG_PPC64 since prom_instantiate_sml() is?
Quoted 32 lines
arch/powerpc/kernel/prom_init.c +7
-8/* * Error results ... some OF calls will return "-1" on error, some @@ -1954,17 +1956,15 @@ static void __init prom_instantiate_sml(void) }prom_printf (" done\n" ); -reserve_mem (base, size); - -prom_setprop (ibmvtpm_node,"/vdevice/vtpm" ,"linux,sml-base" , - &base,sizeof (base)); -prom_setprop (ibmvtpm_node,"/vdevice/vtpm" ,"linux,sml-size" , - &size,sizeof (size)); - -prom_debug ("sml base = 0x%llx\n" , base); +/* Add property now, defer adding log to tree flattening phase */ +prom_setprop (ibmvtpm_node,"/vdevice/vtpm" ,"linux,sml-log" , +NULL ,0 );prom_debug ("sml size = 0x%x\n" , size);prom_debug ("prom_instantiate_sml: end...\n" ); + + sml_base = base; + sml_size = size; }/* @@ -2645,6 +2645,17 @@ static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start, } prev_name = sstart + soff; +if (!prom_strcmp ("linux,sml-log" , pname)) {
arch/powerpc/kernel/prom_init.c static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start, · line 2658
Quoted 10 lines
arch/powerpc/kernel/prom_init.c +10
-0+/* push property head */ +dt_push_token (OF_DT_PROP , mem_start, mem_end); +dt_push_token (sml_size, mem_start, mem_end); +dt_push_token (soff, mem_start, mem_end); +/* push property content */ + valp =make_room (mem_start, mem_end, sml_size,1 ); +memcpy (valp, (void *)sml_base, sml_size); + *mem_start =ALIGN (*mem_start,4 ); +continue ; + }
Same question as above.
Regards,
Jerry
Quoted 6 lines
arch/powerpc/kernel/prom_init.c +0
-0/* get length */ l =call_prom ("getproplen" ,2 ,1 , node, pname);Signature · 1 line
2.43.0
Jarkko Sakkinen
maintainerRe: [RFC PATCH v2 1/3] powerpc/prom_init: Replace linux,sml-base/sml-size with linux,sml-log
In reply to Stefan BergerQuoted 6 lines · Stefan Berger
linux,sml-base holds the address of a buffer with the TPM log. This buffer may become invalid after a kexec. To avoid accessing an invalid address or corrupted buffer, embed the whole TPM log in the device tree property linux,sml-log. This helps to protect the log since it is properly carried across a kexec soft reboot with both of the kexec syscalls.
- Describe the environment where TPM log gets corrupted.
- Describe why TPM log gets corrupted on kexec.
Quoted 4 lines
Avoid having the firmware ingest the whole TPM log when calling
prom_setpropbut only create the linux,sml-log property as a place holder. Insert the actual TPM log during the tree flattening phase.
This commit message should shed some light about reasons of the corruption in order to conclude that it should be fixed up like this. I.e. why the "post-state" is a legit state where can be continued despite a log being corrupted. Especially in security features this is pretty essential information.
BR, Jarkko
RFC PATCH v2 2/3 dt-bindings: tpm: Add linux,sml-log to ibm,vtpm.yaml
In reply to Stefan BergerAdd linux,sml-log, which carries the firmware TPM log in a uint8-array, to the properties. Either this property is required or both linux,sml-base and linux,sml-size are required. Add a test case for verification.
--- .../devicetree/bindings/tpm/ibm,vtpm.yaml | 20 +++++++++++++++++-- .../devicetree/bindings/tpm/tpm-common.yaml | 14 ++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/tpm/ibm,vtpm.yaml +18 -2
@@ -74,8 +74,6 @@ required: - ibm,my-dma-window - ibm,my-drc-index - ibm,loc-code - - linux,sml-base - - linux,sml-size allOf: - $ref: tpm-common.yaml#
@@ -102,3 +100,21 @@ examples: linux,sml-size = <0xbce10200>; }; }; + - | + soc { + #address-cells = <1>; + #size-cells = <0>; + + tpm@30000003 { + compatible = "IBM,vtpm20"; + device_type = "IBM,vtpm"; + reg = <0x30000003>; + interrupts = <0xa0003 0x0>; + ibm,#dma-address-cells = <0x2>; + ibm,#dma-size-cells = <0x2>; + ibm,my-dma-window = <0x10000003 0x0 0x0 0x0 0x10000000>; + ibm,my-drc-index = <0x30000003>; + ibm,loc-code = "U9080.HEX.134CA08-V7-C3"; + linux,sml-log = <00 00 00 00 03 00 00>; + }; + };
Documentation/devicetree/bindings/tpm/tpm-common.yaml +13 -1
@@ -30,6 +30,11 @@ properties: size of reserved memory allocated for firmware event log $ref: /schemas/types.yaml#/definitions/uint32 + linux,sml-log: + description: + Content of firmware event log + $ref: /schemas/types.yaml#/definitions/uint8-array + memory-region: description: reserved memory allocated for firmware event log maxItems: 1
@@ -53,15 +58,22 @@ dependentRequired: linux,sml-base: ['linux,sml-size'] linux,sml-size: ['linux,sml-base'] -# must only have either memory-region or linux,sml-base +# must only have either memory-region or linux,sml-base/size or linux,sml-log # as well as either resets or reset-gpios dependentSchemas: memory-region: properties: linux,sml-base: false + linux,sml-log: false linux,sml-base: properties: memory-region: false + linux,sml-log: false + linux,sml-log: + properties: + memory-region: false + linux,sml-base: false + linux,sml-size: false resets: properties: reset-gpios: false
Signature · 1 line
2.43.0
Re: [RFC PATCH v2 2/3] dt-bindings: tpm: Add linux,sml-log to ibm,vtpm.yaml
Quoted 5 lines · Stefan Berger
Add linux,sml-log, which carries the firmware TPM log in a uint8-array, to the properties. Either this property is required or both linux,sml-base and linux,sml-size are required. Add a test case for verification.
Fixes 82003e0487fb ("Documentation: tpm: add the IBM Virtual TPM device tree binding documentation")
The Fixes tag is confusing. The patch won't even apply cleanly to the v4.10 commit referenced here as the conversion to yaml happened only recently with v6.8.
Why is the Fixes tag necessary in the first place? Same question for the other patches in the series. This looks like feature work rather than a fix. Not sure whether it satisfies the "obviously correct" rule per Documentation/process/stable-kernel-rules.rst.
Documentation/devicetree/bindings/tpm/ibm,vtpm.yaml required: · line 78
Quoted 8 lines
Documentation/devicetree/bindings/tpm/ibm,vtpm.yaml +0
-2@@ -74,8 +74,6 @@ required: - ibm,my-dma-window - ibm,my-drc-index - ibm,loc-code - - linux,sml-base - - linux,sml-size
I assume that either these two or the new "linux,sml-log" property are (still) required? If so, a quick grep through the bindings (e.g. auxdisplay/img,ascii-lcd.yaml) shows that the following might work:
required:
- ...
oneOf:
- required:
- linux,sml-base
- required:
- linux,sml-log
Documentation/devicetree/bindings/tpm/tpm-common.yaml properties: · line 35
Quoted 9 lines
Documentation/devicetree/bindings/tpm/tpm-common.yaml +3
-0@@ -30,6 +30,11 @@ properties: size of reserved memory allocated for firmware event log $ref: /schemas/types.yaml#/definitions/uint32 + linux,sml-log: + description: + Content of firmware event log
Please add one or two sentences of context so that readers don't need to use git blame + git log to find out what this is for. (Mention at least that the property may be used to pass the log to a kexec kernel.)
Quoted 7 lines
Documentation/devicetree/bindings/tpm/tpm-common.yaml +1
-1-# must only have either memory-region or linux,sml-base +# must only have either memory-region or linux,sml-base/size or linux,sml-log # as well as either resets or reset-gpios dependentSchemas: memory-region: properties: linux,sml-base: false
Documentation/devicetree/bindings/tpm/tpm-common.yaml dependentRequired: · line 76
Quoted 10 lines
Documentation/devicetree/bindings/tpm/tpm-common.yaml +7
-0+ linux,sml-log: false linux,sml-base: properties: memory-region: false + linux,sml-log: false + linux,sml-log: + properties: + memory-region: false + linux,sml-base: false + linux,sml-size: false
Could you add "linux,sml-size: false" to "memory-region" as well while at it for consistency?
Thanks,
Lukas
Re: [RFC PATCH v2 2/3] dt-bindings: tpm: Add linux,sml-log to ibm,vtpm.yaml
Quoted 10 lines · Lukas Wunner
Quoted 5 lines · Stefan Berger
Add linux,sml-log, which carries the firmware TPM log in a uint8-array, to the properties. Either this property is required or both linux,sml-base and linux,sml-size are required. Add a test case for verification.
Fixes 82003e0487fb ("Documentation: tpm: add the IBM Virtual TPM device tree binding documentation")The Fixes tag is confusing. The patch won't even apply cleanly to the v4.10 commit referenced here as the conversion to yaml happened only recently with v6.8.
Then that's as far back (6.8) as the series may be applied. I put the Fixes tag on the first appearance of sml-base/sml-size since for kexec this was never correct.
Quoted 5 lines
Why is the Fixes tag necessary in the first place? Same question for the other patches in the series. This looks like feature work rather than a fix. Not sure whether it satisfies the "obviously correct" rule per
Documentation/process/stable-kernel-rules.rst.
It is a fix for the interaction of the TPM firmware log with kexec. The sml-base buffer pointer was never protected across a kexec.
Quoted 16 lines
Documentation/devicetree/bindings/tpm/ibm,vtpm.yaml required: · line 78
Quoted 10 lines
Documentation/devicetree/bindings/tpm/ibm,vtpm.yaml +0
-2@@ -74,8 +74,6 @@ required: - ibm,my-dma-window - ibm,my-drc-index - ibm,loc-code - - linux,sml-base - - linux,sml-sizeI assume that either these two or the new "linux,sml-log" property are (still) required? If so, a quick grep through the bindings (e.g.
auxdisplay/img,ascii-lcd.yaml) shows that the following might work:
Quoted 9 lines
required:
- ...oneOf:
- required:
- linux,sml-base
- required:
- linux,sml-log
You're right, they need to be here since examples could now omit sml-base or sml-log. I added them. Thanks.
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/tpm/tpm-common.yaml +0
-0@@ -30,6 +30,11 @@ properties: size of reserved memory allocated for firmware event log $ref: /schemas/types.yaml#/definitions/uint32
Quoted 8 lines
Documentation/devicetree/bindings/tpm/tpm-common.yaml properties: · line 35
Quoted 3 lines
Documentation/devicetree/bindings/tpm/tpm-common.yaml +3
-0+ linux,sml-log: + description: + Content of firmware event logPlease add one or two sentences of context so that readers don't need to use git blame + git log to find out what this is for. (Mention at least that the property may be used to pass the log to a kexec kernel.)
Ok, will do:
Content of firmware event log embedded in device tree to be safely carried across a kexec soft reboot.
Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/tpm/tpm-common.yaml +3
-1-# must only have either memory-region or linux,sml-base +# must only have either memory-region or linux,sml-base/size or linux,sml-log # as well as either resets or reset-gpios dependentSchemas: memory-region: properties: linux,sml-base: false + linux,sml-log: false linux,sml-base: properties: memory-region: false + linux,sml-log: false
Quoted 8 lines
Documentation/devicetree/bindings/tpm/tpm-common.yaml dependentRequired: · line 76
Quoted 5 lines
Documentation/devicetree/bindings/tpm/tpm-common.yaml +5
-0+ linux,sml-log: + properties: + memory-region: false + linux,sml-base: false + linux,sml-size: falseCould you add "linux,sml-size: false" to "memory-region" as well while at it for consistency?
Done. Thanks.
Stefan
Quoted 4 lines
Thanks,
Lukas
Jarkko Sakkinen
maintainerRe: [RFC PATCH v2 2/3] dt-bindings: tpm: Add linux,sml-log to ibm,vtpm.yaml
In reply to Lukas WunnerQuoted 7 lines · Lukas Wunner
Quoted 5 lines · Stefan Berger
Add linux,sml-log, which carries the firmware TPM log in a uint8-array, to the properties. Either this property is required or both linux,sml-base and linux,sml-size are required. Add a test case for verification.
Fixes 82003e0487fb ("Documentation: tpm: add the IBM Virtual TPM device tree binding documentation")
Quoted 8 lines
The Fixes tag is confusing. The patch won't even apply cleanly to the v4.10 commit referenced here as the conversion to yaml happened only recently with v6.8.
Why is the Fixes tag necessary in the first place? Same question for the other patches in the series. This looks like feature work rather than a fix. Not sure whether it satisfies the "obviously correct" rule per
Documentation/process/stable-kernel-rules.rst.
I'm not yet sure whether these are bug fixes and or improvements because I did not fully understand the scenario where TPM corrupts the event log so that part reminds to be seen.
Probably once I fully understand what is going on, it is possible to argue on that.
BR, Jarkko
RFC PATCH v2 3/3 tpm: of: If available use linux,sml-log to get the log and its size
In reply to Stefan BergerIf linux,sml-log is available use it to get the TPM log rather than the pointer found in linux,sml-base. This resolves an issue on PowerVM and KVM on Power where after a kexec the memory pointed to by linux,sml-base may have become inaccessible or corrupted. Also, linux,sml-log has replaced linux,sml-base and linux,sml-size on these two platforms.
Keep the handling of linux,sml-base/sml-size for powernv platforms that provide the two properties via skiboot.
--- drivers/char/tpm/eventlog/of.c | 36 +++++++++++----------------------- 1 file changed, 11 insertions(+), 25 deletions(-)
drivers/char/tpm/eventlog/of.c +11 -25
@@ -54,8 +54,8 @@ int tpm_read_log_of(struct tpm_chip *chip)const u32 *sizep;const u64 *basep;struct tpm_bios_log *log; +const void *logp;u32 size; -u64 base; log = &chip->log;if (chip->dev.parent && chip->dev.parent->of_node)
@@ -66,37 +66,23 @@ int tpm_read_log_of(struct tpm_chip *chip)if (of_property_read_bool (np,"powered-while-suspended" )) chip->flags |=TPM_CHIP_FLAG_ALWAYS_POWERED ; - sizep =of_get_property (np,"linux,sml-size" ,NULL ); - basep =of_get_property (np,"linux,sml-base" ,NULL ); -if (sizep ==NULL && basep ==NULL ) -return tpm_read_log_memory_region (chip); -if (sizep ==NULL || basep ==NULL ) -return -EIO ; - -/* -* For both vtpm/tpm, firmware has log addr and log size in big -* endian format. But in case of vtpm, there is a method called -* sml-handover which is run during kernel init even before -* device tree is setup. This sml-handover function takes care -* of endianness and writes to sml-base and sml-size in little -* endian format. For this reason, vtpm doesn't need conversion -* but physical tpm needs the conversion. -*/ -if (of_property_match_string (np,"compatible" ,"IBM,vtpm" ) <0 && -of_property_match_string (np,"compatible" ,"IBM,vtpm20" ) <0 ) { + logp =of_get_property (np,"linux,sml-log" , &size); +if (logp ==NULL ) { + sizep =of_get_property (np,"linux,sml-size" ,NULL ); + basep =of_get_property (np,"linux,sml-base" ,NULL ); +if (sizep ==NULL && basep ==NULL ) +return tpm_read_log_memory_region (chip); +if (sizep ==NULL || basep ==NULL ) +return -EIO ; size =be32_to_cpup ((__force __be32 *)sizep); - base =be64_to_cpup ((__force __be64 *)basep); - }else { - size = *sizep; - base = *basep; + logp =__va (be64_to_cpup ((__force __be64 *)basep)); } -if (size ==0 ) {dev_warn (&chip->dev,"%s: Event log area empty\n" , __func__);return -EIO ; } - log->bios_event_log =devm_kmemdup (&chip->dev,__va (base), size,GFP_KERNEL ); + log->bios_event_log =devm_kmemdup (&chip->dev, logp, size,GFP_KERNEL );if (!log->bios_event_log)return -ENOMEM ;
Signature · 1 line
2.43.0
Jarkko Sakkinen
maintainerRe: [RFC PATCH v2 3/3] tpm: of: If available use linux,sml-log to get the log and its size
Quoted 11 lines · Stefan Berger
If linux,sml-log is available use it to get the TPM log rather than the pointer found in linux,sml-base. This resolves an issue on PowerVM and KVM on Power where after a kexec the memory pointed to by linux,sml-base may have become inaccessible or corrupted. Also, linux,sml-log has replaced linux,sml-base and linux,sml-size on these two platforms.
Keep the handling of linux,sml-base/sml-size for powernv platforms that provide the two properties via skiboot.
Fixes c5df39262dd5 ("drivers/char/tpm: Add securityfs support for event log")Signed-off-by Stefan Berger <[email protected]>
I'm worried about not being up to date and instead using "cached" values when verifying anything from a security chip. Does this guarantee that TPM log is corrupted and will not get updated somehow?
BR, Jarkko
Re: [RFC PATCH v2 3/3] tpm: of: If available use linux,sml-log to get the log and its size
Quoted 10 lines · Jarkko Sakkinen
Quoted 9 lines · Stefan Berger
If linux,sml-log is available use it to get the TPM log rather than the pointer found in linux,sml-base. This resolves an issue on PowerVM and KVM on Power where after a kexec the memory pointed to by linux,sml-base may have become inaccessible or corrupted. Also, linux,sml-log has replaced linux,sml-base and linux,sml-size on these two platforms.
Keep the handling of linux,sml-base/sml-size for powernv platforms that provide the two properties via skiboot.
Quoted 6 lines
Quoted 2 lines
Fixes c5df39262dd5 ("drivers/char/tpm: Add securityfs support for event log")Signed-off-by Stefan Berger <[email protected]>I'm worried about not being up to date and instead using "cached" values when verifying anything from a security chip. Does this guarantee that TPM log is corrupted and will not get updated somehow?
What do you mean 'guarantee that TPM log is corrupted'?
The TPM was handed over from the firmware to Linux and the firmware then freed all memory associated with the log and will then not create a new log or touch the TPM or do anything that would require an update to the handed-over log. Linux also does not append to the firmware log. So whatever we now find in linux,sml-log would be the latest firmware log and the state of the 'firmware PCRs' computed from it should correspond to the current state of the 'firmware PCRs'.
Quoted 3 lines
BR, Jarkko
Jarkko Sakkinen
maintainerRe: [RFC PATCH v2 3/3] tpm: of: If available use linux,sml-log to get the log and its size
Quoted 16 lines · Stefan Berger
Quoted 13 lines · Jarkko Sakkinen
Quoted 11 lines · Stefan Berger
If linux,sml-log is available use it to get the TPM log rather than the pointer found in linux,sml-base. This resolves an issue on PowerVM and KVM on Power where after a kexec the memory pointed to by linux,sml-base may have become inaccessible or corrupted. Also, linux,sml-log has replaced linux,sml-base and linux,sml-size on these two platforms.
Keep the handling of linux,sml-base/sml-size for powernv platforms that provide the two properties via skiboot.
Fixes c5df39262dd5 ("drivers/char/tpm: Add securityfs support for event log")Signed-off-by Stefan Berger <[email protected]>
Quoted 6 lines
Quoted 3 lines
I'm worried about not being up to date and instead using "cached" values when verifying anything from a security chip. Does this guarantee that TPM log is corrupted and will not get updated somehow?
What do you mean 'guarantee that TPM log is corrupted'?
I presume that this is for power architecture but I have no idea what leads log being corrupted, and is the scope all of that that arch or some subset of CPUs.
The commit message is not very detailed on kexec scenario. It more like assumes that reader knows all the detail beforehand. So probably this will start to make sense once the backing story is improved, that's all.
Quoted 7 lines
The TPM was handed over from the firmware to Linux and the firmware then freed all memory associated with the log and will then not create a new log or touch the TPM or do anything that would require an update to the handed-over log. Linux also does not append to the firmware log. So whatever we now find in linux,sml-log would be the latest firmware log and the state of the 'firmware PCRs' computed from it should correspond to the current state of the 'firmware PCRs'.
So on what CPU this happens and is there any bigger picture for that design choice in the firmware?
If it is a firmware bug, this should emit FW_BUG log message. If not, then this commit message should provide the necessary context.
BR, Jarkko
Re: [RFC PATCH v2 3/3] tpm: of: If available use linux,sml-log to get the log and its size
Quoted 17 lines · Jarkko Sakkinen
Quoted 16 lines · Stefan Berger
Quoted 13 lines · Jarkko Sakkinen
Quoted 11 lines · Stefan Berger
If linux,sml-log is available use it to get the TPM log rather than the pointer found in linux,sml-base. This resolves an issue on PowerVM and KVM on Power where after a kexec the memory pointed to by linux,sml-base may have become inaccessible or corrupted. Also, linux,sml-log has replaced linux,sml-base and linux,sml-size on these two platforms.
Keep the handling of linux,sml-base/sml-size for powernv platforms that provide the two properties via skiboot.
Fixes c5df39262dd5 ("drivers/char/tpm: Add securityfs support for event log")Signed-off-by Stefan Berger <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I'm worried about not being up to date and instead using "cached" values when verifying anything from a security chip. Does this guarantee that TPM log is corrupted and will not get updated somehow?
What do you mean 'guarantee that TPM log is corrupted'?
I presume that this is for power architecture but I have no idea what
Yes it is for Power. From commit message above: "This resolves an issue on PowerVM and KVM on Power where after a kexec the memory pointed to by linux,sml-base may have become inaccessible or corrupted."
Quoted 2 lines
leads log being corrupted, and is the scope all of that that arch or some subset of CPUs.
Every CPU will see a corrupted log.
Quoted 2 lines
The commit message is not very detailed on kexec scenario. It more like
I guess what is missing in the message that the buffer was not properly protected during the kexec and may have been overwritten for example since it was mistakenly assumed to be free memory?
Quoted 12 lines
assumes that reader knows all the detail beforehand. So probably this will start to make sense once the backing story is improved, that's all.
Quoted 7 lines
The TPM was handed over from the firmware to Linux and the firmware then freed all memory associated with the log and will then not create a new log or touch the TPM or do anything that would require an update to the handed-over log. Linux also does not append to the firmware log. So whatever we now find in linux,sml-log would be the latest firmware log and the state of the 'firmware PCRs' computed from it should correspond to the current state of the 'firmware PCRs'.
Quoted 2 lines
So on what CPU this happens and is there any bigger picture for that design choice in the firmware?
The firmware provides a call sml-handover, which hands over the TPM log to the caller and at the same time frees the log. You cannot call the firmware a 2nd time for the log.
Quoted 3 lines
If it is a firmware bug, this should emit
FW_BUGlog message. If not, then this commit message should provide the necessary context.
It's not a firmware bug. The issue is that the buffer holding the TPM log is not properly carried across a kexec soft reboot and may for example have been overwritten since it was assumed to be free memory.
Quoted 3 lines
BR, Jarkko