summaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorAlex Dewar <alex.dewar90@gmail.com>2020-09-09 20:09:06 +0100
committerMimi Zohar <zohar@linux.ibm.com>2020-09-15 09:57:48 -0400
commitf60c826d031817772b634c0cda37794ce6d7946a (patch)
treee26c876c637443ae896c42f7a915db5eb6b7f512 /security
parent8c2f516c99f0b7e59c53158f4d7a7fe229c5aea8 (diff)
downloadlinux-f60c826d031817772b634c0cda37794ce6d7946a.tar.bz2
ima: Use kmemdup rather than kmalloc+memcpy
Issue identified with Coccinelle. Signed-off-by: Alex Dewar <alex.dewar90@gmail.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
Diffstat (limited to 'security')
-rw-r--r--security/integrity/ima/ima_policy.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
index 34221789c092..5b4bf1790e47 100644
--- a/security/integrity/ima/ima_policy.c
+++ b/security/integrity/ima/ima_policy.c
@@ -353,15 +353,14 @@ 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);
- if (!nentry)
- return NULL;
-
/*
* Immutable elements are copied over as pointers and data; only
* lsm rules can change
*/
- memcpy(nentry, entry, sizeof(*nentry));
+ nentry = kmemdup(entry, sizeof(*nentry), GFP_KERNEL);
+ if (!nentry)
+ return NULL;
+
memset(nentry->lsm, 0, sizeof_field(struct ima_rule_entry, lsm));
for (i = 0; i < MAX_LSM_RULES; i++) {