Received: by 10.223.185.116 with SMTP id b49csp4126813wrg; Tue, 6 Mar 2018 10:13:35 -0800 (PST) X-Google-Smtp-Source: AG47ELuAvO3rD9M1HLSmPD4uvl6a/IjgcQBQKs/0TizSGnxQh1kaw/61Nq4WVnJXM+uFxKaTCFRV X-Received: by 2002:a17:902:bc3:: with SMTP id 61-v6mr17884801plr.398.1520360014948; Tue, 06 Mar 2018 10:13:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520360014; cv=none; d=google.com; s=arc-20160816; b=VBPC4treBclRpO/+xnlOM69d2QcZoJRPBQhqDecF2R4G0xphppQzCbS03f6Gi/TVMM aObtWt7ryShU8/4hh8zpeobpIZVA0+6BYVteK3EcVnlCVdpHVm+jvfRvtLMpuVAQSuUJ gv+QK9EwvD8UVR8sOh5hQOiCQG1lLgigIs/EkjlG0TMJHJ5ZF7vWxzhh0cKxVJopm6Jd q7pcgTIJ6ocKofVThLMR1zwKA0whT+q+FZu4DWPifmONZdzIw/V8TApf2vOCRfIe7hgg xiQM/e2S7avYiXybbfcJTCTEmC72WvLKKeD4IbFWzmtjujiTY0cfs6t+pEbC1K35vO4Q xpqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:references:in-reply-to:message-id :date:cc:to:from:arc-authentication-results; bh=715nyzpKIuS1WTnNKid3sf8XQXncHmQpXeUzTFRqf4w=; b=kyk1EnkOkx89oEWjNE2eCCxZoLtAdDtdNTrAL/xkWFityf7ay910ZDuAq6+f18W2RI 4Ytk7v8mFXNoMy+9TNJzb8nMSWMGoCoZLI+za5GX7mmr8Z/0UENx4DlGM7S1WAAR+NcA TdRBMrARbe0nAsR+LVtdZ9/UFSRYbBs/BEnSEI6CtPEIiRpddiEe3YIrKz+oxCJYLYGK Uzr6p8NpR0tYCnN7HJHFrQ+isNFXJcyvmCjyEYLYZGgTpzdVjOJ6P6Fwi5tdW/XcJEq8 k4yeLcWXgXKTYkYFzP9kR0+15hCgX+raYPX89O5oPC2j93lHleh7y7xJNeqFQk3omjW7 lj4w== 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 f4si10109922pgc.267.2018.03.06.10.13.19; Tue, 06 Mar 2018 10:13:34 -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 S1753920AbeCFSME (ORCPT + 99 others); Tue, 6 Mar 2018 13:12:04 -0500 Received: from tartarus.angband.pl ([89.206.35.136]:54352 "EHLO tartarus.angband.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753070AbeCFSMC (ORCPT ); Tue, 6 Mar 2018 13:12:02 -0500 Received: from [2a02:a312:c201:ce80::6] (helo=umbar.angband.pl) by tartarus.angband.pl with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1etH3q-0003KZ-Tb; Tue, 06 Mar 2018 19:11:40 +0100 Received: from kilobyte by umbar.angband.pl with local (Exim 4.90_1) (envelope-from ) id 1etH3q-0002zb-Im; Tue, 06 Mar 2018 19:11:38 +0100 From: Adam Borowski To: Petr Mladek , Rasmus Villemoes , Andy Shevchenko , "Tobin C . Harding" , Joe Perches , linux-kernel@vger.kernel.org, Andrew Morton , Michal Hocko Cc: Adam Borowski Date: Tue, 6 Mar 2018 19:11:22 +0100 Message-Id: <20180306181122.11449-2-kilobyte@angband.pl> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180306181122.11449-1-kilobyte@angband.pl> References: <20180306092513.ibodfsnv4xrxdlub@pathway.suse.cz> <20180306181122.11449-1-kilobyte@angband.pl> X-SA-Exim-Connect-IP: 2a02:a312:c201:ce80::6 X-SA-Exim-Mail-From: kilobyte@angband.pl X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tartarus X-Spam-Level: X-Spam-Status: No, score=-1.1 required=8.0 tests=BAYES_00=-1.9,RDNS_NONE=0.793, SPF_PASS=-0.001 autolearn=no autolearn_force=no languages=ro en fr Subject: [PATCH 2/2] vsprintf: don't dereference pointers to the first or last page X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on tartarus.angband.pl) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As old code to avoid so is inconsistent, let's unify it within a single macro. Signed-off-by: Adam Borowski --- lib/vsprintf.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 1c2c3cc5a321..4914dac03f0a 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -47,6 +47,8 @@ #include #include "kstrtox.h" +#define IS_BAD_PTR(x) ((unsigned long)(x) >= (unsigned long)-PAGE_SIZE \ + || (unsigned long)(x) < PAGE_SIZE) #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); while (lim--) { @@ -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); /* 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. @@ -2575,8 +2577,7 @@ int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args) const char *save_str = va_arg(args, char *); size_t len; - if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE - || (unsigned long)save_str < PAGE_SIZE) + if (IS_BAD_PTR(save_ptr)) save_str = BAD_PTR_STRING(save_str); len = strlen(save_str) + 1; if (str + len < end) -- 2.16.2