Skip to content

Commit

Permalink
ima: Fix misuse of dereference of pointer in template_desc_init_fields()
Browse files Browse the repository at this point in the history
[ Upstream commit 2536917 ]

The input parameter @fields is type of struct ima_template_field ***, so
when allocates array memory for @fields, the size of element should be
sizeof(**field) instead of sizeof(*field).

Actually the original code would not cause any runtime error, but it's
better to make it logically right.

Fixes: adf53a7 ("ima: new templates management mechanism")
Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
Reviewed-by: Roberto Sassu <roberto.sassu@huawei.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Xiu Jianfeng authored and gregkh committed Dec 31, 2022
1 parent 29d6c69 commit 6225194
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions security/integrity/ima/ima_template.c
Expand Up @@ -241,11 +241,11 @@ int template_desc_init_fields(const char *template_fmt,
}

if (fields && num_fields) {
*fields = kmalloc_array(i, sizeof(*fields), GFP_KERNEL);
*fields = kmalloc_array(i, sizeof(**fields), GFP_KERNEL);
if (*fields == NULL)
return -ENOMEM;

memcpy(*fields, found_fields, i * sizeof(*fields));
memcpy(*fields, found_fields, i * sizeof(**fields));
*num_fields = i;
}

Expand Down

0 comments on commit 6225194

Please sign in to comment.