1
0
Fork 0

MLK-24517-3 crypto: caam - add null terminator to temporary buffer

Add null terminator to temporary buffer used to copy from
user-space data needed for key generation.
This buffer is later used in operations (i.e. strlen()) that
expects properly null-terminated strings.
Therefore add the null terminator character.

Reported-by: Coverity 10893158
Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
Reviewed-by: Franck LENORMAND <franck.lenormand@nxp.com>
(cherry picked from commit b8c49eddfd687e049923ab1e5aca09e2b4160f54)
5.4-rM2-2.2.x-imx-squashed
Iuliana Prodan 2020-08-21 18:28:18 +03:00
parent ef17a97b4b
commit acee2fa973
1 changed files with 4 additions and 1 deletions

View File

@ -144,6 +144,7 @@ static int validate_input(struct caam_keygen_cmd *key_crt, unsigned long arg,
bool random = false;
int ret = 0;
u32 tmp_len = 0;
char null_ch = 0;
/*
* So far, we only support Black keys, encrypted with JDKEK,
@ -174,7 +175,7 @@ static int validate_input(struct caam_keygen_cmd *key_crt, unsigned long arg,
*/
tmp_size = max_t(size_t, key_crt->key_enc_len,
max_t(size_t, key_crt->key_mode_len,
key_crt->key_value_len));
key_crt->key_value_len)) + 1;
tmp = kmalloc(tmp_size, GFP_KERNEL);
if (!tmp) {
msg = "Unable to allocate memory for temporary buffer.\n";
@ -182,6 +183,8 @@ static int validate_input(struct caam_keygen_cmd *key_crt, unsigned long arg,
key_crt->blob_len);
return -ENOMEM;
}
/* Add null terminator */
tmp[tmp_size - 1] = null_ch;
/*
* Validate and set, in type, the Encrypted Key Type
* given from user-space.