Skip to contentSkip to conversation

KEYS: use kmemdup() in request_key_auth_new()

PATCH New Eric Biggers 1 participant 1 message Sep 18, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KEYS: use kmemdup() in request_key_auth_new()

From: Eric Biggers <[email protected]>

kmemdup() is preferred to kmalloc() followed by memcpy().

---
 security/keys/request_key_auth.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
security/keys/request_key_auth.c +2 -3
index f2f29f13ecff..08bf6f99c043 100644
@@ -161,12 +161,13 @@ struct key *request_key_auth_new(struct key *target, const void *callout_info,
 		kleave(" = -ENOMEM");
 		return ERR_PTR(-ENOMEM);
 	}
-	rka->callout_info = kmalloc(callout_len, GFP_KERNEL);
+	rka->callout_info = kmemdup(callout_info, callout_len, GFP_KERNEL);
 	if (!rka->callout_info) {
 		kleave(" = -ENOMEM");
 		kfree(rka);
 		return ERR_PTR(-ENOMEM);
 	}
+	rka->callout_len = callout_len;
 
 	/* see if the calling process is already servicing the key request of
 	 * another process */
@@ -193,8 +194,6 @@ struct key *request_key_auth_new(struct key *target, const void *callout_info,
 
 	rka->target_key = key_get(target);
 	rka->dest_keyring = key_get(dest_keyring);
-	memcpy(rka->callout_info, callout_info, callout_len);
-	rka->callout_len = callout_len;
 
 	/* allocate the auth key */
 	sprintf(desc, "%x", target->serial);
Signature · 1 line
2.14.1.690.gbb1197296e-goog