Commit 30800d99 authored by Kees Cook's avatar Kees Cook

pstore: simplify write_user_compat()

Nothing actually uses write_user_compat() currently, but there is no
reason to reuse the dmesg buffer. Instead, just allocate a new record
buffer, copy in from userspace, and pass it to write() as normal.
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
parent 4c9ec219
...@@ -635,33 +635,27 @@ static void pstore_unregister_console(void) {} ...@@ -635,33 +635,27 @@ static void pstore_unregister_console(void) {}
static int pstore_write_user_compat(struct pstore_record *record, static int pstore_write_user_compat(struct pstore_record *record,
const char __user *buf) const char __user *buf)
{ {
unsigned long flags = 0; int ret = 0;
size_t i, bufsize, total_size = record->size;
long ret = 0; if (record->buf)
return -EINVAL;
if (unlikely(!access_ok(VERIFY_READ, buf, total_size)))
return -EFAULT; record->buf = kmalloc(record->size, GFP_KERNEL);
bufsize = total_size; if (!record->buf)
if (bufsize > psinfo->bufsize) return -ENOMEM;
bufsize = psinfo->bufsize;
record->buf = psinfo->buf; if (unlikely(copy_from_user(record->buf, buf, record->size))) {
spin_lock_irqsave(&psinfo->buf_lock, flags); ret = -EFAULT;
for (i = 0; i < total_size; ) { goto out;
size_t c = min(total_size - i, bufsize);
ret = __copy_from_user(record->buf, buf + i, c);
if (unlikely(ret != 0)) {
ret = -EFAULT;
break;
}
record->size = c;
ret = record->psi->write(record);
if (unlikely(ret < 0))
break;
i += c;
} }
spin_unlock_irqrestore(&psinfo->buf_lock, flags);
return unlikely(ret < 0) ? ret : total_size; ret = record->psi->write(record);
out:
kfree(record->buf);
record->buf = NULL;
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