Commit 077090af authored by Geliang Tang's avatar Geliang Tang Committed by Kees Cook

pstore: use memdup_user

Use memdup_user() helper instead of open-coding to simplify the code.
Signed-off-by: default avatarGeliang Tang <geliangtang@gmail.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
parent d3762358
...@@ -653,19 +653,16 @@ static int pstore_write_user_compat(struct pstore_record *record, ...@@ -653,19 +653,16 @@ static int pstore_write_user_compat(struct pstore_record *record,
if (record->buf) if (record->buf)
return -EINVAL; return -EINVAL;
record->buf = kmalloc(record->size, GFP_KERNEL); record->buf = memdup_user(buf, record->size);
if (!record->buf) if (unlikely(IS_ERR(record->buf))) {
return -ENOMEM; ret = PTR_ERR(record->buf);
if (unlikely(copy_from_user(record->buf, buf, record->size))) {
ret = -EFAULT;
goto out; goto out;
} }
ret = record->psi->write(record); ret = record->psi->write(record);
out:
kfree(record->buf); kfree(record->buf);
out:
record->buf = NULL; record->buf = NULL;
return unlikely(ret < 0) ? ret : record->size; return unlikely(ret < 0) ? ret : record->size;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment