diff mbox series

[v2,1/8] tpm: fix the return code, if the eventlog buffer is full

Message ID 20240623114838.14639-2-ilias.apalodimas@linaro.org
State Accepted
Commit 27d496627ec4b72de33c7c4dd622586217e8c051
Headers show
Series The great TCG deduplication saga | expand

Commit Message

Ilias Apalodimas June 23, 2024, 11:48 a.m. UTC
We currently return 'No space left on device' if the eventlong buffer
we allocated is not enough. On a similar check later on that function
during the call to tcg2_log_init() we return 'No buffer space
available'. So switch both error codes to -ENOBUFS since we are always
checking a buffer and not a device.

Fixes: commit 97707f12fdab ("tpm: Support boot measurements")
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
 lib/tpm-v2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Glass June 23, 2024, 9:52 p.m. UTC | #1
Hi Ilias,

On Sun, 23 Jun 2024 at 05:48, Ilias Apalodimas
<ilias.apalodimas@linaro.org> wrote:
>
> We currently return 'No space left on device' if the eventlong buffer
> we allocated is not enough. On a similar check later on that function
> during the call to tcg2_log_init() we return 'No buffer space
> available'. So switch both error codes to -ENOBUFS since we are always
> checking a buffer and not a device.
>
> Fixes: commit 97707f12fdab ("tpm: Support boot measurements")
> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
>  lib/tpm-v2.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

For better or worse, we mostly use -ENOSPC for this sort of thing. But
this will at least make the TPM error stand out.

>
> diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
> index a67daed2f3c1..91526af33acb 100644
> --- a/lib/tpm-v2.c
> +++ b/lib/tpm-v2.c
> @@ -554,7 +554,7 @@ int tcg2_log_prepare_buffer(struct udevice *dev, struct tcg2_event_log *elog,
>                 if (elog->log_size) {
>                         if (log.found) {
>                                 if (elog->log_size < log.log_position)
> -                                       return -ENOSPC;
> +                                       return -ENOBUFS;
>
>                                 /*
>                                  * Copy the discovered log into the user buffer
> --
> 2.45.2
>

Regards,
Simon
Ilias Apalodimas June 24, 2024, 4:33 a.m. UTC | #2
Hi Simon,

On Mon, 24 Jun 2024 at 00:52, Simon Glass <sjg@chromium.org> wrote:
>
> Hi Ilias,
>
> On Sun, 23 Jun 2024 at 05:48, Ilias Apalodimas
> <ilias.apalodimas@linaro.org> wrote:
> >
> > We currently return 'No space left on device' if the eventlong buffer
> > we allocated is not enough. On a similar check later on that function
> > during the call to tcg2_log_init() we return 'No buffer space
> > available'. So switch both error codes to -ENOBUFS since we are always
> > checking a buffer and not a device.
> >
> > Fixes: commit 97707f12fdab ("tpm: Support boot measurements")
> > Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> > Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> > ---
> >  lib/tpm-v2.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Thanks

>
> For better or worse, we mostly use -ENOSPC for this sort of thing. But
> this will at least make the TPM error stand out.

The TCG spec is an EFI one. Since we moved that code to u-boots core
we had to convert the return values from efi to int etc. We need
mapping to be as precise as possible.
The reason I switched this to ENOBUFS is because it seemed more
appropriate. I just wanted that function to be coherent on the return
code, I can switch both errors to ENOSPC just as easily.

/Ilias
>
> >
> > diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
> > index a67daed2f3c1..91526af33acb 100644
> > --- a/lib/tpm-v2.c
> > +++ b/lib/tpm-v2.c
> > @@ -554,7 +554,7 @@ int tcg2_log_prepare_buffer(struct udevice *dev, struct tcg2_event_log *elog,
> >                 if (elog->log_size) {
> >                         if (log.found) {
> >                                 if (elog->log_size < log.log_position)
> > -                                       return -ENOSPC;
> > +                                       return -ENOBUFS;
> >
> >                                 /*
> >                                  * Copy the discovered log into the user buffer
> > --
> > 2.45.2
> >
>
> Regards,
> Simon
diff mbox series

Patch

diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index a67daed2f3c1..91526af33acb 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -554,7 +554,7 @@  int tcg2_log_prepare_buffer(struct udevice *dev, struct tcg2_event_log *elog,
 		if (elog->log_size) {
 			if (log.found) {
 				if (elog->log_size < log.log_position)
-					return -ENOSPC;
+					return -ENOBUFS;
 
 				/*
 				 * Copy the discovered log into the user buffer