x86/fpu: hold fpregs_lock() across fpstate_reset() in fpu_flush_thread()
PATCH 1/1 x86/fpu: hold fpregs_lock() across fpstate_reset() in fpu_flush_thread()
fpstate_reset() updates the fpstate pointer before resetting its size and feature metadata without holding fpregs_lock(). If the task is preempted during this transition, switch_fpu_prepare() can save the FPU registers using the stale feature configuration into the newly selected, smaller buffer, potentially causing an out-of-bounds write into the embedded fpstate buffer.
Hold fpregs_lock() across fpstate_reset() to prevent a context switch or softirq from accessing the partially updated FPU state.
--- arch/x86/kernel/fpu/core.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/kernel/fpu/core.c +2 -0
@@ -866,7 +866,9 @@ void fpu__clear_user_states(struct fpu *fpu)void fpu_flush_thread (void ) { +fpregs_lock ();fpstate_reset (x86_task_fpu (current)); +fpregs_unlock ();fpu_reset_fpstate_regs (); }/*
Signature · 1 line
2.56.0
Quoted 7 lines · Ömer Mete Kaya
fpstate_reset()updates the fpstate pointer before resetting its size and feature metadata without holdingfpregs_lock(). If the task is preempted during this transition,switch_fpu_prepare()can save the FPU registers using the stale feature configuration into the newly selected, smaller buffer, potentially causing an out-of-bounds write into the embedded fpstate buffer.
Quoted 6 lines
Hold
fpregs_lock()acrossfpstate_reset()to prevent a context switch or softirq from accessing the partially updated FPU state.Fixes e61d6310a0f8 ("x86/fpu: Reset permission and fpstate on exec()")Signed-off-by Ömer Mete Kaya <[email protected]>
Hi Omer,
I'm genuinely curious how you came across this issue and decided to send a patch for it.
Did you happen to read the other (brief) conversation on it?
Quoted 8 lines · Dave Hansen
Hi Omer,
I'm genuinely curious how you came across this issue and decided to send a patch for it.
Did you happen to read the other (brief) conversation on it?
Hi Dave,
I saw that on
https://syzkaller.appspot.com/bug?extid=58cbd7974a103b8b8916 and in the "discussions" section there, the discussion you had with Chang wasn't visible, so I hadn't read it. Looks like you were already working on it.
Thanks,
Ömer