Commit 7e5b58bc authored by Kay Sievers's avatar Kay Sievers Committed by Greg Kroah-Hartman

printk: /dev/kmsg - properly support writev() to avoid interleaved printk() lines

printk: /dev/kmsg - properly support writev() to avoid interleaved printk lines

We should avoid calling printk() in a loop, when we pass a single
string to /dev/kmsg with writev().

Cc: Lennart Poettering <lennart@poettering.net>
Signed-off-by: default avatarKay Sievers <kay.sievers@vrfy.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 47296b19
...@@ -806,29 +806,40 @@ static const struct file_operations oldmem_fops = { ...@@ -806,29 +806,40 @@ static const struct file_operations oldmem_fops = {
}; };
#endif #endif
static ssize_t kmsg_write(struct file *file, const char __user *buf, static ssize_t kmsg_writev(struct kiocb *iocb, const struct iovec *iv,
size_t count, loff_t *ppos) unsigned long count, loff_t pos)
{ {
char *tmp; char *line, *p;
ssize_t ret; int len, i;
ssize_t ret = -EFAULT;
tmp = kmalloc(count + 1, GFP_KERNEL); len = iov_length(iv, count);
if (tmp == NULL) line = p = kmalloc(len + 1, GFP_KERNEL);
if (line == NULL)
return -ENOMEM; return -ENOMEM;
ret = -EFAULT;
if (!copy_from_user(tmp, buf, count)) { /*
tmp[count] = 0; * copy all vectors into a single string, to ensure we do
ret = printk("%s", tmp); * not interleave our log line with other printk calls
if (ret > count) */
/* printk can add a prefix */ for (i = 0; i < count; i++) {
ret = count; if (copy_from_user(p, iv[i].iov_base, iv[i].iov_len))
goto out;
p += iv[i].iov_len;
} }
kfree(tmp); p[0] = '\0';
ret = printk("%s", line);
/* printk can add a prefix */
if (ret > len)
ret = len;
out:
kfree(line);
return ret; return ret;
} }
static const struct file_operations kmsg_fops = { static const struct file_operations kmsg_fops = {
.write = kmsg_write, .aio_write = kmsg_writev,
.llseek = noop_llseek, .llseek = noop_llseek,
}; };
......
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