Commit 9fe8a6f5 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Borislav Petkov

x86/fpu: Cleanup arch_set_user_pkey_access()

The function does a sanity check with a WARN_ON_ONCE() but happily proceeds
when the pkey argument is out of range.

Clean it up.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Reviewed-by: default avatarBorislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20210623121453.635764326@linutronix.de
parent 71ef4533
...@@ -912,11 +912,10 @@ EXPORT_SYMBOL_GPL(get_xsave_addr); ...@@ -912,11 +912,10 @@ EXPORT_SYMBOL_GPL(get_xsave_addr);
* rights for @pkey to @init_val. * rights for @pkey to @init_val.
*/ */
int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
unsigned long init_val) unsigned long init_val)
{ {
u32 old_pkru; u32 old_pkru, new_pkru_bits = 0;
int pkey_shift = (pkey * PKRU_BITS_PER_PKEY); int pkey_shift;
u32 new_pkru_bits = 0;
/* /*
* This check implies XSAVE support. OSPKE only gets * This check implies XSAVE support. OSPKE only gets
...@@ -930,7 +929,8 @@ int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, ...@@ -930,7 +929,8 @@ int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
* values originating from in-kernel users. Complain * values originating from in-kernel users. Complain
* if a bad value is observed. * if a bad value is observed.
*/ */
WARN_ON_ONCE(pkey >= arch_max_pkey()); if (WARN_ON_ONCE(pkey >= arch_max_pkey()))
return -EINVAL;
/* Set the bits we need in PKRU: */ /* Set the bits we need in PKRU: */
if (init_val & PKEY_DISABLE_ACCESS) if (init_val & PKEY_DISABLE_ACCESS)
...@@ -939,6 +939,7 @@ int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, ...@@ -939,6 +939,7 @@ int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
new_pkru_bits |= PKRU_WD_BIT; new_pkru_bits |= PKRU_WD_BIT;
/* Shift the bits in to the correct place in PKRU for pkey: */ /* Shift the bits in to the correct place in PKRU for pkey: */
pkey_shift = pkey * PKRU_BITS_PER_PKEY;
new_pkru_bits <<= pkey_shift; new_pkru_bits <<= pkey_shift;
/* Get old PKRU and mask off any old bits in place: */ /* Get old PKRU and mask off any old bits in place: */
......
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