From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752068AbeAYNVG (ORCPT ); Thu, 25 Jan 2018 08:21:06 -0500 Received: from mail-edgeka24.fraunhofer.de ([153.96.1.24]:38296 "EHLO mail-edgeKA24.fraunhofer.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751674AbeAYNVE (ORCPT ); Thu, 25 Jan 2018 08:21:04 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2EYBQB+2Wla/xoBYJldGwEBAQEDAQEBC?= =?us-ascii?q?QEBAYNCZnQnB4NWixiNdIICmRdDChgLgV6DOgIagXxYFAEBAQEBAQEBAgNoKIJ?= =?us-ascii?q?nBEsqAwEBAQEBAQEBASMBAQEBAQEBAQEBAQEBAQEaAg0YRgEBBAEiBA1FEAIBC?= =?us-ascii?q?BgCAiYCAgImChUQAgQBDQUbihkBELQugW06hBYBAYZAAQEBAQEBBAEBAQEBAQE?= =?us-ascii?q?BAQEZBYEPg0KBDoEHgViBZ4Mugy8CAQGBTwEBgzWCZQWkBAYCgRuGeIcxhhyCG?= =?us-ascii?q?4oLK4dUjVEIA4l+gTw2I4FQcYJ7IYN7ATp4AQELAYwIgSWBFwEBAQ?= X-IPAS-Result: =?us-ascii?q?A2EYBQB+2Wla/xoBYJldGwEBAQEDAQEBCQEBAYNCZnQnB4N?= =?us-ascii?q?WixiNdIICmRdDChgLgV6DOgIagXxYFAEBAQEBAQEBAgNoKIJnBEsqAwEBAQEBA?= =?us-ascii?q?QEBASMBAQEBAQEBAQEBAQEBAQEaAg0YRgEBBAEiBA1FEAIBCBgCAiYCAgImChU?= =?us-ascii?q?QAgQBDQUbihkBELQugW06hBYBAYZAAQEBAQEBBAEBAQEBAQEBAQEZBYEPg0KBD?= =?us-ascii?q?oEHgViBZ4Mugy8CAQGBTwEBgzWCZQWkBAYCgRuGeIcxhhyCG4oLK4dUjVEIA4l?= =?us-ascii?q?+gTw2I4FQcYJ7IYN7ATp4AQELAYwIgSWBFwEBAQ?= X-IronPort-AV: E=Sophos;i="5.46,412,1511823600"; d="scan'208";a="4047644" X-IronPort-AV: E=Sophos;i="5.46,412,1511823600"; d="scan'208";a="6944178" From: "Auer, Lukas" To: "linux-kernel@vger.kernel.org" , "aymen.sghaier@nxp.com" , "horia.geanta@nxp.com" , "pure.logic@nexus-software.ie" , "linux-crypto@vger.kernel.org" CC: "peng.fan@nxp.com" , "davem@davemloft.net" , "ryan.harkin@linaro.org" , "fabio.estevam@nxp.com" , "rui.silva@linaro.org" , "herbert@gondor.apana.org.au" Subject: Re: [RESEND PATCH 6/6] crypto: caam: detect RNG init when TrustZone is active Thread-Topic: [RESEND PATCH 6/6] crypto: caam: detect RNG init when TrustZone is active Thread-Index: AQHTlSLND7aC3/mxmEq7O8ZIEAjfkKOEg54A Date: Thu, 25 Jan 2018 13:20:55 +0000 Message-ID: <1516886454.3733.23.camel@aisec.fraunhofer.de> References: <1516805435-15034-1-git-send-email-pure.logic@nexus-software.ie> <1516805435-15034-7-git-send-email-pure.logic@nexus-software.ie> In-Reply-To: <1516805435-15034-7-git-send-email-pure.logic@nexus-software.ie> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.80.233.51] x-tm-as-product-ver: SMEX-11.0.0.4179-8.200.1013-23618.006 x-tm-as-result: No--3.243000-8.000000-31 x-tm-as-user-approved-sender: No x-tm-as-user-blocked-sender: No Content-Type: text/plain; charset="utf-8" Content-ID: <0EA716E512C8F84598CEA20171FE1BE0@xch.fraunhofer.de> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id w0PDLDdX004932 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 > Cc: "Horia Geantă" > Cc: Aymen Sghaier > Cc: Fabio Estevam > Cc: Peng Fan > Cc: Herbert Xu > Cc: "David S. Miller" > Cc: Lukas Auer > --- > 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