From: "Auer, Lukas" <lukas.auer@aisec.fraunhofer.de>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"aymen.sghaier@nxp.com" <aymen.sghaier@nxp.com>,
"horia.geanta@nxp.com" <horia.geanta@nxp.com>,
"pure.logic@nexus-software.ie" <pure.logic@nexus-software.ie>,
"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>
Cc: "peng.fan@nxp.com" <peng.fan@nxp.com>,
"davem@davemloft.net" <davem@davemloft.net>,
"ryan.harkin@linaro.org" <ryan.harkin@linaro.org>,
"fabio.estevam@nxp.com" <fabio.estevam@nxp.com>,
"rui.silva@linaro.org" <rui.silva@linaro.org>,
"herbert@gondor.apana.org.au" <herbert@gondor.apana.org.au>
Subject: Re: [RESEND PATCH 6/6] crypto: caam: detect RNG init when TrustZone is active
Date: Thu, 25 Jan 2018 13:20:55 +0000 [thread overview]
Message-ID: <1516886454.3733.23.camel@aisec.fraunhofer.de> (raw)
In-Reply-To: <1516805435-15034-7-git-send-email-pure.logic@nexus-software.ie>
On Wed, 2018-01-24 at 14:50 +0000, Bryan O'Donoghue wrote:
> When TrustZone is enabled on sec4 compatible silicon the first page
> of the
> CAAM is reserved for TrustZone only, this means that access to the
> deco
> registers is restricted and will return zero when read.
>
> The solution to this problem is to initialize the RNG prior to
> TrustZone
> being enabled or to initialize the RNG from a TrustZone context and
> simultaneously to ensure that the job-ring registers have been
> assigned to
> the correct non-TrustZone context.
>
> Assigning of the job-ring registers is a task for u-boot or
> OPTEE/TrustZone
> as is the initialization of the RNG. This patch adds logic to detect
> RNG
> initialization if and only if TrustZone has been detected as active
> on the
> CAAM block.
>
> If TrustZone is initialized and the RNG looks to be setup - we mark
> the RNG
> as good to go and continue to load, else we mark the RNG as bad and
> bail
> out.
>
> More detail on the original problem and the split fix between u-boot
> and
> Linux is available in these two threads
>
> Link: https://github.com/OP-TEE/optee_os/issues/1408
> Link: https://tinyurl.com/yam5gv9a
> Link: https://patchwork.ozlabs.org/cover/865042
>
> Signed-off-by: Bryan O'Donoghue <pure.logic@nexus-software.ie>
> Cc: "Horia Geantă" <horia.geanta@nxp.com>
> Cc: Aymen Sghaier <aymen.sghaier@nxp.com>
> Cc: Fabio Estevam <fabio.estevam@nxp.com>
> Cc: Peng Fan <peng.fan@nxp.com>
> Cc: Herbert Xu <herbert@gondor.apana.org.au>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Lukas Auer <lukas.auer@aisec.fraunhofer.de>
> ---
> drivers/crypto/caam/ctrl.c | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
> index 7fd3bfc..66a7c7e 100644
> --- a/drivers/crypto/caam/ctrl.c
> +++ b/drivers/crypto/caam/ctrl.c
> @@ -711,6 +711,24 @@ static int caam_probe(struct platform_device
> *pdev)
> int inst_handles =
> rd_reg32(&ctrl->r4tst[0].rdsta) &
> RDST
> A_IFMASK;
> +
> + /*
> + * If TrustZone is active then u-boot or the
> TrustZone
> + * firmware must have initialized the RNG
> for us else we
> + * cannot do so from Linux.
> + *
> + * We've previously detected TrustZone so
> now let's
> + * detect if the RNG has been initialized.
> + */
> + if (ctrlpriv->trust_zone) {
> + ret = -ENODEV;
> + if (ctrlpriv->rng4_sh_init ||
> inst_handles)
> + ret = 0;
> + dev_info(dev, "TrustZone active RNG
> looks %s\n",
> + ret ? "uninitialized" :
> "initialized");
> + break;
> + }
> +
> /*
> * If either SH were instantiated by
> somebody else
> * (e.g. u-boot) then it is assumed that the
> entropy
This (in addition to patch 5) should not be required if all RNG state
handles are already instantiated. The instantiate_rng() function checks
each state handle if it is already instantiated before trying to do so
itself. DEC0 would therefore never be used and the probe call should
succeed in non-secure mode.
I have submitted a patch [1] to u-boot that instantiates all RNG state
handles.
Thanks,
Lukas
[1] https://www.mail-archive.com/u-boot@lists.denx.de/msg276184.html
next prev parent reply other threads:[~2018-01-25 13:21 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-24 14:50 [RESEND PATCH 0/6] Enable CAAM on i.MX7s fix TrustZone issues Bryan O'Donoghue
2018-01-24 14:50 ` [RESEND PATCH 1/6] crypto: caam: Fix null dereference at error path Bryan O'Donoghue
2018-01-25 17:09 ` Horia Geantă
2018-01-24 14:50 ` [RESEND PATCH 2/6] crypto: caam: Fix endless loop when RNG is already initialized Bryan O'Donoghue
2018-01-24 14:50 ` [RESEND PATCH 3/6] ARM: dts: imx7s: add CAAM device node Bryan O'Donoghue
2018-01-24 18:12 ` Auer, Lukas
2018-01-24 22:48 ` Bryan O'Donoghue
2018-01-24 22:56 ` Bryan O'Donoghue
2018-01-27 15:49 ` kbuild test robot
2018-01-28 15:42 ` Rui Miguel Silva
2018-01-24 14:50 ` [RESEND PATCH 4/6] imx7d: add CAAM clocks Bryan O'Donoghue
2018-01-24 14:50 ` [RESEND PATCH 5/6] crypto: caam: add logic to detect when running under TrustZone Bryan O'Donoghue
2018-01-24 14:50 ` [RESEND PATCH 6/6] crypto: caam: detect RNG init when TrustZone is active Bryan O'Donoghue
2018-01-25 13:20 ` Auer, Lukas [this message]
2018-01-25 17:54 ` Bryan O'Donoghue
2018-01-25 17:50 ` [RESEND PATCH 0/6] Enable CAAM on i.MX7s fix TrustZone issues Horia Geantă
2018-01-26 1:06 ` Bryan O'Donoghue
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=1516886454.3733.23.camel@aisec.fraunhofer.de \
--to=lukas.auer@aisec.fraunhofer.de \
--cc=aymen.sghaier@nxp.com \
--cc=davem@davemloft.net \
--cc=fabio.estevam@nxp.com \
--cc=herbert@gondor.apana.org.au \
--cc=horia.geanta@nxp.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peng.fan@nxp.com \
--cc=pure.logic@nexus-software.ie \
--cc=rui.silva@linaro.org \
--cc=ryan.harkin@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®