Skip to content

Commit 42413b4

Browse files
robertosassumimizohar
authored andcommitted
ima: Directly free *entry in ima_alloc_init_template() if digests is NULL
To support multiple template digests, the static array entry->digest has been replaced with a dynamically allocated array in commit aa724fe ("ima: Switch to dynamically allocated buffer for template digests"). The array is allocated in ima_alloc_init_template() and if the returned pointer is NULL, ima_free_template_entry() is called. However, (*entry)->template_desc is not yet initialized while it is used by ima_free_template_entry(). This patch fixes the issue by directly freeing *entry without calling ima_free_template_entry(). Fixes: aa724fe ("ima: Switch to dynamically allocated buffer for template digests") Reported-by: [email protected] Signed-off-by: Roberto Sassu <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent 6cc7c26 commit 42413b4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

security/integrity/ima/ima_api.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ int ima_alloc_init_template(struct ima_event_data *event_data,
5555
digests = kcalloc(NR_BANKS(ima_tpm_chip) + ima_extra_slots,
5656
sizeof(*digests), GFP_NOFS);
5757
if (!digests) {
58-
result = -ENOMEM;
59-
goto out;
58+
kfree(*entry);
59+
*entry = NULL;
60+
return -ENOMEM;
6061
}
6162

6263
(*entry)->digests = digests;

0 commit comments

Comments
 (0)