Skip to content

Commit c77b33b

Browse files
tobluxgregkh
authored andcommitted
crypto: iaa - Fix out-of-bounds index in find_empty_iaa_compression_mode
commit 4832930 upstream. 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: b190447 ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 52b6e74 commit c77b33b

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

drivers/crypto/intel/iaa/iaa_crypto_main.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,13 @@ static struct iaa_compression_mode *iaa_compression_modes[IAA_COMP_MODES_MAX];
223223

224224
static int find_empty_iaa_compression_mode(void)
225225
{
226-
int i = -EINVAL;
226+
int i;
227227

228-
for (i = 0; i < IAA_COMP_MODES_MAX; i++) {
229-
if (iaa_compression_modes[i])
230-
continue;
231-
break;
232-
}
228+
for (i = 0; i < IAA_COMP_MODES_MAX; i++)
229+
if (!iaa_compression_modes[i])
230+
return i;
233231

234-
return i;
232+
return -EINVAL;
235233
}
236234

237235
static struct iaa_compression_mode *find_iaa_compression_mode(const char *name, int *idx)

0 commit comments

Comments
 (0)