2020-08-24 21:23:20

by Alex Dewar

[permalink] [raw]
Subject: [PATCH] ima: use kmemdup() rather than kmalloc+memcpy

Issue identified with Coccinelle.

Signed-off-by: Alex Dewar <[email protected]>
---
security/integrity/ima/ima_policy.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
index b4de33074b37..ea917a787d9d 100644
--- a/security/integrity/ima/ima_policy.c
+++ b/security/integrity/ima/ima_policy.c
@@ -284,7 +284,7 @@ static struct ima_rule_entry *ima_lsm_copy_rule(struct ima_rule_entry *entry)
struct ima_rule_entry *nentry;
int i;

- nentry = kmalloc(sizeof(*nentry), GFP_KERNEL);
+ nentry = kmemdup(entry, sizeof(*nentry), GFP_KERNEL);
if (!nentry)
return NULL;

@@ -292,7 +292,6 @@ static struct ima_rule_entry *ima_lsm_copy_rule(struct ima_rule_entry *entry)
* Immutable elements are copied over as pointers and data; only
* lsm rules can change
*/
- memcpy(nentry, entry, sizeof(*nentry));
memset(nentry->lsm, 0, sizeof_field(struct ima_rule_entry, lsm));

for (i = 0; i < MAX_LSM_RULES; i++) {
--
2.28.0