Received: by 10.223.185.116 with SMTP id b49csp130136wrg; Fri, 2 Mar 2018 15:10:10 -0800 (PST) X-Google-Smtp-Source: AG47ELvy6Paosf0Cuj+rMa78nq+PblsBDUuQHshzzxsW3zLnGeWKKTF2hV+CNUQ1N5GOzJRPpjOf X-Received: by 2002:a17:902:2ec1:: with SMTP id r59-v6mr6458328plb.416.1520032210613; Fri, 02 Mar 2018 15:10:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520032210; cv=none; d=google.com; s=arc-20160816; b=YKQ7Z1Zl+Hv0O2FT21L33eoXII1n9FEXsN4JuX3kSfj6M5jXLt/GgknOeRR4+MN3c3 vtJw8W2t9Zea9B3TnQcLl+5h6rlYpyIpBbG3VYAYoJLns53ChhmHhbcpBxPP0QEfX//o kSzykfAA6B47KsusoR3M0pKMH2Cvm6cACeyadRP7XODAkw2ByjGcz/lLyEfLg0N2W1NH OQhgL6FHFAvbtHejJjT9J1teA1YFbWZz6K4T/ajh72RULQMCvhBj7I1SLtVVo7si9ZrX GKlLOYXbGVn6ERFuPjBdUqwKNCF4zLZdaAojfY9IaqZ3bLd6mf97ZJtCN4NjQdGGOozg Qh+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:date:cc:to:from:subject :message-id:arc-authentication-results; bh=asuhW57YxWQVAPU6zFmtBT51YNmVe7gDKd23J2x8r/Y=; b=rh+whvQOKw/qrvfpkOyIx2ac9YdzHJcq14aa+HsFHhMxWSRAUU1kjlMR/ZsvmH/bL5 IlwDeHWxdxH/xGTDTkTf80Dd702ViCj6E11sn+yIvznkqfd1J9d3Lj0PtJuuVjWjp0r2 uRkSlPzW/8NjT9ghl/HAyI5RMemfAmtuTUcuBaYBYz5sFkhPPZCkTvxkb3GILB5rbx2o XhDI0zEAKRzo8SXGlZYh4ZvlCMUNxjxP3mtAa3LJlVhgE7ksi1Pvw+nXClpDdF4TC/aJ eMiK9TrLtYd03hyQQ/j8Qm6ouR8R2vG/3CZcGUWuIZ3dNfTF5Fa9VeR0I5mrGCKS1M0Y Ox1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d8si819552pgc.553.2018.03.02.15.09.56; Fri, 02 Mar 2018 15:10:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1428580AbeCBORo (ORCPT + 99 others); Fri, 2 Mar 2018 09:17:44 -0500 Received: from mga12.intel.com ([192.55.52.136]:49737 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1428567AbeCBORi (ORCPT ); Fri, 2 Mar 2018 09:17:38 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Mar 2018 06:17:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,412,1515484800"; d="scan'208";a="22338715" Received: from smile.fi.intel.com (HELO smile) ([10.237.72.86]) by orsmga006.jf.intel.com with ESMTP; 02 Mar 2018 06:17:34 -0800 Message-ID: <1520000254.10722.389.camel@linux.intel.com> Subject: Re: [PATCH] vsprintf: Make "null" pointer dereference more robust From: Andy Shevchenko To: Petr Mladek Cc: "Tobin C . Harding" , linux@rasmusvillemoes.dk, Joe Perches , linux-kernel@vger.kernel.org, Andrew Morton , Michal Hocko Date: Fri, 02 Mar 2018 16:17:34 +0200 In-Reply-To: <20180302125359.szbin2kznxvoq7sc@pathway.suse.cz> References: <20180216210711.79901-1-andriy.shevchenko@linux.intel.com> <20180216210711.79901-8-andriy.shevchenko@linux.intel.com> <20180227155047.o74ohmoyj56up6pa@pathway.suse.cz> <1519752950.10722.231.camel@linux.intel.com> <20180228100437.o4juwxbzomkqjvjx@pathway.suse.cz> <1519814544.10722.266.camel@linux.intel.com> <20180302125118.bjd3tbuu72vgfczo@pathway.suse.cz> <20180302125359.szbin2kznxvoq7sc@pathway.suse.cz> Organization: Intel Finland Oy Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.5-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2018-03-02 at 13:53 +0100, Petr Mladek wrote: > %p has many modifiers where the pointer is dereferenced. An invalid > pointer might cause kernel to crash silently. > > Note that printk() formats the string under logbuf_lock. Any recursive > printks are redirected to the printk_safe implementation and the > messages > are stored into per-CPU buffers. These buffers might be eventually > flushed > in printk_safe_flush_on_panic() but it is not guaranteed. > > In general, we should do our best to get useful message from printk(). > All pointers to the first memory page must be invalid. Let's prevent > the dereference and print "(null)" in this case. This is already done > in many other situations, including "%s" format handling and many > page fault handlers. > With such explanation it makes at least clear for the reader why it's done. Thanks! Would you be okay if I take this one as a first in my series and resubmit the series based on it? > Signed-off-by: Petr Mladek > --- > lib/vsprintf.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index d7a708f82559..5c2d1f44218a 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -1849,7 +1849,7 @@ char *pointer(const char *fmt, char *buf, char > *end, void *ptr, > { > const int default_width = 2 * sizeof(void *); > > - if (!ptr && *fmt != 'K' && *fmt != 'x') { > + if ((unsigned long)ptr < PAGE_SIZE && *fmt != 'K' && *fmt != > 'x') { > /* > * Print (null) with the same width as a pointer so > it makes > * tabular output look nice. -- Andy Shevchenko Intel Finland Oy