Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp753841ybt; Fri, 19 Jun 2020 12:52:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTsgNWTCxk8B4zOWWO1e7b3/5/nNYhadBGN8perLyFh8zAZu4jYbLB81o5t5CJ4F4b+rrD X-Received: by 2002:a17:906:4554:: with SMTP id s20mr5020032ejq.241.1592596374765; Fri, 19 Jun 2020 12:52:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592596374; cv=none; d=google.com; s=arc-20160816; b=sCgrNOTedPEinMqAq4o98mYzX4HDjSdNoace9Tk8Yvvjuv8amrsW5AlDJx7IfjhVRz PlS1lO2EZ2JDbN4/O/gDkWRBVTTIOGGJN0pdxJbwbQc2nHwUJJ7wBly2HjzR6g30f+Q7 LT2UWfax/vHPwHliRZX2quzdIwHLAb5ea2F5MKpjHSklmaGwe7xitc8mFj4pS1KeBpLE tcRdsjxontHISqbYQJ21Dwbn3fno7vTvHpc9YVx57pRlUFZpzpcOVbIlMdHM8KfJkXeB i5ZOyKAf9Vq15lgChd1GvgPcXmxz9H0tVnEHbk2otG+wBXNOhxmqx1DRO48m7znD5Xl5 FKng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gMxvWDPH7lFVHD+bZLbyc/uLk2jbgRGMewX9eX+cI1g=; b=A+Sk0oQOCthsxZuxvAqx753bcoaH5VYmeBfN2d6Ys3yq9tEMd70Qbc76yXi+kWDvGJ HjryrFFtk1VFlQN0+R1u2Q/Kxzi3fppKUWD47VhIDz5/i8luRfHYQj+lRK+EkICAt+gX wwt6DW1zr3lv9ykVnQojeaoPZyC5QRuGODISbc71P/qcYsFGBjJi0uFFPeZBmUpkdzpp GdUb3KlEVH6GVlYOdy98ieYf+RK+Q3p1bguR/wUEUg6hXHCCR9COZxBQB+cw9sj5JqLT kil5nzCxHDEFxK9H3dxLCBAGs/rqNiuhhtutmnAa2oo/uEiqyo9QHiWIUszt/s4f4j27 op8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1Xjz2tPX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id du22si5942688ejc.330.2020.06.19.12.52.32; Fri, 19 Jun 2020 12:52:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1Xjz2tPX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387750AbgFSOl5 (ORCPT + 99 others); Fri, 19 Jun 2020 10:41:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:60626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388300AbgFSOlw (ORCPT ); Fri, 19 Jun 2020 10:41:52 -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 77EB321527; Fri, 19 Jun 2020 14:41:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592577711; bh=0ambyJKz5RjjLK0EaA4PkU3GfZROwDupON57dM5hrAE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1Xjz2tPXKNBsLtbQhRzgHKfxlDVw3L5cGLBrXwyEuPRJnnmrxVJP/uWq8+IS1lASB SMvhWyzY4rCo3n3egf9ZcWLSsHtAHTBxcAfAWyzJA0Fke+BtmdZljalUucvcIhwAzr e+VwjtvuU4kuCz0bLtwzzoRo5l+sXofQxwaZZiTg= 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.9 028/128] x86/speculation: PR_SPEC_FORCE_DISABLE enforcement for indirect branches. Date: Fri, 19 Jun 2020 16:32:02 +0200 Message-Id: <20200619141621.659073783@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141620.148019466@linuxfoundation.org> References: <20200619141620.148019466@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 2ab65f0ec56d..85c1cc0305f3 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -1257,11 +1257,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); -- 2.25.1