From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D605C43387 for ; Mon, 7 Jan 2019 13:06:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1D2C0218A1 for ; Mon, 7 Jan 2019 13:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546866361; bh=Ld13Sbe4HKYF/4vuBE9S6BPU0VGVUx0VCiKIsG3FJ/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=N4CQR4U9+18k25276meEDp8cE6Sm2SbfRy962XOlTTM8fCs4qmt+XrXkNDzeU2oul vWQOVkk8P57msgCxCDy5G2sitKqGp1Hg8V3NzFkEfo1wguGZs2FfEWfvTJlOAXQOgA UqTl+MYOvZGTGZdVMFUdlUTfs0tCQ4TOXqz8eo8s= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727328AbfAGNFy (ORCPT ); Mon, 7 Jan 2019 08:05:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:53442 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730806AbfAGNFx (ORCPT ); Mon, 7 Jan 2019 08:05:53 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 41C6021736; Mon, 7 Jan 2019 13:05:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546866352; bh=Ld13Sbe4HKYF/4vuBE9S6BPU0VGVUx0VCiKIsG3FJ/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v/9Ykk0V1F1w8z57L6pSoV/r/ZzXT16loLkAG+QqdQ1vVY7ns7LCZjljtIu6x2rO6 C4NHEq8vmCV9pr/RIAd8FwvdrYKinPpi/sL/CdTMmhc52pBrvLyfqKUq9FEAT/9nHo pjYcAE005L6Cyf2nVd7u968xf4eVABWztJ2yCY+c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Gustavo A. R. Silva" , "David S. Miller" Subject: [PATCH 4.9 04/71] net: core: Fix Spectre v1 vulnerability Date: Mon, 7 Jan 2019 13:32:33 +0100 Message-Id: <20190107105330.536657603@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107105330.280153213@linuxfoundation.org> References: <20190107105330.280153213@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: "Gustavo A. R. Silva" [ Upstream commit 50d5258634aee2e62832aa086d2fb0de00e72b91 ] flen is indirectly controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability. This issue was detected with the help of Smatch: net/core/filter.c:1101 bpf_check_classic() warn: potential spectre issue 'filter' [w] Fix this by sanitizing flen before using it to index filter at line 1101: switch (filter[flen - 1].code) { and through pc at line 1040: const struct sock_filter *ftest = &filter[pc]; Notice that given that speculation windows are large, the policy is to kill the speculation on the first load and not worry if it can be completed with a dependent load/store [1]. [1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2 Signed-off-by: Gustavo A. R. Silva Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/filter.c | 2 ++ 1 file changed, 2 insertions(+) --- a/net/core/filter.c +++ b/net/core/filter.c @@ -51,6 +51,7 @@ #include #include #include +#include /** * sk_filter_trim_cap - run a packet through a socket filter @@ -786,6 +787,7 @@ static int bpf_check_classic(const struc bool anc_found; int pc; + flen = array_index_nospec(flen, BPF_MAXINSNS + 1); /* Check the filter code now */ for (pc = 0; pc < flen; pc++) { const struct sock_filter *ftest = &filter[pc];