Received: by 10.223.185.116 with SMTP id b49csp939946wrg; Wed, 21 Feb 2018 09:20:49 -0800 (PST) X-Google-Smtp-Source: AH8x225oLvI8jzo/r4aTifvs8Hg6aiF5qdaA+Ov0aA2cmG1vWoD6AuTMgBmitU0v2FNiE363Gs8a X-Received: by 10.98.88.1 with SMTP id m1mr4006905pfb.178.1519233649648; Wed, 21 Feb 2018 09:20:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519233649; cv=none; d=google.com; s=arc-20160816; b=mkZg8SbcuoclEG/0X0dUcSTtDW2jVYpwlXd7v95hxYrBqqJ3LtOzOSQdJXIlqTdCPR pHZ866Fwic2jctsvjW/hZEAqFdMuZqtS9VtPPjBomT5eK5N/+MRjcKeIx3q/n4pUwM3p 4A6YVptlw8oRdYLfvlvheVLNWu+fGEIbK0DBUCtiBC/0sZsSUFCSeeMrQVjahJ3AQWwz Ycm7TNTqNFGKj/s/Td3Kx5iMIgl1zpIOmFrTVg8toyysdvs43VKf0WwpdJH+rvmWL6L5 iLuhpHX+P2WXOdd8geFN5RQEi0SiYtXpyt5I95XyAV2yMaJJfh61Wp7ezIK/iQEfxNXM JIoQ== 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=b06fW+JBE8Id3B9JCc8+SJPfKLpue7JDtIa5jFlDZI8=; b=cwg2Te5D1uo3NGiT+eXCi1yOu/m8FQs8z7d3XnBH6eufAfc1u1PeslbuTAQTWAFHDE JzKoHb1EshKZpVlDU+sxnNJMqWyAAyd3Z7xZK7z5Mub6k+/sGqBzdybmIjnNTg8HMGhf ommZ7VqhjW/yFyosADFnXbsqAUQQUoB9rKJl5QU+/ya66sWzfBxjHkuedIzGVSi4aDFK Sm7nGMmFLs5+bw9G1liLr0Pam6RJ7WTwr7L7Tn808kp5IZpDr4HeRiXERMgphKP+OntI 73GdskXCFmD33W1hQCxY+pLUlFzyEsWw/RgwN5Hk5N0+JnZJgmKaIfaYX7cFbDGHX54g ydOw== 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 q26si1643745pgd.823.2018.02.21.09.20.35; Wed, 21 Feb 2018 09:20:49 -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 S934514AbeBUM4q (ORCPT + 99 others); Wed, 21 Feb 2018 07:56:46 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:35480 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934496AbeBUM4m (ORCPT ); Wed, 21 Feb 2018 07:56:42 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 225F3F10; Wed, 21 Feb 2018 12:56:40 +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 Subject: [PATCH 4.9 61/77] nospec: Move array_index_nospec() parameter checking into separate macro Date: Wed, 21 Feb 2018 13:49:10 +0100 Message-Id: <20180221124434.780300299@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124432.172390020@linuxfoundation.org> References: <20180221124432.172390020@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.9-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 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 @@ -20,20 +20,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. @@ -44,6 +30,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: @@ -61,7 +67,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)); \