public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KEYS: use memdup_user
@ 2017-05-13  3:15 Geliang Tang
  2017-05-13  3:15 ` [PATCH] mmc: block: " Geliang Tang
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Geliang Tang @ 2017-05-13  3:15 UTC (permalink / raw)
  To: David Howells, James Morris, Serge E. Hallyn
  Cc: Geliang Tang, keyrings, linux-security-module, linux-kernel

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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-05-21  3:26 UTC | newest]

Thread overview: 9+ messages (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
2017-05-13  3:15 ` [PATCH] mmc: block: " Geliang Tang
2017-05-19  7:43   ` Ulf Hansson
2017-05-13  3:15 ` [PATCH] usb: gadget: f_fs: " Geliang Tang
2017-05-13  8:05   ` Dan Carpenter
2017-05-21  3:25     ` Al Viro
2017-05-14 11:33   ` Michal Nazarewicz
2017-05-13  3:16 ` [PATCH] USB: iowarrior: " Geliang Tang
2017-05-15 10:14   ` Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox