lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <40f51c91-23a0-2393-285f-c84a3a2e09ae@kernel.org>
Date:   Thu, 10 Jun 2021 18:04:30 -0700
From:   Andy Lutomirski <luto@...nel.org>
To:     Thomas Gleixner <tglx@...utronix.de>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Cc:     the arch/x86 maintainers <x86@...nel.org>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        Fenghua Yu <fenghua.yu@...el.com>,
        Tony Luck <tony.luck@...el.com>,
        Yu-cheng Yu <yu-cheng.yu@...el.com>,
        Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
        Rik van Riel <riel@...riel.com>, Borislav Petkov <bp@...e.de>
Subject: Re: [patch V3 3/6] x86/process: Check PF_KTHREAD and not current->mm
 for kernel threads

On 6/10/21 1:54 PM, Thomas Gleixner wrote:
> On Thu, Jun 10 2021 at 10:10, Andy Lutomirski wrote:
> 
>> On Tue, Jun 8, 2021, at 7:36 AM, Thomas Gleixner wrote:
>>> 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@...utronix.de>
>>> Cc: Rik van Riel <riel@...riel.com>
>>> Cc: stable@...r.kernel.org
>>> ---
>>>  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;
>>>
>>>
>> Why are we checking this at all?  I actually tend to agree with the
>> ->mm check more than PF_anything. If we have a user address space,
>> then PKRU matters. If we don’t, then it doesn’t.
> 
> Which PKRU matters? A kernel thread has always the default PKRU no
> matter whether it uses a mm or not. It _cannot_ borrow the PKRU from the
> mm owning process. There is no way, so let's not pretend there would be.
> 

Hmm.  I guess PK_KTHREAD is consistent with switch_fpu_prepare() --
kernel threads have no FPU state.

It might be worth a loud comment here that kernel threads' PKRU is not
context switched and that, if anyone wants kthread_use_mm() users to use
anything other than the default PKRU, that they will need to change this.

So I guess your patch is okay.

--Andy

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ