Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1214726
| From | Dave Hansen <dave@sr71.net> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 10/11] x86, fpu: check to ensure increasing-offset xstate offsets |
| Date | 2015-08-27 19:20 +0200 |
| Message-ID | <q290f-2v7-37@gated-at.bofh.it> (permalink) |
| References | <q290d-2v7-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Dave Hansen <dave.hansen@linux.intel.com>
The xstate CPUID leaves enumerate where each state component is
inside the XSAVE buffer, along with the size of the entire
buffer. Our new XSAVE sanity-checking code extrapolates an
expected _total_ buffer size by looking at the last component
that it encounters.
That method requires that the highest-numbered component also
be the one with the highest offset. This is a pretty safe
assumption, but let's add some code to ensure it stays true.
To make this check work correctly, we also need to ensure we
only consider the offsets from enabled features because the
offset register (ebx) will return 0 on unsupported features.
This also means that we will preserve the -1's that we
initialized xstate_offsets/sizes[] with. That will help
find bugs.
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: x86@kernel.org
Cc: Borislav Petkov <bp@alien8.de>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: linux-kernel@vger.kernel.org
---
b/arch/x86/kernel/fpu/xstate.c | 34 +++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)
diff -puN arch/x86/kernel/fpu/xstate.c~x86-fpu-increasing-offset-assumption arch/x86/kernel/fpu/xstate.c
--- a/arch/x86/kernel/fpu/xstate.c~x86-fpu-increasing-offset-assumption 2015-08-27 10:08:04.657774861 -0700
+++ b/arch/x86/kernel/fpu/xstate.c 2015-08-27 10:08:04.660774998 -0700
@@ -166,18 +166,40 @@ void fpu__init_cpu_xstate(void)
}
/*
+ * Note that in the future we will likely need a pair of
+ * functions here: one for user xstates and the other for
+ * system xstates. For now, they are the same.
+ */
+static int xfeature_nr_enabled(enum xfeature_nr xfeature_nr)
+{
+ return !!(xfeatures_mask & (1UL << xfeature_nr));
+}
+
+/*
* Record the offsets and sizes of various xstates contained
* in the XSAVE state memory layout.
*/
static void __init setup_xstate_features(void)
{
u32 eax, ebx, ecx, edx, i;
+ /* start at the beginnning of the "extended state" */
+ unsigned int last_good_offset = offsetof(struct xregs_state, __reserved);
for (i = FIRST_EXTENDED_XFEATURE_NR; i < XFEATURES_NR_MAX; i++) {
- cpuid_count(XSTATE_CPUID, i, &eax, &ebx, &ecx, &edx);
+ if (!xfeature_nr_enabled(i))
+ continue;
+ cpuid_count(XSTATE_CPUID, i, &eax, &ebx, &ecx, &edx);
xstate_offsets[i] = ebx;
xstate_sizes[i] = eax;
+ /*
+ * In our xstate size checks, we assume that the
+ * highest-numbered xstate feature has the
+ * highest offset in the buffer. Ensure it does.
+ */
+ WARN_ONCE(last_good_offset > xstate_offsets[i],
+ "x86/fpu: misordered xstate at %d\n", last_good_offset);
+ last_good_offset = xstate_offsets[i];
printk(KERN_INFO "x86/fpu: xstate_offset[%d]: %04x, xstate_sizes[%d]: %04x\n", i, ebx, i, eax);
}
@@ -207,16 +229,6 @@ static void __init print_xstate_features
}
/*
- * Note that in the future we will likely need a pair of
- * functions here: one for user xstates and the other for
- * system xstates. For now, they are the same.
- */
-static int xfeature_nr_enabled(enum xfeature_nr xfeature_nr)
-{
- return !!(xfeatures_mask & (1UL << xfeature_nr));
-}
-
-/*
* This function sets up offsets and sizes of all extended states in
* xsave area. This supports both standard format and compacted format
* of the xsave aread.
_
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 00/11] [v2] x86, fpu: XSAVE cleanups and sanity checks Dave Hansen <dave@sr71.net> - 2015-08-27 19:20 +0200
[PATCH 06/11] x86, fpu: rework MPX 'xstate' types Dave Hansen <dave@sr71.net> - 2015-08-27 19:20 +0200
[PATCH 04/11] x86, fpu: remove xfeature_nr Dave Hansen <dave@sr71.net> - 2015-08-27 19:20 +0200
Re: [PATCH 04/11] x86, fpu: remove xfeature_nr Ingo Molnar <mingo@kernel.org> - 2015-08-28 07:10 +0200
[PATCH 01/11] x86, fpu: kill LWP support Dave Hansen <dave@sr71.net> - 2015-08-27 19:20 +0200
Re: [PATCH 01/11] x86, fpu: kill LWP support Ingo Molnar <mingo@kernel.org> - 2015-08-28 07:00 +0200
[PATCH 07/11] x86, fpu: rework YMM definition Dave Hansen <dave@sr71.net> - 2015-08-27 19:20 +0200
[PATCH 09/11] x86, fpu: correct and check XSAVE xstate size calculations Dave Hansen <dave@sr71.net> - 2015-08-27 19:20 +0200
Re: [PATCH 09/11] x86, fpu: correct and check XSAVE xstate size calculations Ingo Molnar <mingo@kernel.org> - 2015-08-28 07:00 +0200
Re: [PATCH 09/11] x86, fpu: correct and check XSAVE xstate size calculations Dave Hansen <dave@sr71.net> - 2015-08-28 16:40 +0200
Re: [PATCH 09/11] x86, fpu: correct and check XSAVE xstate size calculations Andi Kleen <andi@firstfloor.org> - 2015-08-28 18:50 +0200
[PATCH 10/11] x86, fpu: check to ensure increasing-offset xstate offsets Dave Hansen <dave@sr71.net> - 2015-08-27 19:20 +0200
[PATCH 08/11] x86, fpu: add C structures for AVX-512 state components Dave Hansen <dave@sr71.net> - 2015-08-27 19:20 +0200
Re: [PATCH 08/11] x86, fpu: add C structures for AVX-512 state components Ingo Molnar <mingo@kernel.org> - 2015-08-28 07:10 +0200
[PATCH 11/11] x86, fpu: check CPU-provided sizes against struct declarations Dave Hansen <dave@sr71.net> - 2015-08-27 19:20 +0200
Re: [PATCH 11/11] x86, fpu: check CPU-provided sizes against struct declarations Ingo Molnar <mingo@kernel.org> - 2015-08-28 07:30 +0200
Re: [PATCH 11/11] x86, fpu: check CPU-provided sizes against struct declarations Dave Hansen <dave@sr71.net> - 2015-08-28 18:10 +0200
[PATCH 05/11] x86, fpu: add helper xfeature_nr_enabled() instead of test_bit() Dave Hansen <dave@sr71.net> - 2015-08-27 19:20 +0200
Re: [PATCH 05/11] x86, fpu: add helper xfeature_nr_enabled() instead of test_bit() Ingo Molnar <mingo@kernel.org> - 2015-08-28 07:10 +0200
Re: [PATCH 00/11] [v2] x86, fpu: XSAVE cleanups and sanity checks Ingo Molnar <mingo@kernel.org> - 2015-08-28 07:20 +0200
csiph-web