Linux EFI development
 help / color / mirror / Atom feed
* [PATCH 1/2] tpm: fix signed/unsigned bug when checking event logs
@ 2024-08-30 13:23 Gregory Price
  2024-08-30 13:23 ` [PATCH 2/2] tpm: do not ignore memblock_reserve return value Gregory Price
  0 siblings, 1 reply; 4+ messages in thread
From: Gregory Price @ 2024-08-30 13:23 UTC (permalink / raw)
  To: linux-efi; +Cc: linux-kernel, ardb

A prior bugfix that fixes a signed/unsigned error causes
another signed unsigned error.

A situation where log_tbl->size is invalid can cause the
size passed to memblock_reserve to become negative.

log_size from the main event log is an unsigned int, and
the code reduces to the following

u64 value = (int)unsigned_value;

This results in sign extension, and the value sent to
memblock_reserve becomes effectively negative.

Fixes: be59d57f9806 ("efi/tpm: Fix sanity check of unsigned tbl_size being less than zero")
Signed-off-by: Gregory Price <gourry@gourry.net>
---
 drivers/firmware/efi/tpm.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c
index e8d69bd548f3..9c3613e6af15 100644
--- a/drivers/firmware/efi/tpm.c
+++ b/drivers/firmware/efi/tpm.c
@@ -40,7 +40,8 @@ int __init efi_tpm_eventlog_init(void)
 {
 	struct linux_efi_tpm_eventlog *log_tbl;
 	struct efi_tcg2_final_events_table *final_tbl;
-	int tbl_size;
+	unsigned int tbl_size;
+	int final_tbl_size;
 	int ret = 0;
 
 	if (efi.tpm_log == EFI_INVALID_TABLE_ADDR) {
@@ -80,26 +81,26 @@ int __init efi_tpm_eventlog_init(void)
 		goto out;
 	}
 
-	tbl_size = 0;
+	final_tbl_size = 0;
 	if (final_tbl->nr_events != 0) {
 		void *events = (void *)efi.tpm_final_log
 				+ sizeof(final_tbl->version)
 				+ sizeof(final_tbl->nr_events);
 
-		tbl_size = tpm2_calc_event_log_size(events,
-						    final_tbl->nr_events,
-						    log_tbl->log);
+		final_tbl_size = tpm2_calc_event_log_size(events,
+							  final_tbl->nr_events,
+							  log_tbl->log);
 	}
 
-	if (tbl_size < 0) {
+	if (final_tbl_size < 0) {
 		pr_err(FW_BUG "Failed to parse event in TPM Final Events Log\n");
 		ret = -EINVAL;
 		goto out_calc;
 	}
 
 	memblock_reserve(efi.tpm_final_log,
-			 tbl_size + sizeof(*final_tbl));
-	efi_tpm_final_log_size = tbl_size;
+			 final_tbl_size + sizeof(*final_tbl));
+	efi_tpm_final_log_size = final_tbl_size;
 
 out_calc:
 	early_memunmap(final_tbl, sizeof(*final_tbl));
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] tpm: do not ignore memblock_reserve return value
  2024-08-30 13:23 [PATCH 1/2] tpm: fix signed/unsigned bug when checking event logs Gregory Price
@ 2024-08-30 13:23 ` Gregory Price
  2024-08-30 21:33   ` Usama Arif
  0 siblings, 1 reply; 4+ messages in thread
From: Gregory Price @ 2024-08-30 13:23 UTC (permalink / raw)
  To: linux-efi; +Cc: linux-kernel, ardb

tpm code currently ignores a relevant failure case silently.
Add an error to make this failure non-silent.

Signed-off-by: Gregory Price <gourry@gourry.net>
---
 drivers/firmware/efi/tpm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c
index 9c3613e6af15..b6939a6d44d9 100644
--- a/drivers/firmware/efi/tpm.c
+++ b/drivers/firmware/efi/tpm.c
@@ -61,7 +61,11 @@ int __init efi_tpm_eventlog_init(void)
 	}
 
 	tbl_size = sizeof(*log_tbl) + log_tbl->size;
-	memblock_reserve(efi.tpm_log, tbl_size);
+	if (memblock_reserve(efi.tpm_log, tbl_size)) {
+		pr_err("TPM Event Log memblock reserve fails 0x%lx - %x\n",
+		       efi.tpm_log, tbl_size);
+		goto out;
+	}
 
 	if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR) {
 		pr_info("TPM Final Events table not present\n");
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] tpm: do not ignore memblock_reserve return value
  2024-08-30 13:23 ` [PATCH 2/2] tpm: do not ignore memblock_reserve return value Gregory Price
@ 2024-08-30 21:33   ` Usama Arif
  2024-08-30 21:44     ` Gregory Price
  0 siblings, 1 reply; 4+ messages in thread
From: Usama Arif @ 2024-08-30 21:33 UTC (permalink / raw)
  To: Gregory Price, linux-efi; +Cc: linux-kernel, ardb



On 30/08/2024 09:23, Gregory Price wrote:
> tpm code currently ignores a relevant failure case silently.
> Add an error to make this failure non-silent.
> 
> Signed-off-by: Gregory Price <gourry@gourry.net>
> ---
>  drivers/firmware/efi/tpm.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c
> index 9c3613e6af15..b6939a6d44d9 100644
> --- a/drivers/firmware/efi/tpm.c
> +++ b/drivers/firmware/efi/tpm.c
> @@ -61,7 +61,11 @@ int __init efi_tpm_eventlog_init(void)
>  	}
>  
>  	tbl_size = sizeof(*log_tbl) + log_tbl->size;
> -	memblock_reserve(efi.tpm_log, tbl_size);
> +	if (memblock_reserve(efi.tpm_log, tbl_size)) {
> +		pr_err("TPM Event Log memblock reserve fails 0x%lx - %x\n",
> +		       efi.tpm_log, tbl_size);
> +		goto out;
> +	}
>  
>  	if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR) {
>  		pr_info("TPM Final Events table not present\n");

This was not a proper fix for the issue, sent a bit quickly!

I have sent it here https://lore.kernel.org/all/20240830212852.2794145-1-usamaarif642@gmail.com/


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] tpm: do not ignore memblock_reserve return value
  2024-08-30 21:33   ` Usama Arif
@ 2024-08-30 21:44     ` Gregory Price
  0 siblings, 0 replies; 4+ messages in thread
From: Gregory Price @ 2024-08-30 21:44 UTC (permalink / raw)
  To: Usama Arif; +Cc: linux-efi, linux-kernel, ardb

On Fri, Aug 30, 2024 at 10:33:22PM +0100, Usama Arif wrote:
> 
> 
> On 30/08/2024 09:23, Gregory Price wrote:
> > tpm code currently ignores a relevant failure case silently.
> > Add an error to make this failure non-silent.
> > 
> > Signed-off-by: Gregory Price <gourry@gourry.net>
> > ---
> >  drivers/firmware/efi/tpm.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c
> > index 9c3613e6af15..b6939a6d44d9 100644
> > --- a/drivers/firmware/efi/tpm.c
> > +++ b/drivers/firmware/efi/tpm.c
> > @@ -61,7 +61,11 @@ int __init efi_tpm_eventlog_init(void)
> >  	}
> >  
> >  	tbl_size = sizeof(*log_tbl) + log_tbl->size;
> > -	memblock_reserve(efi.tpm_log, tbl_size);
> > +	if (memblock_reserve(efi.tpm_log, tbl_size)) {
> > +		pr_err("TPM Event Log memblock reserve fails 0x%lx - %x\n",
> > +		       efi.tpm_log, tbl_size);
> > +		goto out;
> > +	}
> >  
> >  	if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR) {
> >  		pr_info("TPM Final Events table not present\n");
> 
> This was not a proper fix for the issue, sent a bit quickly!
> 
> I have sent it here https://lore.kernel.org/all/20240830212852.2794145-1-usamaarif642@gmail.com/
> 

This change addresses a separately, discrete issue and the two
changes should be different patches (this is aside from the change
you posted being incorrect for v1_2).

~Gregory

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-30 21:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-30 13:23 [PATCH 1/2] tpm: fix signed/unsigned bug when checking event logs Gregory Price
2024-08-30 13:23 ` [PATCH 2/2] tpm: do not ignore memblock_reserve return value Gregory Price
2024-08-30 21:33   ` Usama Arif
2024-08-30 21:44     ` Gregory Price

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox