linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KEYS: use memdup_user
@ 2017-05-13  3:15 Geliang Tang
  0 siblings, 0 replies; only message in thread
From: Geliang Tang @ 2017-05-13  3:15 UTC (permalink / raw)
  To: linux-security-module

Use memdup_user() helper instead of open-coding to simplify the code.

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
 security/keys/keyctl.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index dd0da25..ce1574a 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -326,14 +326,11 @@ long keyctl_update_key(key_serial_t id,
 	/* pull the payload in if one was supplied */
 	payload = NULL;
 	if (_payload) {
-		ret = -ENOMEM;
-		payload = kmalloc(plen, GFP_KERNEL);
-		if (!payload)
+		payload = memdup_user(_payload, plen);
+		if (IS_ERR(payload)) {
+			ret = PTR_ERR(payload);
 			goto error;
-
-		ret = -EFAULT;
-		if (copy_from_user(payload, _payload, plen) != 0)
-			goto error2;
+		}
 	}
 
 	/* find the target key (which must be writable) */
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2017-05-13  3:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-13  3:15 [PATCH] KEYS: use memdup_user Geliang Tang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).