diff options
author | Geliang Tang <geliangtang@gmail.com> | 2017-04-29 09:45:16 +0800 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2017-06-27 17:02:36 -0700 |
commit | 077090af337f7d833f82be3d556549512398de66 (patch) | |
tree | e2573b974aedaa99bda80a07181050a95d7b3b9f /fs/pstore | |
parent | d3762358a739e7ef63873d6923938def99affa93 (diff) | |
download | op-kernel-dev-077090af337f7d833f82be3d556549512398de66.zip op-kernel-dev-077090af337f7d833f82be3d556549512398de66.tar.gz |
pstore: use memdup_user
Use memdup_user() helper instead of open-coding to simplify the code.
Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'fs/pstore')
-rw-r--r-- | fs/pstore/platform.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 96fbff7..1b6e0ff 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -653,19 +653,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; |