[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <605779b67af22009111aa9eda287026327d070d0.camel@intel.com>
Date: Thu, 07 May 2020 11:41:43 -0700
From: Yu-cheng Yu <yu-cheng.yu@...el.com>
To: Thomas Gleixner <tglx@...utronix.de>, linux-kernel@...r.kernel.org,
x86@...nel.org, "H. Peter Anvin" <hpa@...or.com>,
Ingo Molnar <mingo@...hat.com>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Tony Luck <tony.luck@...el.com>,
Andy Lutomirski <luto@...nel.org>,
Borislav Petkov <bp@...en8.de>,
Rik van Riel <riel@...riel.com>,
"Ravi V. Shankar" <ravi.v.shankar@...el.com>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
Fenghua Yu <fenghua.yu@...el.com>,
Peter Zijlstra <peterz@...radead.org>
Cc: sam <sunhaoyl@...look.com>, Kees Cook <keescook@...omium.org>,
Alexey Dobriyan <adobriyan@...il.com>,
Dave Hansen <dave.hansen@...el.com>,
Jann Horn <jannh@...gle.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Alexander Potapenko <glider@...gle.com>,
Al Viro <viro@...iv.linux.org.uk>, stable@...r.kernel.org
Subject: Re: [PATCH] x86/fpu/xstate: Clear uninitialized xstate areas in
core dump
On Thu, 2020-05-07 at 20:22 +0200, Thomas Gleixner wrote:
> Yu-cheng Yu <yu-cheng.yu@...el.com> writes:
> > @@ -983,6 +983,7 @@ int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int of
> > {
> > unsigned int offset, size;
> > struct xstate_header header;
> > + int last_off;
> > int i;
> >
> > /*
> > @@ -1006,7 +1007,17 @@ int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int of
> >
> > __copy_xstate_to_kernel(kbuf, &header, offset, size, size_total);
> >
> > + last_off = 0;
> > +
> > for (i = 0; i < XFEATURE_MAX; i++) {
> > + /*
> > + * Clear uninitialized area before XSAVE header.
> > + */
> > + if (i == FIRST_EXTENDED_XFEATURE) {
> > + memset(kbuf + last_off, 0, XSAVE_HDR_OFFSET - last_off);
> > + last_off = XSAVE_HDR_OFFSET + XSAVE_HDR_SIZE;
> > + }
> > +
> > /*
> > * Copy only in-use xstates:
> > */
> > @@ -1020,11 +1031,16 @@ int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int of
> > if (offset + size > size_total)
> > break;
> >
> > + memset(kbuf + last_off, 0, offset - last_off);
> > + last_off = offset + size;
> > +
> > __copy_xstate_to_kernel(kbuf, src, offset, size, size_total);
> > }
> >
> > }
> >
> > + memset(kbuf + last_off, 0, size_total - last_off);
>
> Why doing all this partial zeroing? There is absolutely no point.
>
> Either the caller clears the buffer or this function clears it right at
> the beginning with:
>
> memset(kbuf, 0, min(size_total, XSAVE_MAX_SIZE));
I was concerned that the XSAVES buffer can be large, but this is not in a
performance-critical path. Yes, clear it in the beginning is simpler.
Yu-cheng
Powered by blists - more mailing lists