tpm: Disable tpm verifier if tpm is not present
PATCH v2 1/1 tpm: Disable tpm verifier if tpm is not present
This helps to prevent out of memory error when reading large files via disabling tpm device as verifier has to read all content into memory in one chunk to measure the hash and extend to tpm.
--- grub-core/commands/efi/tpm.c | 37 ++++++++++++++++++++++++++++++++++++ grub-core/commands/tpm.c | 4 ++++ include/grub/tpm.h | 1 + 3 files changed, 42 insertions(+)
grub-core/commands/efi/tpm.c +37 -0
@@ -287,3 +287,40 @@ grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr,else return grub_tpm2_log_event (tpm_handle, buf, size, pcr, description); } + +int +grub_tpm_present (void ) +{ +grub_efi_handle_t tpm_handle; +grub_efi_uint8_t protocol_version; + +if (!grub_tpm_handle_find (&tpm_handle, &protocol_version)) +return 0 ; + +if (protocol_version ==1 ) + { +grub_efi_tpm_protocol_t *tpm; + + tpm =grub_efi_open_protocol (tpm_handle, &tpm_guid, +GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL ); +if (!tpm) + { +grub_dprintf ("tpm" ,"Cannot open TPM protocol\n" ); +return 0 ; + } +return grub_tpm1_present (tpm); + } +else + { +grub_efi_tpm2_protocol_t *tpm; + + tpm =grub_efi_open_protocol (tpm_handle, &tpm2_guid, +GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL ); +if (!tpm) + { +grub_dprintf ("tpm" ,"Cannot open TPM protocol\n" ); +return 0 ; + } +return grub_tpm2_present (tpm); + } +}
grub-core/commands/tpm.c +4 -0
@@ -86,10 +86,14 @@ struct grub_file_verifier grub_tpm_verifier = {GRUB_MOD_INIT (tpm) { +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); }
include/grub/tpm.h +1 -0
@@ -36,4 +36,5 @@grub_err_t grub_tpm_measure (unsigned char *buf,grub_size_t size,grub_uint8_t pcr,const char *description); +int grub_tpm_present (void );#endif
Signature · 1 line
2.35.3
Quoted 3 lines · Michael Chang via Grub-devel
This helps to prevent out of memory error when reading large files via disabling tpm device as verifier has to read all content into memory in one chunk to measure the hash and extend to tpm.
How does this patch help when the TPM is present in the system?
Daniel
Quoted 6 lines · Daniel Kiper
Quoted 3 lines · Michael Chang via Grub-devel
This helps to prevent out of memory error when reading large files via disabling tpm device as verifier has to read all content into memory in one chunk to measure the hash and extend to tpm.
How does this patch help when the TPM is present in the system?
If the firmware menu offers option to disable TPM device, then this patch can be useful to get around 'out of memory error' through disabling TPM device from firmware in order to make tpm verifier won't be in the way of reading huge files.
This is essentially a compromised solution as long as tpm module can be a built-in module in signed image and at the same time user may come across the need to open huge files, for eg, loopback mount in grub for the rescue image. In this case they could be opted in to disable tpm device from firmware to proceed if they run into out of memory or other (slow) reading issues.
Thanks,
Michael
Quoted 7 lines
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 13 lines · Michael Chang via Grub-devel
Quoted 6 lines · Daniel Kiper
Quoted 3 lines · Michael Chang via Grub-devel
This helps to prevent out of memory error when reading large files via disabling tpm device as verifier has to read all content into memory in one chunk to measure the hash and extend to tpm.
How does this patch help when the TPM is present in the system?
If the firmware menu offers option to disable TPM device, then this patch can be useful to get around 'out of memory error' through disabling TPM device from firmware in order to make tpm verifier won't be in the way of reading huge files.
Quoted 6 lines
This is essentially a compromised solution as long as tpm module can be a built-in module in signed image and at the same time user may come across the need to open huge files, for eg, loopback mount in grub for the rescue image. In this case they could be opted in to disable tpm device from firmware to proceed if they run into out of memory or other (slow) reading issues.
I think I would prefer something similar to this [1] patch. Of course if [1] is not enough...
Daniel
[1] http://git.savannah.gnu.org/gitweb/?p=grub.git;a=commit;h=a4356538d03c5a5350790b6453b523fb9214c2e9
Quoted 21 lines · Daniel Kiper
Quoted 13 lines · Michael Chang via Grub-devel
Quoted 6 lines · Daniel Kiper
Quoted 3 lines · Michael Chang via Grub-devel
This helps to prevent out of memory error when reading large files via disabling tpm device as verifier has to read all content into memory in one chunk to measure the hash and extend to tpm.
How does this patch help when the TPM is present in the system?
If the firmware menu offers option to disable TPM device, then this patch can be useful to get around 'out of memory error' through disabling TPM device from firmware in order to make tpm verifier won't be in the way of reading huge files.
Quoted 6 lines
This is essentially a compromised solution as long as tpm module can be a built-in module in signed image and at the same time user may come across the need to open huge files, for eg, loopback mount in grub for the rescue image. In this case they could be opted in to disable tpm device from firmware to proceed if they run into out of memory or other (slow) reading issues.
Quoted 2 lines
I think I would prefer something similar to this [1] patch. Of course if [1] is not enough...
The tpm verifier attempts to set GRUB_VERIFY_FLAGS_SINGLE_CHUNK for all incoming files, which gets loaded into memory in its entirety as an duplicated copy to disk files. The overhead is too huge to some low profile hardwares with smaller memory or when the boot path has to cover very large files, hence the out of memory error.
I think it inevitable to use GRUB_VERIFY_FLAGS_SINGLE_CHUNK as tpm measures and extends file intergrity. But we ought to avoid the overhead when TPM device is not present or disabled by the user.
The patch [1] seems to deal with the tpm error which prevents a file from being opened, which is orthogonal to the memory allocation issue in the common verifier before tpm doing measurement.
Thanks,
Michael
Quoted 9 lines
Daniel
[1] http://git.savannah.gnu.org/gitweb/?p=grub.git;a=commit;h=a4356538d03c5a5350790b6453b523fb9214c2e9
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 31 lines · Michael Chang via Grub-devel
Quoted 21 lines · Daniel Kiper
Quoted 13 lines · Michael Chang via Grub-devel
Quoted 6 lines · Daniel Kiper
Quoted 3 lines · Michael Chang via Grub-devel
This helps to prevent out of memory error when reading large files via disabling tpm device as verifier has to read all content into memory in one chunk to measure the hash and extend to tpm.
How does this patch help when the TPM is present in the system?
If the firmware menu offers option to disable TPM device, then this patch can be useful to get around 'out of memory error' through disabling TPM device from firmware in order to make tpm verifier won't be in the way of reading huge files.
Quoted 6 lines
This is essentially a compromised solution as long as tpm module can be a built-in module in signed image and at the same time user may come across the need to open huge files, for eg, loopback mount in grub for the rescue image. In this case they could be opted in to disable tpm device from firmware to proceed if they run into out of memory or other (slow) reading issues.
Quoted 2 lines
I think I would prefer something similar to this [1] patch. Of course if [1] is not enough...
The tpm verifier attempts to set
GRUB_VERIFY_FLAGS_SINGLE_CHUNKfor all incoming files, which gets loaded into memory in its entirety as an duplicated copy to disk files. The overhead is too huge to some low profile hardwares with smaller memory or when the boot path has to cover very large files, hence the out of memory error.
Quoted 7 lines
I think it inevitable to use
GRUB_VERIFY_FLAGS_SINGLE_CHUNKas tpm measures and extends file intergrity. But we ought to avoid the overhead when TPM device is not present or disabled by the user.The patch [1] seems to deal with the tpm error which prevents a file from being opened, which is orthogonal to the memory allocation issue in the common verifier before tpm doing measurement.
This is what I expected. So, that is why I said "Of course if [1] is not enough..."... :-) Now I think it would be nice if TPM verifier is disabled when the TPM device is broken/disabled/... and/or somebody sets a separate environemnt variable in the GRUB. WDYT?
Daniel
[1] http://git.savannah.gnu.org/gitweb/?p=grub.git;a=commit;h=a4356538d03c5a5350790b6453b523fb9214c2e9
Quoted 36 lines · Daniel Kiper
Quoted 35 lines · Michael Chang via Grub-devel
Quoted 21 lines · Daniel Kiper
Quoted 13 lines · Michael Chang via Grub-devel
Quoted 6 lines · Daniel Kiper
Quoted 3 lines · Michael Chang via Grub-devel
This helps to prevent out of memory error when reading large files via disabling tpm device as verifier has to read all content into memory in one chunk to measure the hash and extend to tpm.
How does this patch help when the TPM is present in the system?
If the firmware menu offers option to disable TPM device, then this patch can be useful to get around 'out of memory error' through disabling TPM device from firmware in order to make tpm verifier won't be in the way of reading huge files.
Quoted 6 lines
This is essentially a compromised solution as long as tpm module can be a built-in module in signed image and at the same time user may come across the need to open huge files, for eg, loopback mount in grub for the rescue image. In this case they could be opted in to disable tpm device from firmware to proceed if they run into out of memory or other (slow) reading issues.
Quoted 2 lines
I think I would prefer something similar to this [1] patch. Of course if [1] is not enough...
The tpm verifier attempts to set
GRUB_VERIFY_FLAGS_SINGLE_CHUNKfor all incoming files, which gets loaded into memory in its entirety as an duplicated copy to disk files. The overhead is too huge to some low profile hardwares with smaller memory or when the boot path has to cover very large files, hence the out of memory error.I think it inevitable to use
GRUB_VERIFY_FLAGS_SINGLE_CHUNKas tpm measures and extends file intergrity. But we ought to avoid the overhead when TPM device is not present or disabled by the user.
Quoted 8 lines
Quoted 3 lines
The patch [1] seems to deal with the tpm error which prevents a file from being opened, which is orthogonal to the memory allocation issue in the common verifier before tpm doing measurement.
This is what I expected. So, that is why I said "Of course if [1] is not enough..."... :-) Now I think it would be nice if TPM verifier is disabled when the TPM device is broken/disabled/... and/or somebody sets a separate environemnt variable in the GRUB. WDYT?
I'm not sure if a separate environment a good idea, because it would expose the funtion to disable verifier in a way much readily accessible through one of grub command line interface, grub.cfg and grubenv file so that the intention have to be very carefully reviewed here.
Thanks,
Michael
Quoted 9 lines
Daniel
[1] http://git.savannah.gnu.org/gitweb/?p=grub.git;a=commit;h=a4356538d03c5a5350790b6453b523fb9214c2e9
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Adding James, Stefan and Robbie...
Quoted 46 lines · Michael Chang via Grub-devel
Quoted 36 lines · Daniel Kiper
Quoted 35 lines · Michael Chang via Grub-devel
Quoted 21 lines · Daniel Kiper
Quoted 13 lines · Michael Chang via Grub-devel
Quoted 6 lines · Daniel Kiper
Quoted 3 lines · Michael Chang via Grub-devel
This helps to prevent out of memory error when reading large files via disabling tpm device as verifier has to read all content into memory in one chunk to measure the hash and extend to tpm.
How does this patch help when the TPM is present in the system?
If the firmware menu offers option to disable TPM device, then this patch can be useful to get around 'out of memory error' through disabling TPM device from firmware in order to make tpm verifier won't be in the way of reading huge files.
Quoted 6 lines
This is essentially a compromised solution as long as tpm module can be a built-in module in signed image and at the same time user may come across the need to open huge files, for eg, loopback mount in grub for the rescue image. In this case they could be opted in to disable tpm device from firmware to proceed if they run into out of memory or other (slow) reading issues.
Quoted 2 lines
I think I would prefer something similar to this [1] patch. Of course if [1] is not enough...
The tpm verifier attempts to set
GRUB_VERIFY_FLAGS_SINGLE_CHUNKfor all incoming files, which gets loaded into memory in its entirety as an duplicated copy to disk files. The overhead is too huge to some low profile hardwares with smaller memory or when the boot path has to cover very large files, hence the out of memory error.I think it inevitable to use
GRUB_VERIFY_FLAGS_SINGLE_CHUNKas tpm measures and extends file intergrity. But we ought to avoid the overhead when TPM device is not present or disabled by the user.Quoted 8 lines
Quoted 3 lines
The patch [1] seems to deal with the tpm error which prevents a file from being opened, which is orthogonal to the memory allocation issue in the common verifier before tpm doing measurement.
This is what I expected. So, that is why I said "Of course if [1] is not enough..."... :-) Now I think it would be nice if TPM verifier is disabled when the TPM device is broken/disabled/... and/or somebody sets a separate environemnt variable in the GRUB. WDYT?
Quoted 4 lines
I'm not sure if a separate environment a good idea, because it would expose the funtion to disable verifier in a way much readily accessible through one of grub command line interface, grub.cfg and grubenv file so that the intention have to be very carefully reviewed here.
I think it should be safe because even if somebody is doing nasty things with disabling the TPM verifier they can be easily detected or will lead to early boot failures when the TPM is used to store secrets. Of course there is small chance somebody disables the TPM verifier during platform initialization/installation. However, this should be also easily to detect due to, e.g., lack of measurements. Anyway, I would extend the GRUB documentation with a note saying that platform initialization/installation should happen in well controlled environment. Just in case...
Daniel
Quoted 54 lines · Daniel Kiper
Adding James, Stefan and Robbie...
Quoted 46 lines · Michael Chang via Grub-devel
Quoted 36 lines · Daniel Kiper
Quoted 35 lines · Michael Chang via Grub-devel
Quoted 21 lines · Daniel Kiper
Quoted 13 lines · Michael Chang via Grub-devel
Quoted 6 lines · Daniel Kiper
Quoted 3 lines · Michael Chang via Grub-devel
This helps to prevent out of memory error when reading large files via disabling tpm device as verifier has to read all content into memory in one chunk to measure the hash and extend to tpm.
How does this patch help when the TPM is present in the system?
If the firmware menu offers option to disable TPM device, then this patch can be useful to get around 'out of memory error' through disabling TPM device from firmware in order to make tpm verifier won't be in the way of reading huge files.
Quoted 6 lines
This is essentially a compromised solution as long as tpm module can be a built-in module in signed image and at the same time user may come across the need to open huge files, for eg, loopback mount in grub for the rescue image. In this case they could be opted in to disable tpm device from firmware to proceed if they run into out of memory or other (slow) reading issues.
Quoted 2 lines
I think I would prefer something similar to this [1] patch. Of course if [1] is not enough...
The tpm verifier attempts to set
GRUB_VERIFY_FLAGS_SINGLE_CHUNKfor all incoming files, which gets loaded into memory in its entirety as an duplicated copy to disk files. The overhead is too huge to some low profile hardwares with smaller memory or when the boot path has to cover very large files, hence the out of memory error.I think it inevitable to use
GRUB_VERIFY_FLAGS_SINGLE_CHUNKas tpm measures and extends file intergrity. But we ought to avoid the overhead when TPM device is not present or disabled by the user.Quoted 8 lines
Quoted 3 lines
The patch [1] seems to deal with the tpm error which prevents a file from being opened, which is orthogonal to the memory allocation issue in the common verifier before tpm doing measurement.
This is what I expected. So, that is why I said "Of course if [1] is not enough..."... :-) Now I think it would be nice if TPM verifier is disabled when the TPM device is broken/disabled/... and/or somebody sets a separate environemnt variable in the GRUB. WDYT?
Quoted 4 lines
I'm not sure if a separate environment a good idea, because it would expose the funtion to disable verifier in a way much readily accessible through one of grub command line interface, grub.cfg and grubenv file so that the intention have to be very carefully reviewed here.
Quoted 6 lines
I think it should be safe because even if somebody is doing nasty things with disabling the TPM verifier they can be easily detected or will lead to early boot failures when the TPM is used to store secrets. Of course there is small chance somebody disables the TPM verifier during platform initialization/installation. However, this should be also easily to detect due to, e.g., lack of measurements.
IMHO it is hardly be detectable, there's no clear distinction to it is a result of lack of measurement or a compromised system if we know that tpm is active and working ...
Quoted 4 lines
Anyway, I would extend the
GRUB documentation with a note saying that platform initialization/installation should happen in well controlled environment. Just in case...
Yes the initial bootstrapping environemt or process is important, but also there's system update which should happen in a well controlled environment as well.
Thanks,
Michael
Quoted 7 lines
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 62 lines · Michael Chang via Grub-devel
Quoted 54 lines · Daniel Kiper
Adding James, Stefan and Robbie...
Quoted 46 lines · Michael Chang via Grub-devel
Quoted 36 lines · Daniel Kiper
Quoted 35 lines · Michael Chang via Grub-devel
Quoted 21 lines · Daniel Kiper
Quoted 13 lines · Michael Chang via Grub-devel
Quoted 6 lines · Daniel Kiper
Quoted 3 lines · Michael Chang via Grub-devel
This helps to prevent out of memory error when reading large files via disabling tpm device as verifier has to read all content into memory in one chunk to measure the hash and extend to tpm.
How does this patch help when the TPM is present in the system?
If the firmware menu offers option to disable TPM device, then this patch can be useful to get around 'out of memory error' through disabling TPM device from firmware in order to make tpm verifier won't be in the way of reading huge files.
Quoted 6 lines
This is essentially a compromised solution as long as tpm module can be a built-in module in signed image and at the same time user may come across the need to open huge files, for eg, loopback mount in grub for the rescue image. In this case they could be opted in to disable tpm device from firmware to proceed if they run into out of memory or other (slow) reading issues.
Quoted 2 lines
I think I would prefer something similar to this [1] patch. Of course if [1] is not enough...
The tpm verifier attempts to set
GRUB_VERIFY_FLAGS_SINGLE_CHUNKfor all incoming files, which gets loaded into memory in its entirety as an duplicated copy to disk files. The overhead is too huge to some low profile hardwares with smaller memory or when the boot path has to cover very large files, hence the out of memory error.I think it inevitable to use
GRUB_VERIFY_FLAGS_SINGLE_CHUNKas tpm measures and extends file intergrity. But we ought to avoid the overhead when TPM device is not present or disabled by the user.Quoted 8 lines
Quoted 3 lines
The patch [1] seems to deal with the tpm error which prevents a file from being opened, which is orthogonal to the memory allocation issue in the common verifier before tpm doing measurement.
This is what I expected. So, that is why I said "Of course if [1] is not enough..."... :-) Now I think it would be nice if TPM verifier is disabled when the TPM device is broken/disabled/... and/or somebody sets a separate environemnt variable in the GRUB. WDYT?
Quoted 4 lines
I'm not sure if a separate environment a good idea, because it would expose the funtion to disable verifier in a way much readily accessible through one of grub command line interface, grub.cfg and grubenv file so that the intention have to be very carefully reviewed here.
Quoted 6 lines
I think it should be safe because even if somebody is doing nasty things with disabling the TPM verifier they can be easily detected or will lead to early boot failures when the TPM is used to store secrets. Of course there is small chance somebody disables the TPM verifier during platform initialization/installation. However, this should be also easily to detect due to, e.g., lack of measurements.
Quoted 3 lines
IMHO it is hardly be detectable, there's no clear distinction to it is a result of lack of measurement or a compromised system if we know that tpm is active and working ...
Sudden lack of measurements should be a red flag and machine should be treated initially as a compromised. Additionally, how the proposed variable/switch/... in the GRUB differs from the switch in the BIOS setup which you mentioned above? The result of their use will be the same.
Quoted 8 lines
Quoted 4 lines
Anyway, I would extend the
GRUB documentation with a note saying that platform initialization/installation should happen in well controlled environment. Just in case...Yes the initial bootstrapping environemt or process is important, but also there's system update which should happen in a well controlled environment as well.
Yes, and we can document this as well...
Daniel
Quoted 67 lines · Daniel Kiper
Quoted 62 lines · Michael Chang via Grub-devel
Quoted 54 lines · Daniel Kiper
Adding James, Stefan and Robbie...
Quoted 46 lines · Michael Chang via Grub-devel
Quoted 36 lines · Daniel Kiper
Quoted 35 lines · Michael Chang via Grub-devel
Quoted 21 lines · Daniel Kiper
Quoted 13 lines · Michael Chang via Grub-devel
Quoted 6 lines · Daniel Kiper
Quoted 3 lines · Michael Chang via Grub-devel
This helps to prevent out of memory error when reading large files via disabling tpm device as verifier has to read all content into memory in one chunk to measure the hash and extend to tpm.
How does this patch help when the TPM is present in the system?
If the firmware menu offers option to disable TPM device, then this patch can be useful to get around 'out of memory error' through disabling TPM device from firmware in order to make tpm verifier won't be in the way of reading huge files.
Quoted 6 lines
This is essentially a compromised solution as long as tpm module can be a built-in module in signed image and at the same time user may come across the need to open huge files, for eg, loopback mount in grub for the rescue image. In this case they could be opted in to disable tpm device from firmware to proceed if they run into out of memory or other (slow) reading issues.
Quoted 2 lines
I think I would prefer something similar to this [1] patch. Of course if [1] is not enough...
The tpm verifier attempts to set
GRUB_VERIFY_FLAGS_SINGLE_CHUNKfor all incoming files, which gets loaded into memory in its entirety as an duplicated copy to disk files. The overhead is too huge to some low profile hardwares with smaller memory or when the boot path has to cover very large files, hence the out of memory error.I think it inevitable to use
GRUB_VERIFY_FLAGS_SINGLE_CHUNKas tpm measures and extends file intergrity. But we ought to avoid the overhead when TPM device is not present or disabled by the user.Quoted 8 lines
Quoted 3 lines
The patch [1] seems to deal with the tpm error which prevents a file from being opened, which is orthogonal to the memory allocation issue in the common verifier before tpm doing measurement.
This is what I expected. So, that is why I said "Of course if [1] is not enough..."... :-) Now I think it would be nice if TPM verifier is disabled when the TPM device is broken/disabled/... and/or somebody sets a separate environemnt variable in the GRUB. WDYT?
Quoted 4 lines
I'm not sure if a separate environment a good idea, because it would expose the funtion to disable verifier in a way much readily accessible through one of grub command line interface, grub.cfg and grubenv file so that the intention have to be very carefully reviewed here.
Quoted 6 lines
I think it should be safe because even if somebody is doing nasty things with disabling the TPM verifier they can be easily detected or will lead to early boot failures when the TPM is used to store secrets. Of course there is small chance somebody disables the TPM verifier during platform initialization/installation. However, this should be also easily to detect due to, e.g., lack of measurements.
Quoted 3 lines
IMHO it is hardly be detectable, there's no clear distinction to it is a result of lack of measurement or a compromised system if we know that tpm is active and working ...
Quoted 5 lines
Sudden lack of measurements should be a red flag and machine should be treated initially as a compromised. Additionally, how the proposed variable/switch/... in the GRUB differs from the switch in the BIOS setup which you mentioned above? The result of their use will be the same.
The off switch in bios may completely shut down the tpm device, so it won't be usable at all to the user who wants to actively disable it there. On the other hand the swich in grub is in a context where tpm is still in action, the missing measurement could lead to a comprehension of compromised system and it can break root of trust, killing the most idea of using a tpm to attest integrity of a booted system.
So instead of making grub bypass tpm become possible, I think user should always go for bios to disable tpm if running into OOM issue upon executing memory consuming commands like loopback, initrd etc, in particular after grub upgrade to add tpm module in small memory systems.
Thanks,
Michael
Quoted 13 lines
Quoted 9 lines
Quoted 5 lines
Anyway, I would extend the
GRUB documentation with a note saying that platform initialization/installation should happen in well controlled environment. Just in case...Yes the initial bootstrapping environemt or process is important, but also there's system update which should happen in a well controlled environment as well.
Yes, and we can document this as well...
Daniel
Quoted 74 lines · Michael Chang
Quoted 67 lines · Daniel Kiper
Quoted 62 lines · Michael Chang via Grub-devel
Quoted 54 lines · Daniel Kiper
Adding James, Stefan and Robbie...
Quoted 46 lines · Michael Chang via Grub-devel
Quoted 36 lines · Daniel Kiper
Quoted 35 lines · Michael Chang via Grub-devel
Quoted 21 lines · Daniel Kiper
Quoted 13 lines · Michael Chang via Grub-devel
Quoted 6 lines · Daniel Kiper
Quoted 3 lines · Michael Chang via Grub-devel
This helps to prevent out of memory error when reading large files via disabling tpm device as verifier has to read all content into memory in one chunk to measure the hash and extend to tpm.
How does this patch help when the TPM is present in the system?
If the firmware menu offers option to disable TPM device, then this patch can be useful to get around 'out of memory error' through disabling TPM device from firmware in order to make tpm verifier won't be in the way of reading huge files.
Quoted 6 lines
This is essentially a compromised solution as long as tpm module can be a built-in module in signed image and at the same time user may come across the need to open huge files, for eg, loopback mount in grub for the rescue image. In this case they could be opted in to disable tpm device from firmware to proceed if they run into out of memory or other (slow) reading issues.
Quoted 2 lines
I think I would prefer something similar to this [1] patch. Of course if [1] is not enough...
The tpm verifier attempts to set
GRUB_VERIFY_FLAGS_SINGLE_CHUNKfor all incoming files, which gets loaded into memory in its entirety as an duplicated copy to disk files. The overhead is too huge to some low profile hardwares with smaller memory or when the boot path has to cover very large files, hence the out of memory error.I think it inevitable to use
GRUB_VERIFY_FLAGS_SINGLE_CHUNKas tpm measures and extends file intergrity. But we ought to avoid the overhead when TPM device is not present or disabled by the user.Quoted 8 lines
Quoted 3 lines
The patch [1] seems to deal with the tpm error which prevents a file from being opened, which is orthogonal to the memory allocation issue in the common verifier before tpm doing measurement.
This is what I expected. So, that is why I said "Of course if [1] is not enough..."... :-) Now I think it would be nice if TPM verifier is disabled when the TPM device is broken/disabled/... and/or somebody sets a separate environemnt variable in the GRUB. WDYT?
Quoted 4 lines
I'm not sure if a separate environment a good idea, because it would expose the funtion to disable verifier in a way much readily accessible through one of grub command line interface, grub.cfg and grubenv file so that the intention have to be very carefully reviewed here.
Quoted 6 lines
I think it should be safe because even if somebody is doing nasty things with disabling the TPM verifier they can be easily detected or will lead to early boot failures when the TPM is used to store secrets. Of course there is small chance somebody disables the TPM verifier during platform initialization/installation. However, this should be also easily to detect due to, e.g., lack of measurements.
Quoted 3 lines
IMHO it is hardly be detectable, there's no clear distinction to it is a result of lack of measurement or a compromised system if we know that tpm is active and working ...
Quoted 5 lines
Sudden lack of measurements should be a red flag and machine should be treated initially as a compromised. Additionally, how the proposed variable/switch/... in the GRUB differs from the switch in the BIOS setup which you mentioned above? The result of their use will be the same.
Quoted 6 lines
The off switch in bios may completely shut down the tpm device, so it won't be usable at all to the user who wants to actively disable it there. On the other hand the swich in grub is in a context where tpm is still in action, the missing measurement could lead to a comprehension of compromised system and it can break root of trust, killing the most idea of using a tpm to attest integrity of a booted system.
I am still not convinced. Using one or another lead to the same result, lack of measurements. Am I missing something?
Quoted 4 lines
So instead of making grub bypass tpm become possible, I think user should always go for bios to disable tpm if running into OOM issue upon executing memory consuming commands like loopback, initrd etc, in particular after grub upgrade to add tpm module in small memory systems.
Did you try latest GRUB upstream master branch? It has significant changes in mm code which should solve your problems. Or at least in some cases...
Daniel
Quoted 82 lines · Daniel Kiper
Quoted 74 lines · Michael Chang
Quoted 67 lines · Daniel Kiper
Quoted 62 lines · Michael Chang via Grub-devel
Quoted 54 lines · Daniel Kiper
Adding James, Stefan and Robbie...
Quoted 46 lines · Michael Chang via Grub-devel
Quoted 36 lines · Daniel Kiper
Quoted 35 lines · Michael Chang via Grub-devel
Quoted 21 lines · Daniel Kiper
Quoted 13 lines · Michael Chang via Grub-devel
Quoted 6 lines · Daniel Kiper
Quoted 3 lines · Michael Chang via Grub-devel
This helps to prevent out of memory error when reading large files via disabling tpm device as verifier has to read all content into memory in one chunk to measure the hash and extend to tpm.
How does this patch help when the TPM is present in the system?
If the firmware menu offers option to disable TPM device, then this patch can be useful to get around 'out of memory error' through disabling TPM device from firmware in order to make tpm verifier won't be in the way of reading huge files.
Quoted 6 lines
This is essentially a compromised solution as long as tpm module can be a built-in module in signed image and at the same time user may come across the need to open huge files, for eg, loopback mount in grub for the rescue image. In this case they could be opted in to disable tpm device from firmware to proceed if they run into out of memory or other (slow) reading issues.
Quoted 2 lines
I think I would prefer something similar to this [1] patch. Of course if [1] is not enough...
The tpm verifier attempts to set
GRUB_VERIFY_FLAGS_SINGLE_CHUNKfor all incoming files, which gets loaded into memory in its entirety as an duplicated copy to disk files. The overhead is too huge to some low profile hardwares with smaller memory or when the boot path has to cover very large files, hence the out of memory error.I think it inevitable to use
GRUB_VERIFY_FLAGS_SINGLE_CHUNKas tpm measures and extends file intergrity. But we ought to avoid the overhead when TPM device is not present or disabled by the user.Quoted 8 lines
Quoted 3 lines
The patch [1] seems to deal with the tpm error which prevents a file from being opened, which is orthogonal to the memory allocation issue in the common verifier before tpm doing measurement.
This is what I expected. So, that is why I said "Of course if [1] is not enough..."... :-) Now I think it would be nice if TPM verifier is disabled when the TPM device is broken/disabled/... and/or somebody sets a separate environemnt variable in the GRUB. WDYT?
Quoted 4 lines
I'm not sure if a separate environment a good idea, because it would expose the funtion to disable verifier in a way much readily accessible through one of grub command line interface, grub.cfg and grubenv file so that the intention have to be very carefully reviewed here.
Quoted 6 lines
I think it should be safe because even if somebody is doing nasty things with disabling the TPM verifier they can be easily detected or will lead to early boot failures when the TPM is used to store secrets. Of course there is small chance somebody disables the TPM verifier during platform initialization/installation. However, this should be also easily to detect due to, e.g., lack of measurements.
Quoted 3 lines
IMHO it is hardly be detectable, there's no clear distinction to it is a result of lack of measurement or a compromised system if we know that tpm is active and working ...
Quoted 5 lines
Sudden lack of measurements should be a red flag and machine should be treated initially as a compromised. Additionally, how the proposed variable/switch/... in the GRUB differs from the switch in the BIOS setup which you mentioned above? The result of their use will be the same.
Quoted 6 lines
The off switch in bios may completely shut down the tpm device, so it won't be usable at all to the user who wants to actively disable it there. On the other hand the swich in grub is in a context where tpm is still in action, the missing measurement could lead to a comprehension of compromised system and it can break root of trust, killing the most idea of using a tpm to attest integrity of a booted system.
Quoted 2 lines
I am still not convinced. Using one or another lead to the same result, lack of measurements. Am I missing something?
Unless it is necessary for something to really work out, "convenience is the enemy of security" could be my (lame) excuse that I didn't want to have that in the beginning if firmware already had offered the same functionality to the user.
It can be added later any time someone has found it beneficial.
Quoted 8 lines
Quoted 5 lines
So instead of making grub bypass tpm become possible, I think user should always go for bios to disable tpm if running into OOM issue upon executing memory consuming commands like loopback, initrd etc, in particular after grub upgrade to add tpm module in small memory systems.
Did you try latest GRUB upstream master branch? It has significant changes in mm code which should solve your problems. Or at least in some cases...
Yes I did. And they are working satisfactorily well in that many out of memory related problems were solved. However, depending on the available memory and usage of grub, chances are still there that the memory can be completely exhasuted or to a limit where too little left to the booted kernel that it cannot relocate itself.
As many distributions start to making tpm as builtin to signed grub image, this can help in the worse case that people can opt in to disable tpm from the firwmare settings and continue as if they were before.
Thanks,
Michael
Quoted 2 lines
Daniel
Quoted 3 lines · Michael Chang via Grub-devel
This helps to prevent out of memory error when reading large files via disabling tpm device as verifier has to read all content into memory in one chunk to measure the hash and extend to tpm.
For ibmvtpm driver support this change here would be need. Can you merge it into your patch once the ibmvtpm driver is in the repo?
grub-core/commands/ieee1275/ibmvtpm.c +10 -10
@@ -135,16 +135,6 @@ grub_err_t grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr, const char *description) { -/* -* Call tpm_init() 'late' rather than from GRUB_MOD_INIT() so that device nodes -* can be found. -*/ - grub_err_t err = tpm_init (); - -/* Absence of a TPM isn't a failure. */ -if (err !=GRUB_ERR_NONE ) -return GRUB_ERR_NONE ; - grub_dprintf ("tpm", "log_event, pcr = %d, size = 0x%" PRIxGRUB_SIZE ", %s\n", pcr, size, description);
@@ -153,3 +143,13 @@ grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr,return GRUB_ERR_NONE ; } + +int +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 ; +}
grub-core/commands/tpm.c struct grub_file_verifier grub_tpm_verifier = { · line 90
Quoted 10 lines
grub-core/commands/tpm.c +2
-0@@ -86,10 +86,14 @@ struct grub_file_verifier grub_tpm_verifier = {GRUB_MOD_INIT (tpm) { +if (!grub_tpm_present ()) +return ;
Even though this now calls grub_tpm_present() from GRUB_MOD_INIT() and I have this comment in the code above, it does seem to call it late enough in the initialization sequence so that whatever discovered 'device nodes' before your GRUB_MOD_INIT() is called, enables the ibmvtpm driver to see the device nodes.
Per my tests powerpc grub now measures and logs for PCR 8 and 9 correctly and also extends PCRs 8 & 9. I hope that nothing will change this initialization order because there seems to be little control over it.
Stefan
Quoted 19 lines
grub-core/commands/tpm.c +2
-0grub_verifier_register (&grub_tpm_verifier); }GRUB_MOD_FINI (tpm) { +if (!grub_tpm_present ()) +return ;grub_verifier_unregister (&grub_tpm_verifier); }include/grub/tpm.h +1
-0@@ -36,4 +36,5 @@grub_err_t grub_tpm_measure (unsigned char *buf,grub_size_t size,grub_uint8_t pcr,const char *description); +int grub_tpm_present (void );#endif
Quoted 48 lines · Stefan Berger
Quoted 3 lines · Michael Chang via Grub-devel
This helps to prevent out of memory error when reading large files via disabling tpm device as verifier has to read all content into memory in one chunk to measure the hash and extend to tpm.
For ibmvtpm driver support this change here would be need. Can you merge it into your patch once the ibmvtpm driver is in the repo?
grub-core/commands/ieee1275/ibmvtpm.c +10
-10@@ -135,16 +135,6 @@ grub_err_t grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr, const char *description) { -/* -* Call tpm_init() 'late' rather than from GRUB_MOD_INIT() so that device nodes -* can be found. -*/ - grub_err_t err = tpm_init (); - -/* Absence of a TPM isn't a failure. */ -if (err !=GRUB_ERR_NONE ) -return GRUB_ERR_NONE ; - grub_dprintf ("tpm", "log_event, pcr = %d, size = 0x%" PRIxGRUB_SIZE ", %s\n", pcr, size, description);@@ -153,3 +143,13 @@ grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr,return GRUB_ERR_NONE ; } + +int +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 ; +}Signed-off-by Stefan Berger <[email protected]>
Quoted 13 lines
grub-core/commands/tpm.c struct grub_file_verifier grub_tpm_verifier = { · line 89
Quoted 9 lines
grub-core/commands/tpm.c +2
-0@@ -86,10 +86,14 @@ struct grub_file_verifier grub_tpm_verifier = {GRUB_MOD_INIT (tpm) { +if (!grub_tpm_present ()) +return ;Even though this now calls
grub_tpm_present()fromGRUB_MOD_INIT()and I have this comment in the code above, it does seem to call it late enough in the initialization sequence so that whatever discovered 'device nodes' before yourGRUB_MOD_INIT()is called, enables the ibmvtpm driver to see the device nodes.
Thanks to the clarification. I think it is worth to keep this comment in the patched hunk so the reader won't get confused by the comment followed in grub_tpm_present.
Quoted 3 lines
Per my tests powerpc grub now measures and logs for PCR 8 and 9 correctly and also extends PCRs 8 & 9. I hope that nothing will change this initialization order because there seems to be little control over it.
I will merge you change and submit a new version.
Thanks.
Michael
Quoted 20 lines
Stefan
Quoted 17 lines
grub-core/commands/tpm.c +2
-0grub_verifier_register (&grub_tpm_verifier); }GRUB_MOD_FINI (tpm) { +if (!grub_tpm_present ()) +return ;grub_verifier_unregister (&grub_tpm_verifier); }include/grub/tpm.h +1
-0@@ -36,4 +36,5 @@grub_err_t grub_tpm_measure (unsigned char *buf,grub_size_t size,grub_uint8_t pcr,const char *description); +int grub_tpm_present (void );#endif