Received: by 10.223.185.116 with SMTP id b49csp5032152wrg; Wed, 7 Mar 2018 05:23:55 -0800 (PST) X-Google-Smtp-Source: AG47ELtSr6iIMiLybLl/nOspDZBH2/srZu/2tKnMewG04yb4eVgw/eScKIZVCUoK99FjTClRh8IM X-Received: by 2002:a17:902:7088:: with SMTP id z8-v6mr21048460plk.174.1520429035530; Wed, 07 Mar 2018 05:23:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520429035; cv=none; d=google.com; s=arc-20160816; b=U4cx/h1Iz7dhdbZMr6d2stjuOP9merAvg9SrbXn22prgO1s+iyNaRgbST04QEYmlEu M9gOeDrbORc6SumG2QbjaQDp3SoJUYvYlrQp2GnFbcWXrmApu0PCYvFCMs1Vs4smmnMQ M05TMyOz4zSjgaWhE6JV2YEgf3DEdMjYQYhv7lV3gZ/yVqPms8M8FsmNcpse1aKTMB9d ZeHWY+XFVAIojXFk3KvTnBqx+1tXJp/dJZ+AO/7bhP0AC+M2/FLZnIGDqFqIO6F1B4w3 m25+5JpU6A7FSA7En1o4e06Q7qtogOlieJcZ/+TZrHlNzDsIsnNum6JTvnhd90LDZRds SkdA== 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:to:from:subject:message-id :arc-authentication-results; bh=gNfYPqdgO+J2h3riT6XqLrja4UNI368jDQkSW0oj5HU=; b=hsssntLUGY0qt3bq0lH2sqNxQKq2azZVuPzDqelYeUB1ZtFJmeZ0a8Uc9M5VTWO3dC oCDZIauq1/ENrurEJdBULRPpXhQka0KJZClZ0bCLJLZz2iBAXwACgjY4r3d9HB3Kzco9 cwlWr1dFQCbt1Tpf8bRTiJo/HXiYW2eD7E8o2iAlRYQHv2cBRgWzT96UUFtIjSWdEqhk BJ2/HkbQ/6HLWC3B1NAejzSkeTC4q+56IAI5Z/6F5t9bGl4PWIldngp1DXnIBbvdS0yq hbL1KWpWpkVssOCBRarnzXME81IpfwybLrCg+Mx+Jyo4xTPXFdtmqOlgsUGsdxlFsAY/ jpgQ== 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 h1si12727795pfn.266.2018.03.07.05.23.41; Wed, 07 Mar 2018 05:23:55 -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 S933355AbeCGNWa (ORCPT + 99 others); Wed, 7 Mar 2018 08:22:30 -0500 Received: from mga07.intel.com ([134.134.136.100]:43105 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754545AbeCGNWZ (ORCPT ); Wed, 7 Mar 2018 08:22:25 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Mar 2018 05:22:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,435,1515484800"; d="scan'208";a="39930073" Received: from smile.fi.intel.com (HELO smile) ([10.237.72.86]) by orsmga002.jf.intel.com with ESMTP; 07 Mar 2018 05:22:22 -0800 Message-ID: <1520428941.10722.466.camel@linux.intel.com> Subject: Re: [PATCH 2/2] vsprintf: don't dereference pointers to the first or last page From: Andy Shevchenko To: Adam Borowski , Petr Mladek , Rasmus Villemoes , "Tobin C . Harding" , Joe Perches , linux-kernel@vger.kernel.org, Andrew Morton , Michal Hocko Date: Wed, 07 Mar 2018 15:22:21 +0200 In-Reply-To: <20180306181122.11449-2-kilobyte@angband.pl> References: <20180306092513.ibodfsnv4xrxdlub@pathway.suse.cz> <20180306181122.11449-1-kilobyte@angband.pl> <20180306181122.11449-2-kilobyte@angband.pl> 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 Tue, 2018-03-06 at 19:11 +0100, Adam Borowski wrote: > As old code to avoid so is inconsistent, let's unify it within a > single > macro. > > > +#define IS_BAD_PTR(x) ((unsigned long)(x) >= (unsigned long)- > PAGE_SIZE \ > + || (unsigned long)(x) < PAGE_SIZE) Oh, no. First of all, why it's a macro? Next, what prevents us to do it in place using IS_ERR() instead? (Btw, I have a patch for that, not published yet) > #define BAD_PTR_STRING(x) (!(x) ? "(null)" : IS_ERR(x) ? "(err)" : > "(invalid)") > > /** > @@ -589,7 +591,7 @@ char *string(char *buf, char *end, const char *s, > struct printf_spec spec) > int len = 0; > size_t lim = spec.precision; > > - if ((unsigned long)s < PAGE_SIZE) > + if (IS_BAD_PTR(s)) > s = BAD_PTR_STRING(s); I don't think it's a good idea to change current behaviour. > @@ -1583,7 +1585,7 @@ char *device_node_string(char *buf, char *end, > struct device_node *dn, > if (!IS_ENABLED(CONFIG_OF)) > return string(buf, end, "(!OF)", spec); > > - if ((unsigned long)dn < PAGE_SIZE) > + if (IS_BAD_PTR(dn)) > return string(buf, end, BAD_PTR_STRING(dn), spec); This makes no sense. Explained in comment against patch 1. > > /* simple case without anything any more format specifiers */ > @@ -1851,7 +1853,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 (IS_BAD_PTR(ptr) && *fmt != 'K' && *fmt != 'x') { > /* > * Print (null)/etc with the same width as a pointer > so it > * makes tabular output look nice. > -- Andy Shevchenko Intel Finland Oy