Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 304085
b: refs/heads/master
c: e11fea9
h: refs/heads/master
i:
  304083: e7bb096
v: v3
  • Loading branch information
Kay Sievers authored and Greg Kroah-Hartman committed May 8, 2012
1 parent 427704f commit c613a59
Show file tree
Hide file tree
Showing 4 changed files with 317 additions and 61 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7ff9554bb578ba02166071d2d487b7fc7d860d62
refs/heads/master: e11fea92e13fb91c50bacca799a6131c81929986
61 changes: 1 addition & 60 deletions trunk/drivers/char/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,65 +807,6 @@ static const struct file_operations oldmem_fops = {
};
#endif

static ssize_t kmsg_writev(struct kiocb *iocb, const struct iovec *iv,
unsigned long count, loff_t pos)
{
char *buf, *line;
int i;
int level = default_message_loglevel;
int facility = 1; /* LOG_USER */
size_t len = iov_length(iv, count);
ssize_t ret = len;

if (len > 1024)
return -EINVAL;
buf = kmalloc(len+1, GFP_KERNEL);
if (buf == NULL)
return -ENOMEM;

line = buf;
for (i = 0; i < count; i++) {
if (copy_from_user(line, iv[i].iov_base, iv[i].iov_len))
goto out;
line += iv[i].iov_len;
}

/*
* Extract and skip the syslog prefix <[0-9]*>. Coming from userspace
* the decimal value represents 32bit, the lower 3 bit are the log
* level, the rest are the log facility.
*
* If no prefix or no userspace facility is specified, we
* enforce LOG_USER, to be able to reliably distinguish
* kernel-generated messages from userspace-injected ones.
*/
line = buf;
if (line[0] == '<') {
char *endp = NULL;

i = simple_strtoul(line+1, &endp, 10);
if (endp && endp[0] == '>') {
level = i & 7;
if (i >> 3)
facility = i >> 3;
endp++;
len -= endp - line;
line = endp;
}
}
line[len] = '\0';

printk_emit(facility, level, NULL, 0, "%s", line);
out:
kfree(buf);
return ret;
}

static const struct file_operations kmsg_fops = {
.aio_write = kmsg_writev,
.llseek = noop_llseek,
};

static const struct memdev {
const char *name;
umode_t mode;
Expand All @@ -884,7 +825,7 @@ static const struct memdev {
[7] = { "full", 0666, &full_fops, NULL },
[8] = { "random", 0666, &random_fops, NULL },
[9] = { "urandom", 0666, &urandom_fops, NULL },
[11] = { "kmsg", 0, &kmsg_fops, NULL },
[11] = { "kmsg", 0644, &kmsg_fops, NULL },
#ifdef CONFIG_CRASH_DUMP
[12] = { "oldmem", 0, &oldmem_fops, NULL },
#endif
Expand Down
2 changes: 2 additions & 0 deletions trunk/include/linux/printk.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ extern void dump_stack(void) __cold;
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
#endif

extern const struct file_operations kmsg_fops;

enum {
DUMP_PREFIX_NONE,
DUMP_PREFIX_ADDRESS,
Expand Down
Loading

0 comments on commit c613a59

Please sign in to comment.