Commit 22abece4 authored by Anthony Steinhauser's avatar Anthony Steinhauser Committed by Khalid Elmously

x86/speculation: PR_SPEC_FORCE_DISABLE enforcement for indirect branches.

BugLink: https://bugs.launchpad.net/bugs/1884564

[ Upstream commit 4d8df8cb ]

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: 9137bb27 ("x86/speculation: Add prctl() control for indirect branch speculation")
Signed-off-by: default avatarAnthony Steinhauser <asteinhauser@google.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 421e79e8
...@@ -1295,11 +1295,14 @@ static int ib_prctl_set(struct task_struct *task, unsigned long ctrl) ...@@ -1295,11 +1295,14 @@ static int ib_prctl_set(struct task_struct *task, unsigned long ctrl)
return 0; return 0;
/* /*
* Indirect branch speculation is always disabled in strict * 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 || 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 ||
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; return -EPERM;
task_clear_spec_ib_disable(task); task_clear_spec_ib_disable(task);
task_update_spec_tif(task); task_update_spec_tif(task);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment