This is a note to let you know that I've just added the patch titled x86/process: Check PF_KTHREAD and not current->mm for kernel threads to the 5.12-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: x86-process-check-pf_kthread-and-not-current-mm-for-kernel-threads.patch and it can be found in the queue-5.12 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 12f7764ac61200e32c916f038bdc08f884b0b604 Mon Sep 17 00:00:00 2001 From: Thomas Gleixner <tglx@xxxxxxxxxxxxx> Date: Tue, 8 Jun 2021 16:36:20 +0200 Subject: x86/process: Check PF_KTHREAD and not current->mm for kernel threads From: Thomas Gleixner <tglx@xxxxxxxxxxxxx> commit 12f7764ac61200e32c916f038bdc08f884b0b604 upstream. switch_fpu_finish() checks current->mm as indicator for kernel threads. That's wrong because kernel threads can temporarily use a mm of a user process via kthread_use_mm(). Check the task flags for PF_KTHREAD instead. Fixes: 0cecca9d03c9 ("x86/fpu: Eager switch PKRU state") Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx> Signed-off-by: Borislav Petkov <bp@xxxxxxx> Acked-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx> Acked-by: Rik van Riel <riel@xxxxxxxxxxx> Cc: stable@xxxxxxxxxxxxxxx Link: https://lkml.kernel.org/r/20210608144345.912645927@xxxxxxxxxxxxx Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- arch/x86/include/asm/fpu/internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -578,7 +578,7 @@ static inline void switch_fpu_finish(str * PKRU state is switched eagerly because it needs to be valid before we * return to userland e.g. for a copy_to_user() operation. */ - if (current->mm) { + if (!(current->flags & PF_KTHREAD)) { pk = get_xsave_addr(&new_fpu->state.xsave, XFEATURE_PKRU); if (pk) pkru_val = pk->pkru; Patches currently in stable-queue which might be from tglx@xxxxxxxxxxxxx are queue-5.12/x86-process-check-pf_kthread-and-not-current-mm-for-kernel-threads.patch queue-5.12/x86-pkru-write-hardware-init-value-to-pkru-when-xstate-is-init.patch queue-5.12/x86-fpu-prevent-state-corruption-in-__fpu__restore_sig.patch queue-5.12/crash_core-vmcoreinfo-append-section_size_bits-to-vmcoreinfo.patch queue-5.12/x86-fpu-invalidate-fpu-state-after-a-failed-xrstor-from-a-user-buffer.patch queue-5.12/x86-fpu-reset-state-for-all-signal-restore-failures.patch