Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.

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>

authored by

Thorsten Blum and committed by
Herbert Xu
48329301 5565a72b

+5 -7
+5 -7
drivers/crypto/intel/iaa/iaa_crypto_main.c
··· 221 221 222 222 static int find_empty_iaa_compression_mode(void) 223 223 { 224 - int i = -EINVAL; 224 + int i; 225 225 226 - for (i = 0; i < IAA_COMP_MODES_MAX; i++) { 227 - if (iaa_compression_modes[i]) 228 - continue; 229 - break; 230 - } 226 + for (i = 0; i < IAA_COMP_MODES_MAX; i++) 227 + if (!iaa_compression_modes[i]) 228 + return i; 231 229 232 - return i; 230 + return -EINVAL; 233 231 } 234 232 235 233 static struct iaa_compression_mode *find_iaa_compression_mode(const char *name, int *idx)