Skip to contentSkip to conversation

crypto: iaa - Fix out-of-bounds index in find_empty_iaa_compression_mode

PATCH In review Thorsten Blum 3 participants 3 messages Nov 27, 2025 – Dec 19, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: iaa - Fix out-of-bounds index in find_empty_iaa_compression_mode

The local variable 'i' is initialized with -EINVAL, but the for loop immediately overwrites it and -EINVAL is never returned.

If no empty compression mode can be found, the function would return the out-of-bounds index IAA_COMP_MODES_MAX, which would cause an invalid array access in add_iaa_compression_mode().

Fix both issues by returning either a valid index or -EINVAL.

Fixes b190447e0fa3 ("crypto: iaa - Add compression mode management along with fixed mode")
---
 drivers/crypto/intel/iaa/iaa_crypto_main.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/crypto/intel/iaa/iaa_crypto_main.c +5 -7
index 23f585219fb4..8ee2a55ec449 100644
@@ -221,15 +221,13 @@ static struct iaa_compression_mode *iaa_compression_modes[IAA_COMP_MODES_MAX];
 
 static int find_empty_iaa_compression_mode(void)
 {
-	int i = -EINVAL;
+	int i;
 
-	for (i = 0; i < IAA_COMP_MODES_MAX; i++) {
-		if (iaa_compression_modes[i])
-			continue;
-		break;
-	}
+	for (i = 0; i < IAA_COMP_MODES_MAX; i++)
+		if (!iaa_compression_modes[i])
+			return i;
 
-	return i;
+	return -EINVAL;
 }
 
 static struct iaa_compression_mode *find_iaa_compression_mode(const char *name, int *idx)
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
Acked-by on v1 1/1
#1 lore raw
Quoted 21 lines

-----Original Message-----
From: Thorsten Blum <[email protected]>
Sent: Thursday, November 27, 2025 6:02 AM
To: Accardi, Kristen C <[email protected]>; Gomes, Vinicius <[email protected]>; Sridhar, Kanchana P <[email protected]>; Herbert Xu <[email protected]>; David S. Miller <[email protected]>; Tom Zanussi <[email protected]>
Cc: Thorsten Blum <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH] crypto: iaa - Fix out-of-bounds index in find_empty_iaa_compression_mode

The local variable 'i' is initialized with -EINVAL, but the for loop immediately overwrites it and -EINVAL is never returned.

If no empty compression mode can be found, the function would return the out-of-bounds index IAA_COMP_MODES_MAX, which would cause an invalid array access in add_iaa_compression_mode().

Quoted 6 lines

Fix both issues by returning either a valid index or -EINVAL.

Fixes b190447e0fa3 ("crypto: iaa - Add compression mode management

along with fixed mode")

Quoted 35 lines
---
 drivers/crypto/intel/iaa/iaa_crypto_main.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/crypto/intel/iaa/iaa_crypto_main.c +5 -7
index 23f585219fb4..8ee2a55ec449 100644
@@ -221,15 +221,13 @@ static struct iaa_compression_mode
 *iaa_compression_modes[IAA_COMP_MODES_MAX];
 
 static int find_empty_iaa_compression_mode(void)
 {
-	int i = -EINVAL;
+	int i;
 
-	for (i = 0; i < IAA_COMP_MODES_MAX; i++) {
-		if (iaa_compression_modes[i])
-			continue;
-		break;
-	}
+	for (i = 0; i < IAA_COMP_MODES_MAX; i++)
+		if (!iaa_compression_modes[i])
+			return i;
 
-	return i;
+	return -EINVAL;
 }
 

static struct iaa_compression_mode *find_iaa_compression_mode(const
char *name, int *idx)
--
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4

maintainer
#2 lore raw
In reply to Thorsten Blum
Quoted 7 lines · Thorsten Blum

The local variable 'i' is initialized with -EINVAL, but the for loop immediately overwrites it and -EINVAL is never returned.

If no empty compression mode can be found, the function would return the out-of-bounds index IAA_COMP_MODES_MAX, which would cause an invalid array access in add_iaa_compression_mode().

Quoted 8 lines

Fix both issues by returning either a valid index or -EINVAL.

Fixes b190447e0fa3 ("crypto: iaa - Add compression mode management along with fixed mode")
---
 drivers/crypto/intel/iaa/iaa_crypto_main.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt