All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rasmus Villemoes <ravi@prevas.dk>
To: u-boot@lists.u-boot-project.org
Cc: Igor Opaniuk <igor.opaniuk@gmail.com>,
	Mattijs Korpershoek <mkorpershoek@kernel.org>,
	Tom Rini <trini@konsulko.com>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Jens Wiklander <jens.wiklander@linaro.org>,
	Rasmus Villemoes <ravi@prevas.dk>
Subject: [PATCH 3/3] avb_verify: read_persistent_value: honour contract regarding too small buffer
Date: Fri, 28 Aug 2026 12:50:05 +0200	[thread overview]
Message-ID: <20260828105005.200338-4-ravi@prevas.dk> (raw)
In-Reply-To: <20260828105005.200338-1-ravi@prevas.dk>

The avb_ops.h header file, which has been imported from the upstream
libavb, says:

   /* Reads a persistent value corresponding to the given |name|. The value is
    * returned in |out_buffer| which must point to |buffer_size| bytes. On
    * success |out_num_bytes_read| contains the number of bytes read into
    * |out_buffer|. If AVB_IO_RESULT_ERROR_INSUFFICIENT_SPACE is returned,
    * |out_num_bytes_read| contains the number of bytes that would have been read
    * which can be used to allocate a buffer.

The invoke_func() wrapper does translate a TEE_ERROR_STORAGE_NO_SPACE
return to AVB_IO_RESULT_ERROR_INSUFFICIENT_SPACE. However, this
implementation of the read_persistent_value method currently never
updates *out_num_bytes_read in case of an error.

Also note that currently, at least the upstream optee-os
implementation of TA_AVB_CMD_READ_PERSIST_VALUE never returns
TEE_ERROR_STORAGE_NO_SPACE, but instead silently returns a truncated
value, with no way for the caller to know that happened. A fix has
been proposed (https://github.com/OP-TEE/optee_os/pull/7959).

Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
---
 common/avb_verify.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/common/avb_verify.c b/common/avb_verify.c
index 76c523fd0ba..af166e7dfba 100644
--- a/common/avb_verify.c
+++ b/common/avb_verify.c
@@ -963,8 +963,11 @@ static AvbIOResult read_persistent_value(AvbOps *ops,
 
 	rc = invoke_func(ops->user_data, TA_AVB_CMD_READ_PERSIST_VALUE,
 			 2, param);
-	if (rc)
+	if (rc) {
+		if (rc == AVB_IO_RESULT_ERROR_INSUFFICIENT_SPACE)
+			*out_num_bytes_read = param[1].u.memref.size;
 		goto out;
+	}
 
 	if (param[1].u.memref.size > buffer_size) {
 		rc = AVB_IO_RESULT_ERROR_NO_SUCH_VALUE;
-- 
2.55.0


  parent reply	other threads:[~2026-08-28 10:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28 10:50 [PATCH 0/3] avb: start handling too small buffer for reading persistent values Rasmus Villemoes
2026-08-28 10:50 ` [PATCH 1/3] cmd: optee_rpmb: sanitize TEE_ERROR -> E* translations Rasmus Villemoes
2026-09-02 12:45   ` Mattijs Korpershoek
2026-09-02 12:51     ` Rasmus Villemoes
2026-08-28 10:50 ` [PATCH 2/3] cmd: optee_rpmb: try to allocate large enough buffer when reading persistent value Rasmus Villemoes
2026-09-02 12:55   ` Mattijs Korpershoek
2026-08-28 10:50 ` Rasmus Villemoes [this message]
2026-09-02 13:03   ` [PATCH 3/3] avb_verify: read_persistent_value: honour contract regarding too small buffer Mattijs Korpershoek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260828105005.200338-4-ravi@prevas.dk \
    --to=ravi@prevas.dk \
    --cc=igor.opaniuk@gmail.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jens.wiklander@linaro.org \
    --cc=mkorpershoek@kernel.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.