All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Ilias Apalodimas <apalos@gmail.com>,
	Ying-Chun Liu <paul.liu@linaro.org>,
	Jens Wiklander <jens.wiklander@linaro.org>,
	Alexander Graf <agraf@csgraf.de>,
	U-Boot Mailing List <u-boot@lists.denx.de>
Subject: Re: [PATCH v2] efi_loader: Don't limit the StMM buffer size explicitly
Date: Sat, 25 Dec 2021 21:35:11 +0200	[thread overview]
Message-ID: <Ycdyb1zfIlvBuKXb@hades> (raw)
In-Reply-To: <93e7b044-163f-4828-abd9-a9631ecc2ae8@gmx.de>

On Sat, Dec 25, 2021 at 05:13:23PM +0100, Heinrich Schuchardt wrote:
> On 12/25/21 16:04, Ilias Apalodimas wrote:
> > 
> > 
> > On Sat, 25 Dec 2021, 16:28 Heinrich Schuchardt, <xypron.glpk@gmx.de
> > <mailto:xypron.glpk@gmx.de>> wrote:
> > 
> > 
> > 
> >     Am 25. Dezember 2021 12:16:29 MEZ schrieb Ilias Apalodimas
> >     <ilias.apalodimas@linaro.org <mailto:ilias.apalodimas@linaro.org>>:
> >      >> >
> >      >[...]
> >      >> >    rc = tee_invoke_func(conn.tee, &arg, 2, param);
> >      >> >    tee_shm_free(shm);
> >      >> > +  /*
> >      >> > +   * Although the max payload is configurable on StMM, we
> >     only share
> >      >> > +   * four pages from OP-TEE for the non-secure buffer used to
> >     communicate
> >      >> > +   * with StMM. OP-TEE will reject anything bigger than that
> >     and will
> >      >> > +   * return.  So le'ts at least warn users
> >      >> > +   */
> 
> The comment mentioning four pages does not make too much sense to me as
> both OP-TEE as well as U-Boot can be configured to other sizes.
> 
> >      >> >    tee_close_session(conn.tee, conn.session);
> >      >> > -  if (rc || arg.ret != TEE_SUCCESS)
> >      >> > +  if (rc || arg.ret != TEE_SUCCESS) {
> >      >>
> >      >> tee_close_session(): Will arg.ret be valid if rc != 0?
> >      >
> >      >Depends when tee_invoke_func() failed.  But why do we care?
> > 
> >     Should we write a message if rc !=0 && arg.ret == TEE_ERROR_EXCESS_DATA?
> > 
> > 
> > I don't think its needed. OPTEE will set that only if RC == 0
> > 
> > Cheers
> > Ilias
> > 
> > 
> >      >The connection needs to close regardless and we then have to
> >     reason with
> >      >the error.
> >      >
> >      >Regards
> >      >/Ilias
> 
> So how about:
> 
> @@ -114,7 +113,11 @@ static efi_status_t optee_mm_communicate(void
> *comm_buf, ulong dsize)
>         rc = tee_invoke_func(conn.tee, &arg, 2, param);
>         tee_shm_free(shm);
>         tee_close_session(conn.tee, conn.session);
> -       if (rc || arg.ret != TEE_SUCCESS)
> +       if (rc)
> +               return EFI_DEVICE_ERROR;
> +       if (arg.ret == TEE_ERROR_EXCESS_DATA)
> +               log_err("Variable payload too large\n");
> +       if (arg.ret != TEE_SUCCESS)
>                 return EFI_DEVICE_ERROR;

We just move the error reporting out of the inner if.
i.e 
if (arg.ret == TEE_ERROR_EXCESS_DATA)
	log_err("Variable payload too large\n");

if (rc || arg.ret != TEE_SUCCESS)
	return EFI_DEVICE_ERROR;

Which looks better to me

Regards
/Ilias
> 
> Best regards
> 
> Heinrich
> 
> >      >>
> >      >> > +          if (arg.ret == TEE_ERROR_EXCESS_DATA)
> >      >> > +                  log_err("Variable payload too large\n");
> >      >> >            return EFI_DEVICE_ERROR;
> >      >> > +  }
> >      >> >
> >      >> >    switch (param[1].u.value.a) {
> >      >> >    case ARM_SVC_SPM_RET_SUCCESS:
> >      >> > @@ -255,15 +263,6 @@ efi_status_t EFIAPI
> >     get_max_payload(efi_uintn_t *size)
> >      >> >            goto out;
> >      >> >    }
> >      >> >    *size = var_payload->size;
> >      >> > -  /*
> >      >> > -   * Although the max payload is configurable on StMM, we
> >     only share a
> >      >> > -   * single page from OP-TEE for the non-secure buffer used
> >     to communicate
> >      >> > -   * with StMM. Since OP-TEE will reject to map anything
> >     bigger than that,
> >      >> > -   * make sure we are in bounds.
> >      >> > -   */
> >      >> > -  if (*size > OPTEE_PAGE_SIZE)
> >      >> > -          *size = OPTEE_PAGE_SIZE - MM_COMMUNICATE_HEADER_SIZE  -
> >      >> > -                  MM_VARIABLE_COMMUNICATE_SIZE;
> >      >> >    /*
> >      >> >     * There seems to be a bug in EDK2 miscalculating the
> >     boundaries and
> >      >> >     * size checks, so deduct 2 more bytes to fulfill this
> >     requirement. Fix
> >      >>
> > 
> 

  reply	other threads:[~2021-12-25 19:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-24  8:08 [PATCH v2] efi_loader: Don't limit the StMM buffer size explicitly Ilias Apalodimas
2021-12-25 10:03 ` Heinrich Schuchardt
2021-12-25 11:16   ` Ilias Apalodimas
2021-12-25 14:28     ` Heinrich Schuchardt
2021-12-25 15:04       ` Ilias Apalodimas
2021-12-25 16:13         ` Heinrich Schuchardt
2021-12-25 19:35           ` Ilias Apalodimas [this message]
2021-12-25 19:39           ` Ilias Apalodimas
2021-12-27  8:26             ` Jens Wiklander
2021-12-27  8:29               ` Ilias Apalodimas
2021-12-27  8:35                 ` Heinrich Schuchardt

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=Ycdyb1zfIlvBuKXb@hades \
    --to=ilias.apalodimas@linaro.org \
    --cc=agraf@csgraf.de \
    --cc=apalos@gmail.com \
    --cc=jens.wiklander@linaro.org \
    --cc=paul.liu@linaro.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /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.