From: Tejun Heo <htejun@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Randy Dunlap <randy.dunlap@oracle.com>,
Linux Kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] printk: implement printk_buf overflow warning
Date: Wed, 13 Feb 2008 18:03:12 +0900 [thread overview]
Message-ID: <47B2B250.8020209@gmail.com> (raw)
printk silently truncates messages longer than 1024 - 1 bytes.
Implement overflow detection and append "$PRINTK_BUF_OVERFLOW$\n" to
truncated messages.
Signed-off-by: Tejun Heo <htejun@gmail.com>
---
kernel/printk.c | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/kernel/printk.c b/kernel/printk.c
index 074a3ea..419cd47 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -42,6 +42,7 @@ void __attribute__((weak)) early_printk(const char *fmt, ...)
{
}
+#define PRINTK_BUF_LEN 1024
#define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)
/* printk's without a loglevel use this.. */
@@ -619,9 +620,10 @@ asmlinkage int vprintk(const char *fmt, va_list args)
static volatile unsigned int printk_cpu = UINT_MAX;
static const char printk_recursion_bug_msg [] =
KERN_CRIT "BUG: recent printk recursion!\n";
+ static const char overflow_tag[] = "$PRINTK_BUF_OVERFLOW$\n";
static int printk_recursion_bug;
static int log_level_unknown = 1;
- static char printk_buf[1024];
+ static char printk_buf[PRINTK_BUF_LEN + sizeof(overflow_tag) - 1];
unsigned long flags;
int printed_len = 0;
@@ -663,8 +665,15 @@ asmlinkage int vprintk(const char *fmt, va_list args)
printed_len = sizeof(printk_recursion_bug_msg);
}
/* Emit the output into the temporary buffer */
- printed_len += vscnprintf(printk_buf + printed_len,
- sizeof(printk_buf) - printed_len, fmt, args);
+ printed_len += vsnprintf(printk_buf + printed_len,
+ PRINTK_BUF_LEN - printed_len, fmt, args);
+
+ /* Check for overflow and tag the message if overflowed */
+ if (printed_len >= PRINTK_BUF_LEN) {
+ memcpy(printk_buf + PRINTK_BUF_LEN - 1, overflow_tag,
+ sizeof(overflow_tag));
+ printed_len = sizeof(printk_buf) - 1;
+ }
/*
* Copy the output into log_buf. If the caller didn't provide
--
1.5.2.4
next reply other threads:[~2008-02-13 9:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-13 9:03 Tejun Heo [this message]
2008-02-13 23:59 ` [PATCH] printk: implement printk_buf overflow warning Andrew Morton
2008-02-14 0:14 ` 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=47B2B250.8020209@gmail.com \
--to=htejun@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--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.