public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH 1/4] ARM: stm32: Fix ECDSA authentication with Dcache enabled
@ 2022-12-06  2:33 Marek Vasut
  2022-12-06  2:33 ` [PATCH 2/4] ARM: stm32: Factor out save_boot_params Marek Vasut
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: Marek Vasut @ 2022-12-06  2:33 UTC (permalink / raw)
  To: u-boot; +Cc: Marek Vasut, Alexandru Gagniuc, Patrice Chotard, Patrick Delaunay

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 <marex@denx.de>
---
Cc: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Cc: Patrice Chotard <patrice.chotard@foss.st.com>
Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
---
 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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-12-06 12:04 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-06  2:33 [PATCH 1/4] ARM: stm32: Fix ECDSA authentication with Dcache enabled Marek Vasut
2022-12-06  2:33 ` [PATCH 2/4] ARM: stm32: Factor out save_boot_params Marek Vasut
2022-12-06  8:08   ` Patrice CHOTARD
2022-12-06  8:43   ` Patrick DELAUNAY
2022-12-06  2:33 ` [PATCH 3/4] ARM: stm32: Pass ROM API table pointer to U-Boot proper Marek Vasut
2022-12-06  8:09   ` Patrice CHOTARD
2022-12-06  8:53   ` Patrick DELAUNAY
2022-12-06  2:33 ` [PATCH 4/4] ARM: stm32: Make ECDSA authentication available to U-Boot Marek Vasut
2022-12-06  8:09   ` Patrice CHOTARD
2022-12-06  8:57   ` Patrick DELAUNAY
2022-12-06  7:40 ` [PATCH 1/4] ARM: stm32: Fix ECDSA authentication with Dcache enabled Patrice CHOTARD
2022-12-06  8:56 ` Patrice CHOTARD
2022-12-06  9:13 ` Patrick DELAUNAY
2022-12-06 11:51   ` Marek Vasut

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox