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 D205AC4708C for ; Tue, 6 Dec 2022 02:34:18 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6E4A0854AA; Tue, 6 Dec 2022 03:34:16 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1670294056; bh=H+VaUf50yGH390UTb73MoWGkufLSLp9ahm+eNiWEQWs=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=UA/z/23ATv5BaNl3/qeUNRwnkcvp0esI5PDopkm1dvTMErnjoTgR0MrYv2bZUDhHP JmYHQQSg+sQL96XGZpAXUGVbTqihz4Oup+2O9uShHG8HlrNbePHNYSfxXUtCcdcuhT 4RLQEUb8OVOBstaZOHky8yqH6IAVnbIqhy8I2CwnuDAOG/jnd2z2paNSl1O9FXfwTM h+sDvdcNGV5FUt584VTHqfN5ELvIjouB/cDFURpwoEOlGn4ttfD+4a7wxvRhKDNrrm bFOCTE3z7Jqdh6N8XvMNJR5uUC9C/wfWKmDG/JJjqh+qGBgsODedOKyNnIujxtkhgM LC83GZvN/4c4Q== Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 7D98584F87; Tue, 6 Dec 2022 03:34:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1670294054; bh=H+VaUf50yGH390UTb73MoWGkufLSLp9ahm+eNiWEQWs=; h=From:To:Cc:Subject:Date:From; b=qdRSAjpCkTMhYNkm+wKLu8Gp65cPOflO2lNFL7n/0c8caYRSp3wJ7U5E455vo6d2u ga2n6CzPZsxup2e2ZdjtUlXL5s8103xs1senEy5TlktFcFjMcs7lv6f2/22RTvYBeQ lSLTXFxoFR9AHNKTW2dkuVszYEpUODYTA87FEdBQy+DZEUjCYNbHccPaau7r9AyI0t /U9GGLicIoM2sJbTFTC3VmD0WSqPQbYATcviTOoiZlnTulnFOMXsiFh1aZDXeVrkYm pX/Qa8aJgK4J/Enz1HP68RY0aGZnl36p0JUW8JRogf4pNcZCWseTlhFwygIppVoFMt S4Vm1TuQZgq5Q== From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , Alexandru Gagniuc , Patrice Chotard , Patrick Delaunay Subject: [PATCH 1/4] ARM: stm32: Fix ECDSA authentication with Dcache enabled Date: Tue, 6 Dec 2022 03:33:54 +0100 Message-Id: <20221206023357.113361-1-marex@denx.de> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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; } -- 2.35.1