Received: by 10.223.185.116 with SMTP id b49csp5027331wrg; Wed, 7 Mar 2018 05:18:39 -0800 (PST) X-Google-Smtp-Source: AG47ELv3r5/tooNid+ir2Au2zZ+09XuvbrXN3Wwdp8g7SOFeX74gvLrm9sFJge5/5Glyl/WDZtb2 X-Received: by 10.99.49.208 with SMTP id x199mr16904262pgx.424.1520428719328; Wed, 07 Mar 2018 05:18:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520428719; cv=none; d=google.com; s=arc-20160816; b=fZupzDE3cYKMQ8Ei5ax+q9QmOC3O5wiMXWYkr4xVMDJiDhvpVT1SlaQL2vGTufaEOe a/L17tzVJ5eEiLAHh5Oz2aT5E8FgNXrjFc+4+0i5GZvpzdsWazJlb/sci8MMuTMNvCS9 0Wc7IlEAkmyS5UWtDQcJ/rfvUBQbTvkFCoU7lPD/912feUcp+GR/LVcVdBcRpQRRPidH XF55xAo3BxuQHGzVlmU/zKJrQtF1nxY04J3qeaFNtqZO8Awhm2uJ/E/mWlr8SLjD7NdD 1Om6bULhWWZJlct1V8r/S/dmYwmM0JNFd049Z+dUlvmT6dGEO9IQGBFsWiKISQQTH6pd F14w== 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=K6JhKoJ4I7aDZOhZHkTfsoHxlNddxYIj2ci9rLL5ys0=; b=Ptxs4fctoudaFliRJKOvwzhy7nZn1mOQ6w7i8EJW3jRvGmran8ywqSOPIRFLL1R29o JQiFknrkpgU4btSHlbbAoWPfsg1Nn27A+r6/zkNMefvCzmH9594eE6dvu8EGjqmFQDUt kCsguCCk2TlqED0wyZfIIDHvgszT8EmHWLhoneW8zv0Ov3i0Fq6tf4UORkbvCS4aeWI3 BlAs7zITn2RkHhFI/XWiVzRFsAHaQzN4VEbqHu+DgUFq9D2uXhjMKYWs78HuZdlsQwLY VSx9axLQmvWe5uLYMghW/gDLD2XgeIzpYRFXY0oaTWCIKpRE5o0/hPxbo1BLVxQb/raj RlvQ== 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 e10si3096800pgu.428.2018.03.07.05.18.25; Wed, 07 Mar 2018 05:18:39 -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 S1754416AbeCGNR0 (ORCPT + 99 others); Wed, 7 Mar 2018 08:17:26 -0500 Received: from mga04.intel.com ([192.55.52.120]:1796 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751220AbeCGNRZ (ORCPT ); Wed, 7 Mar 2018 08:17:25 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Mar 2018 05:17:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,435,1515484800"; d="scan'208";a="36197404" Received: from smile.fi.intel.com (HELO smile) ([10.237.72.86]) by fmsmga001.fm.intel.com with ESMTP; 07 Mar 2018 05:17:20 -0800 Message-ID: <1520428639.10722.461.camel@linux.intel.com> Subject: Re: [PATCH 1/2] vsprintf: distinguish between (null), (err) and (invalid) pointer derefs 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:17:19 +0200 In-Reply-To: <20180306181122.11449-1-kilobyte@angband.pl> References: <20180306092513.ibodfsnv4xrxdlub@pathway.suse.cz> <20180306181122.11449-1-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: Thanks for the patch, my comments below. > Attempting to print an object pointed to by a bad (usually ERR_PTR) > pointer > is a not so surprising error. Our code handles them inconsistently: > * two places print (null) if ptr * one place prints (null) if abs(ptr) * one place prints (null) only if !ptr > > Obviously, saying (null) for a small but non-0 value is misleading. > Thus, let's print: > * (null) for exactly 0 > * (err) if last page && abs(ptr)<=MAX_ERRNO > * (invalid) otherwise > First of all, this patch is much more arguable than the other one in your small series. "(invalid)" is invalid. Hint: there is a nice comment in the code why. I'm in principle not putting explanation here to insist people to eventually _read and understand_ the code before doing anything. Some comments below. > +#define BAD_PTR_STRING(x) (!(x) ? "(null)" : IS_ERR(x) ? "(err)" : > "(invalid)") It looks ugly. > /** > * simple_strtoull - convert a string to an unsigned long long > * @cp: The start of the string > @@ -588,7 +590,7 @@ char *string(char *buf, char *end, const char *s, > struct printf_spec spec) > size_t lim = spec.precision; > > if ((unsigned long)s < PAGE_SIZE) > - s = "(null)"; > + s = BAD_PTR_STRING(s); It doesn't make any sense before your patch 2. > if ((unsigned long)dn < PAGE_SIZE) > - return string(buf, end, "(null)", spec); > + return string(buf, end, BAD_PTR_STRING(dn), spec); It simple doesn't make sense. The idea is to do it below, in the pointer. These certain lines are going to be removed by my patch. > - return string(buf, end, "(null)", spec); > + return string(buf, end, BAD_PTR_STRING(ptr), spec); Doesn't make sense before your patch 2. > if ((unsigned long)save_str > (unsigned > long)-PAGE_SIZE > || (unsigned long)save_str < > PAGE_SIZE) > - save_str = "(null)"; > + save_str = BAD_PTR_STRING(save_str); This is perhaps one valid change in such situation. -- Andy Shevchenko Intel Finland Oy