From patchwork Fri Jun 19 14:31:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 223705 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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,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 51CD0C433DF for ; Fri, 19 Jun 2020 16:39:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 333562067D for ; Fri, 19 Jun 2020 16:39:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592584772; bh=0vMi/bjA1Wl/ZBxz9u8m9VwMcTJ/3ow8errzm8Ae+Ds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ITa7liBrQ3aYp7HDY+6TWBM9BmNAi4M1iRUi/nPfcIFk6aLLlDv4mYiVBm1/UpZpS jGoG3GpjHkOjxXRm+cZ6I3nqBsJ6NByxRXcG8oMBsOQ/EJvDGRYIQsPY0I/WHp791V KT+vjE3vA5uFHGIda9XOAIwz82Li/Gkd8dvCuqrs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2395341AbgFSQjY (ORCPT ); Fri, 19 Jun 2020 12:39:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:38404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388410AbgFSOqf (ORCPT ); Fri, 19 Jun 2020 10:46:35 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 BD41E20DD4; Fri, 19 Jun 2020 14:46:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592577995; bh=0vMi/bjA1Wl/ZBxz9u8m9VwMcTJ/3ow8errzm8Ae+Ds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ttPKp1fkveQOrcwplHUXnAj/5QZb+YIdGN5Jart8rRYxxMNZUKUVH5thwLGhvyoi9 obxuqYrAXq83lX6pRaSNP4sBhbmR2srRav/neJruCGCoGUlX+EIBrTvW5SWOBNXo93 sKMGQrJ/UktuV3l3RLvAQUnydoStMX9OUBGFqqLE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anthony Steinhauser , Thomas Gleixner , Sasha Levin Subject: [PATCH 4.14 042/190] x86/speculation: PR_SPEC_FORCE_DISABLE enforcement for indirect branches. Date: Fri, 19 Jun 2020 16:31:27 +0200 Message-Id: <20200619141635.695714428@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141633.446429600@linuxfoundation.org> References: <20200619141633.446429600@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Anthony Steinhauser [ Upstream commit 4d8df8cbb9156b0a0ab3f802b80cb5db57acc0bf ] Currently, it is possible to enable indirect branch speculation even after it was force-disabled using the PR_SPEC_FORCE_DISABLE option. Moreover, the PR_GET_SPECULATION_CTRL command gives afterwards an incorrect result (force-disabled when it is in fact enabled). This also is inconsistent vs. STIBP and the documention which cleary states that PR_SPEC_FORCE_DISABLE cannot be undone. Fix this by actually enforcing force-disabled indirect branch speculation. PR_SPEC_ENABLE called after PR_SPEC_FORCE_DISABLE now fails with -EPERM as described in the documentation. Fixes: 9137bb27e60e ("x86/speculation: Add prctl() control for indirect branch speculation") Signed-off-by: Anthony Steinhauser Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org Signed-off-by: Sasha Levin --- arch/x86/kernel/cpu/bugs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index ffcf30ec0aae..245184152892 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -1249,11 +1249,14 @@ static int ib_prctl_set(struct task_struct *task, unsigned long ctrl) return 0; /* * Indirect branch speculation is always disabled in strict - * mode. + * mode. It can neither be enabled if it was force-disabled + * by a previous prctl call. + */ if (spectre_v2_user_ibpb == SPECTRE_V2_USER_STRICT || spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT || - spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT_PREFERRED) + spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT_PREFERRED || + task_spec_ib_force_disable(task)) return -EPERM; task_clear_spec_ib_disable(task); task_update_spec_tif(task);