Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762038AbdDSJ6Q (ORCPT ); Wed, 19 Apr 2017 05:58:16 -0400 Received: from bastet.se.axis.com ([195.60.68.11]:50582 "EHLO bastet.se.axis.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761732AbdDSJ6N (ORCPT ); Wed, 19 Apr 2017 05:58:13 -0400 From: Rabin Vincent To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, Rabin Vincent Subject: [PATCH] printk: fix lost last line in kmsg dump Date: Wed, 19 Apr 2017 11:58:09 +0200 Message-Id: <1492595889-25222-1-git-send-email-rabin.vincent@axis.com> X-Mailer: git-send-email 2.7.0 X-TM-AS-GCONF: 00 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1511 Lines: 40 From: Rabin Vincent 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 --- 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