Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 901ABC3A5A7 for ; Tue, 6 Dec 2022 07:40:42 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 08BD1853DA; Tue, 6 Dec 2022 08:40:40 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.b="ObZp/SKM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4470785310; Tue, 6 Dec 2022 08:40:38 +0100 (CET) Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3092385586 for ; Tue, 6 Dec 2022 08:40:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=83393c7670=patrice.chotard@foss.st.com Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B63Hbwm016368; Tue, 6 Dec 2022 08:40:33 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=Bs2cXCyxbjcxx0/1x9dGubmJ3/xpkve9ikwgmfndx6M=; b=ObZp/SKM1wONJhdgNZtAuA9gAjstEMiK7v6giMIqw+aam9Zvj5azrST+I6R58DKPvZFe x7jqULtnKdELlc3p8BZ+YYC/Kw/Z6jjlMnydcnS7NqRNaIiaOeirtZuWe9y/cjcOdN7/ sMwYx2n85tRr7JVWKDJwBS8rn1yci3S008KqIsJBCIsfWzdMBuxUq/4Jo6ZbQopWA2aI TlivSi+53nBU2r3oRX7uidXfXGk+brLMaZ7P0F9L2olk6s2LRnB39NjMG3EWSKLNANEm rVsPkaxMjNbaSO4432facsA/LgEeqHNgFfrV6M7n4WfAJyMdJqE5Ab3Kc/0JFg8oal+L zg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3m7xp6xspr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 06 Dec 2022 08:40:33 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4582010002A; Tue, 6 Dec 2022 08:40:22 +0100 (CET) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 3F3D7212FAA; Tue, 6 Dec 2022 08:40:22 +0100 (CET) Received: from [10.201.20.130] (10.201.20.130) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.13; Tue, 6 Dec 2022 08:40:21 +0100 Message-ID: Date: Tue, 6 Dec 2022 08:40:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH 1/4] ARM: stm32: Fix ECDSA authentication with Dcache enabled Content-Language: en-US To: Marek Vasut , CC: Alexandru Gagniuc , Patrick Delaunay References: <20221206023357.113361-1-marex@denx.de> From: Patrice CHOTARD In-Reply-To: <20221206023357.113361-1-marex@denx.de> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.201.20.130] X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-06_05,2022-12-05_01,2022-06-22_01 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On 12/6/22 03:33, Marek Vasut wrote: > In case Dcache is enabled while the ECDSA authentication function is > called via BootROM ROM API, the CRYP DMA might pick stale version of > data from DRAM. Disable Dcache around the BootROM call to avoid this > issue. > > Signed-off-by: Marek Vasut > --- > Cc: Alexandru Gagniuc > Cc: Patrice Chotard > Cc: Patrick Delaunay > --- > arch/arm/mach-stm32mp/ecdsa_romapi.c | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/arch/arm/mach-stm32mp/ecdsa_romapi.c b/arch/arm/mach-stm32mp/ecdsa_romapi.c > index a2f63ff879f..72b87bf2c64 100644 > --- a/arch/arm/mach-stm32mp/ecdsa_romapi.c > +++ b/arch/arm/mach-stm32mp/ecdsa_romapi.c > @@ -64,6 +64,7 @@ static int romapi_ecdsa_verify(struct udevice *dev, > const void *signature, size_t sig_len) > { > struct ecdsa_rom_api rom; > + bool reenable_dcache; > uint8_t raw_key[64]; > uint32_t rom_ret; > int algo; > @@ -81,8 +82,21 @@ static int romapi_ecdsa_verify(struct udevice *dev, > memcpy(raw_key + 32, pubkey->y, 32); > > stm32mp_rom_get_ecdsa_functions(&rom); > + > + /* > + * Disable D-cache before calling into BootROM, else CRYP DMA > + * may fail to pick up the correct data. > + */ > + if (dcache_status()) { > + dcache_disable(); > + reenable_dcache = true; > + } > + > rom_ret = rom.ecdsa_verify_signature(hash, raw_key, signature, algo); > > + if (reenable_dcache) > + dcache_enable(); > + > return rom_ret == ROM_API_SUCCESS ? 0 : -EPERM; > } > Reviewed-by: Patrice Chotard Thanks Patrice