diff mbox series

[2/3] crypto: spacc - Fix off by one in spacc_isenabled()

Message ID 6327d472-b4d5-4678-b54c-9808a68e3504@stanley.mountain (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series crypto: spacc - Fix Smatch issues | expand

Commit Message

Dan Carpenter Aug. 14, 2024, 9:11 p.m. UTC
The spacc->config.modes[] array has CRYPTO_MODE_LAST number of elements
so this > comparison should be >= to prevent an out of bounds access.

Fixes: c8981d9230d8 ("crypto: spacc - Add SPAcc Skcipher support")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
The CRYPTO_MODE_LAST variable is poorly named.  Based on the name you
would expect it to be the last valid value but it's not.  (I'm not
a huge fan of code which uses the last valid value instead of the
size personally, but the names should match).

 drivers/crypto/dwc-spacc/spacc_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/crypto/dwc-spacc/spacc_core.c b/drivers/crypto/dwc-spacc/spacc_core.c
index e3380528e82b..b7630f559973 100644
--- a/drivers/crypto/dwc-spacc/spacc_core.c
+++ b/drivers/crypto/dwc-spacc/spacc_core.c
@@ -1295,7 +1295,7 @@  int spacc_isenabled(struct spacc_device *spacc, int mode, int keysize)
 {
 	int x;
 
-	if (mode < 0 || mode > CRYPTO_MODE_LAST)
+	if (mode < 0 || mode >= CRYPTO_MODE_LAST)
 		return 0;
 
 	if (mode == CRYPTO_MODE_NULL    ||