[PATCH] KEYS: use memdup_user

Geliang Tang geliangtang at gmail.com
Sat May 13 03:15:57 UTC 2017


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

Signed-off-by: Geliang Tang <geliangtang at 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



More information about the Linux-security-module-archive mailing list