From: Tejun Heo <htejun@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
Ingo Molnar <mingo@elte.hu>,
Randy Dunlap <randy.dunlap@oracle.com>
Cc: Linux Kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH REPOST] printk: fix possible printk buffer overrun introduced with recursion check
Date: Wed, 13 Feb 2008 17:46:52 +0900 [thread overview]
Message-ID: <47B2AE7C.608@gmail.com> (raw)
printk recursion detection prepends message to printk_buf and offsets
printk_buf when actual message is printed but it forgets to trim
buffer length accordingly. This can result in buffer overrun in
extreme cases.
While at it, make printk_recursion_bug_msg static and move static
variables for recursion check into vprintk().
Signed-off-by: Tejun Heo <htejun@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
---
Eeeek, forgot to cc lkml last time. Re-sending. Sorry about the
noise.
kernel/printk.c | 14 ++++++--------
1 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/kernel/printk.c b/kernel/printk.c
index bee3610..074a3ea 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -613,15 +613,13 @@ asmlinkage int printk(const char *fmt, ...)
return r;
}
-/* cpu currently holding logbuf_lock */
-static volatile unsigned int printk_cpu = UINT_MAX;
-
-const char printk_recursion_bug_msg [] =
- KERN_CRIT "BUG: recent printk recursion!\n";
-static int printk_recursion_bug;
-
asmlinkage int vprintk(const char *fmt, va_list args)
{
+ /* cpu currently holding logbuf_lock */
+ static volatile unsigned int printk_cpu = UINT_MAX;
+ static const char printk_recursion_bug_msg [] =
+ KERN_CRIT "BUG: recent printk recursion!\n";
+ static int printk_recursion_bug;
static int log_level_unknown = 1;
static char printk_buf[1024];
@@ -666,7 +664,7 @@ asmlinkage int vprintk(const char *fmt, va_list args)
}
/* Emit the output into the temporary buffer */
printed_len += vscnprintf(printk_buf + printed_len,
- sizeof(printk_buf), fmt, args);
+ sizeof(printk_buf) - printed_len, fmt, args);
/*
* Copy the output into log_buf. If the caller didn't provide
--
1.5.2.4
next reply other threads:[~2008-02-13 8:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-13 8:46 Tejun Heo [this message]
2008-02-13 12:45 ` [PATCH REPOST] printk: fix possible printk buffer overrun introduced with recursion check Ingo Molnar
2008-02-14 0:11 ` Tejun Heo
2008-02-14 1:32 ` [PATCH UPDATED] " Tejun Heo
2008-02-14 1:39 ` [PATCH] printk: clean up recursion check related static variables Tejun Heo
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=47B2AE7C.608@gmail.com \
--to=htejun@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=randy.dunlap@oracle.com \
--cc=torvalds@linux-foundation.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.