]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ima: Fix misuse of dereference of pointer in template_desc_init_fields()
authorXiu Jianfeng <xiujianfeng@huawei.com>
Sat, 12 Nov 2022 09:27:19 +0000 (17:27 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Jan 2023 10:41:03 +0000 (11:41 +0100)
[ Upstream commit 25369175ce84813dd99d6604e710dc2491f68523 ]

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: e5ac05aabec8 ("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>
security/integrity/ima/ima_template.c

index 2283051d063bce786793cc7de64df74a7d06f3ff..7721909b26152fc9d4f733fb904150e9905359eb 100644 (file)
@@ -222,11 +222,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;
        }