mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] printk: fix lost last line in kmsg dump
@ 2017-04-19  9:58 Rabin Vincent
  0 siblings, 0 replies; only message in thread
From: Rabin Vincent @ 2017-04-19  9:58 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Rabin Vincent

From: Rabin Vincent <rabinv@axis.com>

kmsg_dump_get_buffer() selects the youngest log messages which fit into
the provided buffer.  When that function determines the correct start
index, by looping and calling msg_print_text() with a NULL buffer, it
allows the youngest log messages to completely fill the provided buffer.

However, when doing the actual printing, an off-by-one error in
msg_print_text() leads to that function allowing the provided buffer to
only be filled to (size - 1).

So if the lengths of the selected youngest log messages happen to
completely fill up the provided buffer, the last log message is lost.

Note that msg_print_text() is also used from the syslog code but this
bug does trigger there since the buffers used in the syslog code are
never filled up completely (since they are only used to print individual
lines, and their size is always LOG_LINE_MAX + PREFIX_MAX, and
PREFIX_MAX is larger than the largest possible prefix).

Signed-off-by: Rabin Vincent <rabinv@axis.com>
---
 kernel/printk/printk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index de08fc9..abac373 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1260,7 +1260,7 @@ static size_t msg_print_text(const struct printk_log *msg, enum log_flags prev,
 
 		if (buf) {
 			if (print_prefix(msg, syslog, NULL) +
-			    text_len + 1 >= size - len)
+			    text_len + 1 > size - len)
 				break;
 
 			if (prefix)
-- 
2.7.0

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-04-19  9:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-19  9:58 [PATCH] printk: fix lost last line in kmsg dump Rabin Vincent

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome