Received: by 10.223.185.116 with SMTP id b49csp115943wrg; Fri, 2 Mar 2018 14:51:01 -0800 (PST) X-Google-Smtp-Source: AG47ELvVY+TEt1OPWDMK4gzqmgGZJj2U8QYVAkrdCLYXXcrVnokceU1Zi1FA9seUPkpo1xKP+iEx X-Received: by 10.101.66.136 with SMTP id j8mr5761763pgp.409.1520031061687; Fri, 02 Mar 2018 14:51:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520031061; cv=none; d=google.com; s=arc-20160816; b=OVEOIInuHa1b+cIoTt4Rkp06P15P339iwOPCG1KX5JeO8YVWlV8clLHO1ydz37c2VV ffOcAUdk0fXTwavCQIaHexFcKgBI0D6ADgY8GWgjIal90K+VolmezdwCWsu/+HHCX9FK 53inQFXdglrYixCN+bNAUEEpBPcyo3wu+JDhILPNuiOmj+DDXgVM6QuUdpx4f3QNJrmo aeBQUUYiQaGafV8JODiZM14vTXMb62h6qSSY/v6IYkSq1aqrbPY8wfHs7soiNt8bgX/H CNuut1KLNeGrU7f1sP6NXHMFEEya7yzAj0EmH0HegG8+iNEZkd5uM/qE/xJS2vyTp0Kk t8Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=QXdxgRBwJFc0sxovBAjw/kwiDb7k7E/8S2zoCviffHk=; b=BmQgDApXPoSzDASz6RbC3owp1jTbL5eAklbtomwYItuJmT0kzTRd1ha9iQxxjiEFlJ +xyDd1s+mlwFKDz7v/hTtdnqIH13X2ijG82FHEg9lzL7tccDOVR63AxPHxVmACwILZQE b+hH3Z1yqTTWDTbedlbPYdbGOCo+/O759o7ck+KfTo8hcI4j5O40FYFwLcjswpMIc660 0gfDq60fDAGQMP9BkSU6qAWEDX/qVnIPrc80cb7FxlSwMzIZ8w8l3XmHxlewNdeTpd4/ vHQmZL7Lar9qLDJ65gHyOTFKJNpUAOBc01H2OPXFBhhcqwGFSuASoMeB8NXxjyFeIAeG UdsQ== 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 h67si4608844pgc.324.2018.03.02.14.50.46; Fri, 02 Mar 2018 14:51:01 -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 S1427900AbeCBMyC (ORCPT + 99 others); Fri, 2 Mar 2018 07:54:02 -0500 Received: from mx2.suse.de ([195.135.220.15]:49847 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423162AbeCBMyB (ORCPT ); Fri, 2 Mar 2018 07:54:01 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 0330EABC8; Fri, 2 Mar 2018 12:54:00 +0000 (UTC) Date: Fri, 2 Mar 2018 13:53:59 +0100 From: Petr Mladek To: Andy Shevchenko Cc: "Tobin C . Harding" , linux@rasmusvillemoes.dk, Joe Perches , linux-kernel@vger.kernel.org, Andrew Morton , Michal Hocko Subject: [PATCH] vsprintf: Make "null" pointer dereference more robust Message-ID: <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180302125118.bjd3tbuu72vgfczo@pathway.suse.cz> User-Agent: NeoMutt/20170421 (1.8.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org %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. 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. -- 2.13.6