From 2e1dba44fded455a38b3870998286ab16bc4237e Mon Sep 17 00:00:00 2001 From: Konstantin Porotchkin Date: Sun, 2 Aug 2020 20:27:56 +0300 Subject: [PATCH] plat/marvell/armada: fix TRNG return SMC handling Use single 64b register for the return value instead of two 32b. Report an error if caller requested larger than than 64b random number in a single SMC call. Signed-off-by: Konstantin Porotchkin Change-Id: Ib8756cd3c0808b78c359f90c6f6913f7d16ac360 Reviewed-on: https://sj1git1.cavium.com/c/IP/SW/boot/atf/+/33280 Tested-by: sa_ip-sw-jenkins Reviewed-by: Nadav Haklai --- plat/marvell/armada/common/mrvl_sip_svc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plat/marvell/armada/common/mrvl_sip_svc.c b/plat/marvell/armada/common/mrvl_sip_svc.c index 4e17390ce..c4c5c0eea 100644 --- a/plat/marvell/armada/common/mrvl_sip_svc.c +++ b/plat/marvell/armada/common/mrvl_sip_svc.c @@ -80,7 +80,6 @@ uintptr_t mrvl_sip_smc_handler(uint32_t smc_fid, u_register_t flags) { u_register_t ret, read, x5 = x1; - uint32_t w2[2] = {0, 0}; int i; debug("%s: got SMC (0x%x) x1 0x%lx, x2 0x%lx, x3 0x%lx\n", @@ -165,8 +164,13 @@ uintptr_t mrvl_sip_smc_handler(uint32_t smc_fid, ret = mvebu_ddr_phy_read(x1, (uint16_t *)&read); SMC_RET2(handle, ret, read); case MV_SIP_RNG_64: - ret = eip76_rng_get_random((uint8_t *)&w2, 4 * (x1 % 2 + 1)); - SMC_RET3(handle, ret, w2[0], w2[1]); + if ((x1 % 2 + 1) > sizeof(read)/4) { + ERROR("%s: Maximum %ld random bytes per SMC call\n", + __func__, sizeof(read)); + SMC_RET1(handle, SMC_UNK); + } + ret = eip76_rng_get_random((uint8_t *)&read, 4 * (x1 % 2 + 1)); + SMC_RET2(handle, ret, read); default: ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid); SMC_RET1(handle, SMC_UNK); -- GitLab