lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220801200338.261264-1-james.cowgill@blaize.com>
Date:   Mon, 1 Aug 2022 20:04:18 +0000
From:   James Cowgill <james.cowgill@...ize.com>
To:     Olivia Mackall <olivia@...enic.com>,
        Herbert Xu <herbert@...dor.apana.org.au>,
        Andre Przywara <andre.przywara@....com>,
        Ard Biesheuvel <ardb@...nel.org>,
        Mark Brown <broonie@...nel.org>
CC:     James Cowgill <james.cowgill@...ize.com>,
        "linux-crypto@...r.kernel.org" <linux-crypto@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: [PATCH] hwrng: arm-smccc-trng - fix NO_ENTROPY handling

The SMCCC_RET_TRNG_NO_ENTROPY switch arm is never used because the
NO_ENTROPY return value is negative and negative values are handled
above the switch by immediately returning.

Fix by handling errors using a default arm in the switch.

Fixes: 0888d04b47a1 ("hwrng: Add Arm SMCCC TRNG based driver")
Signed-off-by: James Cowgill <james.cowgill@...ize.com>
---
 drivers/char/hw_random/arm_smccc_trng.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/char/hw_random/arm_smccc_trng.c b/drivers/char/hw_random/arm_smccc_trng.c
index b24ac39a903b..e34c3ea692b6 100644
--- a/drivers/char/hw_random/arm_smccc_trng.c
+++ b/drivers/char/hw_random/arm_smccc_trng.c
@@ -66,33 +66,33 @@ static int smccc_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)
 	unsigned int copied = 0;
 	int tries = 0;
 
 	while (copied < max) {
 		size_t bits = min_t(size_t, (max - copied) * BITS_PER_BYTE,
 				  MAX_BITS_PER_CALL);
 
 		arm_smccc_1_1_invoke(ARM_SMCCC_TRNG_RND, bits, &res);
-		if ((int)res.a0 < 0)
-			return (int)res.a0;
 
 		switch ((int)res.a0) {
 		case SMCCC_RET_SUCCESS:
 			copied += copy_from_registers(buf + copied, &res,
 						      bits / BITS_PER_BYTE);
 			tries = 0;
 			break;
 		case SMCCC_RET_TRNG_NO_ENTROPY:
 			if (!wait)
 				return copied;
 			tries++;
 			if (tries >= SMCCC_TRNG_MAX_TRIES)
 				return copied;
 			cond_resched();
 			break;
+		default:
+			return -EIO;
 		}
 	}
 
 	return copied;
 }
 
 static int smccc_trng_probe(struct platform_device *pdev)
 {
-- 
2.36.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ