Received: by 10.213.65.68 with SMTP id h4csp636573imn; Fri, 6 Apr 2018 06:33:03 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/8Ff+sz3zgszZS2DoFWgSG5279yGNVgXCVz6FKE4CAR3K2Pdg07LjZF9xQ9qVhpexOJc/J X-Received: by 2002:a17:902:2943:: with SMTP id g61-v6mr27753665plb.238.1523021583092; Fri, 06 Apr 2018 06:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523021583; cv=none; d=google.com; s=arc-20160816; b=x+iiDimcNA2O4wfKe2oe7y+bl9truH/5GM8rD/2NtafPS16XGuzZ+lHYi3Tr86CqmB x8fslKLLtharr+hG4ourO1Z84HSIuOqRHygvroFVhNza6bq6UHXkQ6a124csU9cpvXID XNFu/1H7FgEODU3r4ZPeaNpg3gX2+gUyegy4nCkeph77JHsLFlxpGf+knpsUC5WMB9E1 TRUC5lQAoX3FyT3f1Bv0+u+1M3vF91R/VpYCYIkP3DUkbIhn7mz5qsIwkBlDFUucmlfu PxkM2CfIwMUnDZWC2KsQqNnWcmgbPRw1dGF9qAdftYaXWGe1z7YuH250Ci2yQyITxpHA 9+SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=IhM+Udd2W3LNd1j2SldlyRcijHKg9KhrYaOl4khzCNk=; b=OPNiGc6F+swXz7vXr0eFJ4gCiNxsprfLsEhq/7OSirX553W3z6fEAqqJ1Q4WrFLFyV KuBtCgWDvNzt/trm86yO3kanokFtMvWfQaV+HF09wvRKh4CPSFctwHCROXwk9gOGW31Q TUNoRWyk4803PpEacsVsHcfY7rxnMNL0lPrwocm1TVGtGKHkK5uIIUn6ATtVl8AAtWAF ixh+Uv9pjOq14VTkdI6/CojTFPAIkJTUNHHJ44qQKpp99S6nUmYa+5tSGjGZg5+09s6e GKmvfwJ8kkuvxotUAPzph5rD2lL+0b7kS9Nzy0m3p0z/ffsjJovIs5hXmyNPkhbkW30f OP9g== 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 x8-v6si7876644plv.420.2018.04.06.06.32.49; Fri, 06 Apr 2018 06:33:03 -0700 (PDT) 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 S1755249AbeDFNbx (ORCPT + 99 others); Fri, 6 Apr 2018 09:31:53 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56876 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755231AbeDFNbt (ORCPT ); Fri, 6 Apr 2018 09:31:49 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0C7C88A5; Fri, 6 Apr 2018 13:31:48 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Will Deacon , Thomas Gleixner , Dan Williams , Linus Torvalds , Peter Zijlstra , Ingo Molnar , Ben Hutchings Subject: [PATCH 4.4 63/72] nospec: Move array_index_nospec() parameter checking into separate macro Date: Fri, 6 Apr 2018 15:24:04 +0200 Message-Id: <20180406084310.714705931@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084305.210085169@linuxfoundation.org> References: <20180406084305.210085169@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Will Deacon commit 8fa80c503b484ddc1abbd10c7cb2ab81f3824a50 upstream. For architectures providing their own implementation of array_index_mask_nospec() in asm/barrier.h, attempting to use WARN_ONCE() to complain about out-of-range parameters using WARN_ON() results in a mess of mutually-dependent include files. Rather than unpick the dependencies, simply have the core code in nospec.h perform the checking for us. Signed-off-by: Will Deacon Acked-by: Thomas Gleixner Cc: Dan Williams Cc: Linus Torvalds Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1517840166-15399-1-git-send-email-will.deacon@arm.com Signed-off-by: Ingo Molnar Cc: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- include/linux/nospec.h | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) --- a/include/linux/nospec.h +++ b/include/linux/nospec.h @@ -21,20 +21,6 @@ static inline unsigned long array_index_ unsigned long size) { /* - * Warn developers about inappropriate array_index_nospec() usage. - * - * Even if the CPU speculates past the WARN_ONCE branch, the - * sign bit of @index is taken into account when generating the - * mask. - * - * This warning is compiled out when the compiler can infer that - * @index and @size are less than LONG_MAX. - */ - if (WARN_ONCE(index > LONG_MAX || size > LONG_MAX, - "array_index_nospec() limited to range of [0, LONG_MAX]\n")) - return 0; - - /* * Always calculate and emit the mask even if the compiler * thinks the mask is not needed. The compiler does not take * into account the value of @index under speculation. @@ -45,6 +31,26 @@ static inline unsigned long array_index_ #endif /* + * Warn developers about inappropriate array_index_nospec() usage. + * + * Even if the CPU speculates past the WARN_ONCE branch, the + * sign bit of @index is taken into account when generating the + * mask. + * + * This warning is compiled out when the compiler can infer that + * @index and @size are less than LONG_MAX. + */ +#define array_index_mask_nospec_check(index, size) \ +({ \ + if (WARN_ONCE(index > LONG_MAX || size > LONG_MAX, \ + "array_index_nospec() limited to range of [0, LONG_MAX]\n")) \ + _mask = 0; \ + else \ + _mask = array_index_mask_nospec(index, size); \ + _mask; \ +}) + +/* * array_index_nospec - sanitize an array index after a bounds check * * For a code sequence like: @@ -62,7 +68,7 @@ static inline unsigned long array_index_ ({ \ typeof(index) _i = (index); \ typeof(size) _s = (size); \ - unsigned long _mask = array_index_mask_nospec(_i, _s); \ + unsigned long _mask = array_index_mask_nospec_check(_i, _s); \ \ BUILD_BUG_ON(sizeof(_i) > sizeof(long)); \ BUILD_BUG_ON(sizeof(_s) > sizeof(long)); \