public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-tip-commits@vger.kernel.org,
	Andy Lutomirski <luto@kernel.org>,
	Brian Gerst <brgerst@gmail.com>,
	"Chang S. Bae" <chang.seok.bae@intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	x86@kernel.org
Subject: Re: hardened_usercopy 32-bit (was: Re: [tip: x86/merge] x86/fpu: Make task_struct::thread constant size)
Date: Mon, 5 May 2025 14:09:21 -0700	[thread overview]
Message-ID: <202505051408.7CABD131@keescook> (raw)
In-Reply-To: <aBihr1qRFBm1xj3_@gmail.com>

On Mon, May 05, 2025 at 01:31:59PM +0200, Ingo Molnar wrote:
> 
> * Kees Cook <kees@kernel.org> wrote:
> 
> > But as reported above, there *is* a copy in copy_uabi_to_xstate(). (It
> > seems there are several, actually.)
> > 
> > int copy_sigframe_from_user_to_xstate(struct task_struct *tsk,
> >                                       const void __user *ubuf)
> > {
> >         return copy_uabi_to_xstate(x86_task_fpu(tsk)->fpstate, NULL, ubuf, &tsk->thread.pkru);
> > }
> > 
> > This appears to be writing into x86_task_fpu(tsk)->fpstate. With or
> > without CONFIG_X86_DEBUG_FPU, this resolves to:
> > 
> > 	((struct fpu *)((void *)(task) + sizeof(*(task))))
> > 
> > i.e. the memory "after task_struct" is cast to "struct fpu", and the
> > uses the "fpstate" pointer. How that pointer gets set looks to be
> > variable, but I think the one we care about here is:
> > 
> >         fpu->fpstate = &fpu->__fpstate;
> > 
> > And struct fpu::__fpstate says:
> > 
> >         struct fpstate                  __fpstate;
> >         /*
> >          * WARNING: '__fpstate' is dynamically-sized.  Do not put
> >          * anything after it here.
> >          */
> > 
> > So we're still dealing with a dynamically sized thing, even if it's not
> > within the literal struct task_struct -- it's still in the kmem cache,
> > though.
> 
> Indeed!
> 
> > So, this is still copying out of the kmem cache for task_struct, and the
> > window seems unchanged (still fpu regs). This is what the window was
> > before:
> > 
> > void fpu_thread_struct_whitelist(unsigned long *offset, unsigned long *size)
> > {
> >         *offset = offsetof(struct thread_struct, fpu.__fpstate.regs);
> >         *size = fpu_kernel_cfg.default_size;
> > }
> > 
> > And the same commit I mentioned above removed it.
> > 
> > I think the misunderstanding is here:
> > 
> > >    The fpu_thread_struct_whitelist() quirk to hardened usercopy can be removed,
> > >    now that the FPU structure is not embedded in the task struct anymore, which
> > >    reduces text footprint a bit.
> > 
> > Yes, FPU is no longer in task_struct, but it IS in the kmem cache named
> > "task_struct", since the fpstate is still being allocated there.
> 
> Thank you for this fantastic explanation and the bug fix!
> 
> Since IMHO it would be a shame to lose all these explanations, and 
> because it's been exposed to -next for weeks without getting reported, 
> I've applied your fix to tip:x86/fpu after changeloggifying it. I've 
> also added your SOB, if that's fine with you. Let's not destroy genuine 
> Git history, let's not lose credit and let's not lose all these details 
> by squashing this fix into the buggy commit...

Okay, sounds good. :) Yeah, please consider it:

Signed-off-by: Kees Cook <kees@kernel.org>

Thanks!

-- 
Kees Cook

      reply	other threads:[~2025-05-05 21:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-03 12:07 hardened_usercopy 32-bit (was: Re: [tip: x86/merge] x86/fpu: Make task_struct::thread constant size) Borislav Petkov
2025-05-04  6:45 ` Ingo Molnar
2025-05-04  8:44   ` Ingo Molnar
2025-05-04  9:50     ` Borislav Petkov
2025-05-04  9:53       ` Ingo Molnar
2025-05-04 22:30 ` Kees Cook
2025-05-04 22:43   ` Kees Cook
2025-05-05  9:15     ` Borislav Petkov
2025-05-05 11:31   ` Ingo Molnar
2025-05-05 21:09     ` Kees Cook [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202505051408.7CABD131@keescook \
    --to=kees@kernel.org \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=chang.seok.bae@intel.com \
    --cc=gustavoars@kernel.org \
    --cc=hpa@zytor.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox