Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3920289pxj; Mon, 21 Jun 2021 09:23:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4bPf9NnDGZKKeo9k0lL8manCAE5caUe8zvPTVhG14WPKk5lCuL4OebyeDzdW6hmONrsdR X-Received: by 2002:a17:906:b215:: with SMTP id p21mr23497931ejz.237.1624292606401; Mon, 21 Jun 2021 09:23:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624292606; cv=none; d=google.com; s=arc-20160816; b=IrLJEubxSEd4Qk66AaTFH3xrIkTkRjI6MKo+0SV31O2Yc2qn6UWFnskGbM5o8sN/Mk jmZNjGeyU2iCwfIyohSn8O8VTOsbxjBtZ0MX5bEKZrByWXEIUnUdrhBpDDGzzYw+plKG 26dkX/Wa227u5V2W9vGpPZw/fR0je4IywJkGG0BIcsdlAv0QJdTKn8auCcHJRszghn1F z5odxtkv8Ft/wBkWnn7XTWMct1O+XdtKRC+HsYSmEMfuEhKXlsegf+GpxTu0G4bszEEy YHAlPJr//mEAKNw3KsVqz5R9GhFgwtf+tCbMPB5tBG4sxEjtQyinQzB0obBCsfk3qbXX nn+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TDevlwvf4X9HRrbMYXLE+gxfobyOcmfA355yHymhHxs=; b=vLtIutwa/514WBw9NjwUuRRRTmZ1gK0Tz9Ld5gv1I3kpalDWkq7pRE8DXm+7tWCtR/ st8DkYcLAjH/FxOK+gYPtkGV1r7PR9DeRweVUSH/SBrJshVSFimSorXiOnCYy/gxsL/f 7I/hGM+p3Jbw9/H7CoMEsp27GJSpw5ByKY/GY98a6BAMueeCUS+WRhh20+0PS9zfcZFi QB1/EAfnY2rCe+691LLbDLfV3pVd0NSOyEqYo/DBwF/E2fcX98VRQCVLK82xKynSXPC3 hQByaCnZ8OuWYTedr8UrgXjLoILIXdhRb+w+7b7zQs3/V8a1yn+ilzULr1wMNt04cFwy IAXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="E/yfkSay"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 18si11212409ejj.568.2021.06.21.09.23.04; Mon, 21 Jun 2021 09:23:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="E/yfkSay"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231661AbhFUQXN (ORCPT + 99 others); Mon, 21 Jun 2021 12:23:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:41850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231432AbhFUQV6 (ORCPT ); Mon, 21 Jun 2021 12:21:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8BFF161360; Mon, 21 Jun 2021 16:19:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292374; bh=oD6nPcakbFF37NET7R7AagDjjKz46GpqfleNg2BbKS8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E/yfkSayzyG1E6Ro9iulg9eWhqxFuAx6jfqSkWx+bhkylA9wn8h+PVRnRpuNCU4Ci n3My4UUffSei7A3RjsCxqhivL9ro6tLgZ3Ob6rRHVLH0SW9vm2qxfh9jR+McsZTyf3 4sm/QvOagfsEpXKLRAl5MLNQOEQP3Z2CHalCjr08= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Borislav Petkov , Dave Hansen , Rik van Riel Subject: [PATCH 5.4 66/90] x86/process: Check PF_KTHREAD and not current->mm for kernel threads Date: Mon, 21 Jun 2021 18:15:41 +0200 Message-Id: <20210621154906.393789166@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154904.159672728@linuxfoundation.org> References: <20210621154904.159672728@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner 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 Signed-off-by: Borislav Petkov Acked-by: Dave Hansen Acked-by: Rik van Riel Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20210608144345.912645927@linutronix.de Signed-off-by: Greg Kroah-Hartman --- 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 @@ -607,7 +607,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;