Received: by 10.223.185.116 with SMTP id b49csp2695464wrg; Mon, 5 Mar 2018 07:18:00 -0800 (PST) X-Google-Smtp-Source: AG47ELtMtRZXbJcoKFr53FAIKRnhQWPcdHxnPTXE7iu0ysqpansxYNAAzyPOwN7/ij8C3/EtSlwC X-Received: by 10.99.96.199 with SMTP id u190mr12469909pgb.231.1520263079895; Mon, 05 Mar 2018 07:17:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520263079; cv=none; d=google.com; s=arc-20160816; b=mLyBwvSSkE9e/pneOoUi6lN3Yb4IX5NgtVIxyxkKsRoC88DbdHUzBTBpgrQ4grFPU4 6N0pHAeX5vcMoPB4Ff2W/4uI2mZMJzcHJ/9uo3ROFglOdi45x8c1lKuhdCgTdkC8QPWA ODPSKE7wnfHiys3DE0XLDnJqT3+NJlO/JSfGmcYWNSzW+hXoBc4BNwt4rAGnVgdKvVnE ZcyOwOBzsbFxqXntL83jxgbqHCl9JvWK/Vz5XLL9DSVFFIQ22orrmfE29bvMdurUUQGC b+v/Lt2RkNh7FSl5t7v5hvfaHluSG4sj+BiohFehmmo71+eZME0B2nOBZgjL5BngcmVs cVDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=bhjrbPyTBt6l8uPXHJuARXj+gKoPLiHwyGRFm4JRxxQ=; b=KGU6i0B7ilygmHp250IWG2y2m68qpL24LRiOuorugKB02mW298Kvfdgv6aYazz8hBx ZMj0V0bbvZThCWBhKV3IxCyawov9rWziOSNtj3ngy+n9DrgdJcCTO9SYEmdacMSCGJIp 5IJjrYKGnyP2kA6L3sCxCe0XUFPMdaVFaHSERT1K9nxoaQkmbXp0egxExFCjtKobRLmo PsCCzJcE0NBYgua2v/Ya+vRXE1bBLDBPll7QAsFgJnaj+XLUPfSm6k62w+1pZfIXVcYm ez5f/Ab2tbq64pe8YcHm32PBX3C6FxHSGAthjBdKtTCdK7UbVh6QfIgLHsoxLWqPEo4/ K7ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=JYzFwJil; 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 j63si8429823pgd.731.2018.03.05.07.17.46; Mon, 05 Mar 2018 07:17:59 -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; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=JYzFwJil; 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 S932069AbeCEPQj (ORCPT + 99 others); Mon, 5 Mar 2018 10:16:39 -0500 Received: from mail-io0-f194.google.com ([209.85.223.194]:42060 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751311AbeCEPQi (ORCPT ); Mon, 5 Mar 2018 10:16:38 -0500 Received: by mail-io0-f194.google.com with SMTP id u84so18319395iod.9 for ; Mon, 05 Mar 2018 07:16:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=bhjrbPyTBt6l8uPXHJuARXj+gKoPLiHwyGRFm4JRxxQ=; b=JYzFwJilSavfzZ655IXCmA+uKSmQJSJDNyifEVDz0hsXzBx+kU4thEcuOXYTtaypvZ Ls9f7jgmdscBV8V65RLxyJ9AYLX26OoB+GKLjn9Bd+lCv5KWid55aNhFvBnrphJSDZxo nzh712i/I3Kql6i6kAN02Vq/bS5zUnzacCgKI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=bhjrbPyTBt6l8uPXHJuARXj+gKoPLiHwyGRFm4JRxxQ=; b=hiooidI6e0Ws34PmLserlTqTAJ7gT/RRjK9M3DIrAf4Sj/1N/qQcHnG0pgvwXYmSfO 4R5CAfYveaSJnQZCf3gMtRXOd8y2w4KR/T/tX6Rl9ybMn927QAkRW7VGr7VNfodoAz8/ ckDuAfpeXreN5jsgto0bYTpLIzzvjBM2f8jful2uyE2Kr2nTlmZnwObz8bgJMbwCpHHl I6NsFVW9mnmvdJyg3eEipoxwkGwivs5UwikffVRJKq11oMfhHxZpvZb+EFkbVyDQxcXW LQ/KXuPIaRKIcM0OavK7+jS8Hu35or8CNjN95Ry2/4tYrpixmQwKX0X37E8RbR4H+86Q f8Jg== X-Gm-Message-State: APf1xPDbqsOzU9m+5WH3BDHhLuMBO9kGsNkUhCYbt6QU3XsP5JgK2Bco jnAtb7K3h6VlZwE6ZGGq02/VZk1FhEXbcJgjxdOpTF2R X-Received: by 10.107.164.3 with SMTP id n3mr16021849ioe.88.1520262997636; Mon, 05 Mar 2018 07:16:37 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.146.65 with HTTP; Mon, 5 Mar 2018 07:16:37 -0800 (PST) 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> From: Rasmus Villemoes Date: Mon, 5 Mar 2018 16:16:37 +0100 Message-ID: Subject: Re: [PATCH] vsprintf: Make "null" pointer dereference more robust To: Petr Mladek Cc: Andy Shevchenko , "Tobin C . Harding" , Joe Perches , linux-kernel@vger.kernel.org, Andrew Morton , Michal Hocko Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2 March 2018 at 13:53, 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. Yeah, it's annoying that we can't reliably WARN for bogus vsprintf() uses. > 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') { ISTM that accidentally passing an ERR_PTR would be just as likely as passing a NULL pointer (or some small offset from one), so if we do this, shouldn't the test also cover IS_ERR values? Rasmus