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>
This commit is contained in:
Geliang Tang 2017-04-29 09:45:16 +08:00 committed by Kees Cook
parent d3762358a7
commit 077090af33
1 changed files with 4 additions and 7 deletions

View File

@ -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;