From: Geliang Tang <geliangtang@gmail.com>
To: Kees Cook <keescook@chromium.org>,
Anton Vorontsov <anton@enomsg.org>,
Colin Cross <ccross@android.com>, Tony Luck <tony.luck@intel.com>
Cc: Geliang Tang <geliangtang@gmail.com>, linux-kernel@vger.kernel.org
Subject: [PATCH] pstore: use memdup_user
Date: Sat, 29 Apr 2017 09:45:16 +0800 [thread overview]
Message-ID: <8f344463f47f40c462ad3b41ef1b0daee1ddf2d2.1493382464.git.geliangtang@gmail.com> (raw)
In-Reply-To: <4db2a0ba17dc68d7bcfbd7d47b0eb22ad9a220c2.1493381463.git.geliangtang@gmail.com>
Use memdup_user() helper instead of open-coding to simplify the code.
Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
fs/pstore/platform.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 43b3ca5..903e0fe 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -640,19 +640,16 @@ static int pstore_write_user_compat(struct pstore_record *record,
if (record->buf)
return -EINVAL;
- record->buf = kmalloc(record->size, GFP_KERNEL);
- if (!record->buf)
- return -ENOMEM;
-
- if (unlikely(copy_from_user(record->buf, buf, record->size))) {
- ret = -EFAULT;
+ record->buf = memdup_user(buf, record->size);
+ if (unlikely(IS_ERR(record->buf))) {
+ ret = PTR_ERR(record->buf);
goto out;
}
ret = record->psi->write(record);
-out:
kfree(record->buf);
+out:
record->buf = NULL;
return unlikely(ret < 0) ? ret : record->size;
--
2.9.3
next prev parent reply other threads:[~2017-04-29 1:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-29 1:45 [PATCH] cciss: use memdup_user Geliang Tang
2017-04-29 1:45 ` [PATCH] floppy: " Geliang Tang
2017-04-29 1:45 ` [PATCH] powerpc/nvram: " Geliang Tang
2017-06-28 0:08 ` Kees Cook
2017-04-29 1:45 ` [PATCH] powerpc/powernv: " Geliang Tang
2017-07-27 12:37 ` Michael Ellerman
2017-04-29 1:45 ` [PATCH] powerpc/pseries: use memdup_user_nul Geliang Tang
2017-07-27 12:37 ` Michael Ellerman
2017-04-29 1:45 ` Geliang Tang [this message]
2017-06-28 0:07 ` [PATCH] pstore: use memdup_user Kees Cook
2017-04-29 1:45 ` [PATCH] skd_main: " Geliang Tang
2017-04-29 1:45 ` [PATCH] staging: comedi: " Geliang Tang
2017-04-29 1:53 ` Joe Perches
2017-04-29 5:17 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8f344463f47f40c462ad3b41ef1b0daee1ddf2d2.1493382464.git.geliangtang@gmail.com \
--to=geliangtang@gmail.com \
--cc=anton@enomsg.org \
--cc=ccross@android.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).