Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 81765388 authored by Xiu Jianfeng's avatar Xiu Jianfeng Committed by Greg Kroah-Hartman
Browse files

ima: Fix misuse of dereference of pointer in template_desc_init_fields()



[ 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: adf53a77 ("ima: new templates management mechanism")
Signed-off-by: default avatarXiu Jianfeng <xiujianfeng@huawei.com>
Reviewed-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 9b7c4488
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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;
	}