]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
x86/process: Check PF_KTHREAD and not current->mm for kernel threads
authorThomas Gleixner <tglx@linutronix.de>
Tue, 8 Jun 2021 14:36:20 +0000 (16:36 +0200)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Thu, 15 Jul 2021 17:27:44 +0000 (19:27 +0200)
BugLink: https://bugs.launchpad.net/bugs/1934179
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@linutronix.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Acked-by: Rik van Riel <riel@surriel.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/20210608144345.912645927@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
arch/x86/include/asm/fpu/internal.h

index 00eac7f1529b08db11d65830cfd14e38a495d75e..68088ae6296f207864d2abdb9c6334a5b37eaaa5 100644 (file)
@@ -607,7 +607,7 @@ static inline void switch_fpu_finish(struct fpu *new_fpu)
         * 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;