public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
To: linux-kernel@vger.kernel.org
Cc: wfg@linux.intel.com, Yuanhan Liu <yuanhan.liu@linux.intel.com>,
	Kay Sievers <kay@vrfy.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
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	[thread overview]
Message-ID: <1339821655-14059-2-git-send-email-yuanhan.liu@linux.intel.com> (raw)
In-Reply-To: <1339821655-14059-1-git-send-email-yuanhan.liu@linux.intel.com>

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


  reply	other threads:[~2012-06-16  4:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-16  4:40 [PATCH 1/2] printk: use logbuf_mutex_lock to stop syslog_seq from going wild Yuanhan Liu
2012-06-16  4:40 ` Yuanhan Liu [this message]
2012-06-16 12:50   ` [PATCH 2/2] printk: return -EINVAL if the message len is bigger than the buf size Kay Sievers
2012-06-16 13:21     ` Fengguang Wu
2012-06-16 12:42 ` [PATCH 1/2] printk: use logbuf_mutex_lock to stop syslog_seq from going wild Kay Sievers
2012-06-16 12:59   ` Yuanhan Liu
2012-06-16 13:03     ` Kay Sievers
2012-06-16 13:25       ` Yuanhan Liu
2012-06-16 13:20     ` Fengguang Wu
2012-06-16 13:28       ` Yuanhan Liu
2012-06-16 15:28         ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1339821655-14059-2-git-send-email-yuanhan.liu@linux.intel.com \
    --to=yuanhan.liu@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kay@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wfg@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox