Re: [PATCH 2/2] efi+tpm: don't traverse an event log with no events
On Mon, 26 Aug 2019 at 18:30, Peter Jones wrote: > > When there are no entries to put into the final event log, some machines > will return the template they would have populated anyway. In this case > the nr_events field is 0, but the rest of the log is just garbage. > > This patch stops us from trying to iterate the table with > __calc_tpm2_event_size() when the number of events in the table is 0. > > Signed-off-by: Peter Jones > Tested-by: Lyude Paul > --- > drivers/firmware/efi/tpm.c | 14 +- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c > index 1d3f5ca3eaa..be51ed17c6e 100644 > --- a/drivers/firmware/efi/tpm.c > +++ b/drivers/firmware/efi/tpm.c > @@ -75,11 +75,15 @@ int __init efi_tpm_eventlog_init(void) > goto out; > } > > - tbl_size = tpm2_calc_event_log_size((void *)efi.tpm_final_log > - + sizeof(final_tbl->version) > - + sizeof(final_tbl->nr_events), > - final_tbl->nr_events, > - log_tbl->log); > + 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); Please put a newline here With that fixed, Acked-by: Ard Biesheuvel > + tbl_size = tpm2_calc_event_log_size(events, > + final_tbl->nr_events, > + log_tbl->log); > + } > memblock_reserve((unsigned long)final_tbl, > tbl_size + sizeof(*final_tbl)); > early_memunmap(final_tbl, sizeof(*final_tbl)); > -- > 2.23.0.rc2 >
Re: [PATCH 2/2] efi+tpm: don't traverse an event log with no events
On Mon, Aug 26, 2019 at 9:30 AM Jarkko Sakkinen wrote: > > On Mon, Aug 26, 2019 at 11:30:28AM -0400, Peter Jones wrote: > > When there are no entries to put into the final event log, some machines > > will return the template they would have populated anyway. In this case > > the nr_events field is 0, but the rest of the log is just garbage. > > > > This patch stops us from trying to iterate the table with > > __calc_tpm2_event_size() when the number of events in the table is 0. > > > > Signed-off-by: Peter Jones > > Tested-by: Lyude Paul > > --- > > drivers/firmware/efi/tpm.c | 14 +- > > 1 file changed, 9 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c > > index 1d3f5ca3eaa..be51ed17c6e 100644 > > --- a/drivers/firmware/efi/tpm.c > > +++ b/drivers/firmware/efi/tpm.c > > @@ -75,11 +75,15 @@ int __init efi_tpm_eventlog_init(void) > > goto out; > > } > > > > - tbl_size = tpm2_calc_event_log_size((void *)efi.tpm_final_log > > - + sizeof(final_tbl->version) > > - + sizeof(final_tbl->nr_events), > > - final_tbl->nr_events, > > - log_tbl->log); > > + 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); > > + } > > Reviewed-by: Jarkko Sakkinen Acked-by: Matthew Garrett
Re: [PATCH 2/2] efi+tpm: don't traverse an event log with no events
On Mon, Aug 26, 2019 at 11:30:28AM -0400, Peter Jones wrote: > When there are no entries to put into the final event log, some machines > will return the template they would have populated anyway. In this case > the nr_events field is 0, but the rest of the log is just garbage. > > This patch stops us from trying to iterate the table with > __calc_tpm2_event_size() when the number of events in the table is 0. > > Signed-off-by: Peter Jones > Tested-by: Lyude Paul > --- > drivers/firmware/efi/tpm.c | 14 +- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c > index 1d3f5ca3eaa..be51ed17c6e 100644 > --- a/drivers/firmware/efi/tpm.c > +++ b/drivers/firmware/efi/tpm.c > @@ -75,11 +75,15 @@ int __init efi_tpm_eventlog_init(void) > goto out; > } > > - tbl_size = tpm2_calc_event_log_size((void *)efi.tpm_final_log > - + sizeof(final_tbl->version) > - + sizeof(final_tbl->nr_events), > - final_tbl->nr_events, > - log_tbl->log); > + 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); > + } Reviewed-by: Jarkko Sakkinen /Jarkko
[PATCH 2/2] efi+tpm: don't traverse an event log with no events
When there are no entries to put into the final event log, some machines will return the template they would have populated anyway. In this case the nr_events field is 0, but the rest of the log is just garbage. This patch stops us from trying to iterate the table with __calc_tpm2_event_size() when the number of events in the table is 0. Signed-off-by: Peter Jones Tested-by: Lyude Paul --- drivers/firmware/efi/tpm.c | 14 +- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c index 1d3f5ca3eaa..be51ed17c6e 100644 --- a/drivers/firmware/efi/tpm.c +++ b/drivers/firmware/efi/tpm.c @@ -75,11 +75,15 @@ int __init efi_tpm_eventlog_init(void) goto out; } - tbl_size = tpm2_calc_event_log_size((void *)efi.tpm_final_log - + sizeof(final_tbl->version) - + sizeof(final_tbl->nr_events), - final_tbl->nr_events, - log_tbl->log); + 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); + } memblock_reserve((unsigned long)final_tbl, tbl_size + sizeof(*final_tbl)); early_memunmap(final_tbl, sizeof(*final_tbl)); -- 2.23.0.rc2