Thread (91 messages) 91 messages, 7 authors, 2021-09-17

Re: [PATCH v9 14/26] x86/arch_prctl: Create ARCH_SET_STATE_ENABLE/ARCH_GET_STATE_ENABLE

From: Bae, Chang Seok <hidden>
Date: 2021-08-10 00:57:39
Subsystem: the rest, x86 architecture (32-bit and 64-bit) · Maintainers: Linus Torvalds, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen

On Aug 9, 2021, at 16:42, Macieira, Thiago [off-list ref] wrote:
This means the corruption can get worse since the rollback code can undo or 
partially undo the progression of the other ARCH_SET_STATE_ENABLE.
Maybe something like this can help here to ensure a valid rollback.
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 96056f49bcff..3468bc0ee654 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -1353,6 +1353,8 @@ int alloc_xstate_buffer(struct fpu *fpu, u64 mask)
       return 0;
}

+static DEFINE_SPINLOCK(set_xstate_perm_lock);
+
/**
 * set_process_xstate_perm - Set a per-process permission to use dynamic
 *                          user xstates.
@@ -1383,6 +1385,8 @@ long set_process_xstate_perm(struct task_struct *tsk, u64 state_perm)
       if (!req_dynstate_perm)
               return 0;

+       spin_lock(&set_xstate_perm_lock);
+
       old_dynstate_perm = tsk->thread.fpu.dynamic_state_perm;

       for_each_thread(tsk, t) {
@@ -1396,6 +1400,8 @@ long set_process_xstate_perm(struct task_struct *tsk, u64 state_perm)
               pr_err("x86/fpu: ARCH_XSTATE_PERM failed as thread number mismatched.\n");
               return -EBUSY;
       }
+
+       spin_unlock(&set_xstate_perm_lock);
       return 0;
}

Thanks,
Chang
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help