]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
crypto: iaa - Fix out-of-bounds index in find_empty_iaa_compression_mode
authorThorsten Blum <thorsten.blum@linux.dev>
Thu, 27 Nov 2025 14:01:57 +0000 (15:01 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 19 Dec 2025 06:47:47 +0000 (14:47 +0800)
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.

Cc: stable@vger.kernel.org
Fixes: b190447e0fa3 ("crypto: iaa - Add compression mode management along with fixed mode")
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Acked-by: Kanchana P Sridhar <kanchana.p.sridhar@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/intel/iaa/iaa_crypto_main.c

index d0058757b0000d2e7cd9d6bc15416a8319ee83cb..da9b2bc515194f6a23a23c03acd0e46dd5d1c2b2 100644 (file)
@@ -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)