Messages in this thread Patch in this message |  | | | From | Yuanhan Liu <> | | Subject | [PATCH 2/2] printk: return -EINVAL if the message len is bigger than the buf size | | Date | Sat, 16 Jun 2012 12:40:55 +0800 |
| |
Just like what devkmsg_read() does, return -EINVAL if the message len is bigger than the buf size, or it will trigger a segfault error.
Cc: Kay Sievers <kay@vrfy.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com> --- kernel/printk.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/kernel/printk.c b/kernel/printk.c index d2ddb83..734e2a4 100644 --- a/kernel/printk.c +++ b/kernel/printk.c @@ -879,7 +879,9 @@ static int syslog_print(char __user *buf, int size) syslog_seq++; raw_spin_unlock_irq(&logbuf_lock); - if (len > 0 && copy_to_user(buf, text, len)) + if (len > size) + len = -EINVAL; + else if (len > 0 && copy_to_user(buf, text, len)) len = -EFAULT; kfree(text); -- 1.7.3.1
|  |