Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753186AbdHJQzv (ORCPT ); Thu, 10 Aug 2017 12:55:51 -0400 Received: from mail-ua0-f195.google.com ([209.85.217.195]:34679 "EHLO mail-ua0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752283AbdHJQzu (ORCPT ); Thu, 10 Aug 2017 12:55:50 -0400 MIME-Version: 1.0 In-Reply-To: References: <1501421870-12042-1-git-send-email-vichy.kuo@gmail.com> <20170801024303.GA469@jagdpanzerIV.localdomain> From: pierre kuo Date: Fri, 11 Aug 2017 00:55:48 +0800 Message-ID: Subject: Re: [RFC V2] printk: add warning while drop partial text in msg To: Sergey Senozhatsky Cc: Petr Mladek , Sergey Senozhatsky , rostedt@goodmis.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3063 Lines: 69 hi Sergey: (Please ignore previous mail, I apologize for pressing send button too early :) >> this is not the only place that can truncate the message. >> vprintk_emit() can do so as well /* vscnprintf() */. but >> I think we don't care that much. a user likely will notice >> truncated messages. we report lost messages, because this >> is a completely different sort of problem. Usually people will more easily find message truncated from semantics by vscnprintf, since it brute force truncate input message by the upper limit of output buffer. In msg_print_text, it use memchr to find "\n" as copying unit while memcping msg->text to output buffer. And people will be hard to find out some part of message is left behind. (since the tail of original message is elegantly dropped by "\n") That is the reason I try to add such warning in msg_print_text. > your log_store(), invoked from msg_print_text(), will append the error > message to the logbuf (tail), possibly far-far-far away from console_idx. > so your "characters dropped" warning will appear much later. Got ur point and thanks for your advising. >> len += print_prefix(msg, syslog, buf + len); >> memcpy(buf + len, text, text_len); > > > but more importantly, msg_print_text() is called from several places. and > can even be called from a user space, potentially triggering the same > "" error log_store() over and over again, wiping out > the actually important kernel messages. which is > a) not nice > and > b) can be used to deliberately "hide" something really important. > how about we directly adding warning message in buffer instead of log_store like below? Appreciate your review and advising. diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index fc47863..fcd1dd4 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -557,6 +557,7 @@ static u32 msg_used_size(u16 text_len, u16 dict_len, u32 *pad_len) */ #define MAX_LOG_TAKE_PART 4 static const char trunc_msg[] = ""; +static const char drop_msg[] = ""; static u32 truncate_msg(u16 *text_len, u16 *trunc_msg_len, u16 *dict_len, u32 *pad_len) @@ -1264,8 +1265,14 @@ static size_t msg_print_text(const struct printk_log *msg, bool syslog, char *bu if (buf) { if (print_prefix(msg, syslog, NULL) + - text_len + 1 >= size - len) + text_len + 1 >= size - len) { + /* below adding warning message + * related information into output buffer + */ + if ((size - len) > strlen(drop_msg)) + memcpy(buf + len, drop_msg, strlen(drop_msg)); break; + } len += print_prefix(msg, syslog, buf + len); memcpy(buf + len, text, text_len);