Received: by 10.213.65.68 with SMTP id h4csp727969imn; Fri, 6 Apr 2018 07:58:01 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/ER8tOC1gsQQEx6SSxMBhH3EfgPY9Y0bdGeVvzAfFSQtLTP/ngpALF76qNpTfB0yNKeB6d X-Received: by 2002:a17:902:7582:: with SMTP id j2-v6mr21602403pll.46.1523026681614; Fri, 06 Apr 2018 07:58:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523026681; cv=none; d=google.com; s=arc-20160816; b=IYmLmLJbtF+tEOFdk8nBSW18s9STWPlogQdiV1SJOTjPHOANfHhPgAeqzyO2nb4Zip zX2WE5C/z3AfKAskjZfW29rqty6c/Kc1u/gupg4ClXXuV45AU0T3LM2gknH0xTGs3Z+q viY/o+970xIWw0F7wNKhvcHVjhPOOq7ATYdXY33wOzehn+WPweFohVUyJDdvZob5cYU2 naBk+OugSyayGOrF0LgVJxMHaV7FpJi9ZrQAxSDexEv6izDf1DeBqUBu4lfJFe7EDuJo 58LpZ88DMrOiNwvkmD1deFOYC7crW1K+2RritD6dSCqCV6IR9RF/safL/yuJkngLGtzC Ufqg== 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=KMFtC7DviRHpNFiDEPT72XprLhhRnBvIYiJQebEugy8=; b=et7rUwlML1NFAzN25/N8YTYnosZoM+xiN+4iNa2CZjMIEgAYnbL2dMhpiDuGttkKi3 Bu/+14kzMJsAPrRoCFHILFsc/LFkUhZLOkM0xnT8FUENaN1e7YiS9tmSviHImDXUc7a6 BVQw8lt8fBMOt//5SKIYxuBCp1E+91BflJ3HoPAnQdPfZU8fr7oBCdZ54w5fGeSnHTIN 5oX++FDZTKEPqVkCuHIG5ftooKqT+1mXI93maAfQ+XdF7aRRWVbESDpK9ow/1L8wSnNt qclzKQLi2mxQ8xQX7oP7JhGdey85G0myHnK+RiDvYV5GWS/ZmweDMERsS7Zba7A7gXSx B86A== 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 d13si7436138pgn.334.2018.04.06.07.57.45; Fri, 06 Apr 2018 07:58:01 -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 S1755351AbeDFO4o (ORCPT + 99 others); Fri, 6 Apr 2018 10:56:44 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56902 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755196AbeDFNbw (ORCPT ); Fri, 6 Apr 2018 09:31:52 -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 8E4705A8; Fri, 6 Apr 2018 13:31:51 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Torvalds , Dan Williams , Andy Lutomirski , Arjan van de Ven , Borislav Petkov , Dave Hansen , David Woodhouse , Josh Poimboeuf , Peter Zijlstra , Thomas Gleixner , Will Deacon , linux-arch@vger.kernel.org, Ingo Molnar , Ben Hutchings Subject: [PATCH 4.4 64/72] nospec: Kill array_index_nospec_mask_check() Date: Fri, 6 Apr 2018 15:24:05 +0200 Message-Id: <20180406084310.804074694@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: Dan Williams commit 1d91c1d2c80cb70e2e553845e278b87a960c04da upstream. There are multiple problems with the dynamic sanity checking in array_index_nospec_mask_check(): * It causes unnecessary overhead in the 32-bit case since integer sized @index values will no longer cause the check to be compiled away like in the 64-bit case. * In the 32-bit case it may trigger with user controllable input when the expectation is that should only trigger during development of new kernel enabling. * The macro reuses the input parameter in multiple locations which is broken if someone passes an expression like 'index++' to array_index_nospec(). Reported-by: Linus Torvalds Signed-off-by: Dan Williams Cc: Andy Lutomirski Cc: Arjan van de Ven Cc: Borislav Petkov Cc: Dave Hansen Cc: David Woodhouse Cc: Greg Kroah-Hartman Cc: Josh Poimboeuf Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Will Deacon Cc: linux-arch@vger.kernel.org Link: http://lkml.kernel.org/r/151881604278.17395.6605847763178076520.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Ingo Molnar Cc: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- include/linux/nospec.h | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) --- a/include/linux/nospec.h +++ b/include/linux/nospec.h @@ -31,26 +31,6 @@ 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: @@ -68,7 +48,7 @@ static inline unsigned long array_index_ ({ \ typeof(index) _i = (index); \ typeof(size) _s = (size); \ - unsigned long _mask = array_index_mask_nospec_check(_i, _s); \ + unsigned long _mask = array_index_mask_nospec(_i, _s); \ \ BUILD_BUG_ON(sizeof(_i) > sizeof(long)); \ BUILD_BUG_ON(sizeof(_s) > sizeof(long)); \