aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2017-09-24 06:59:08 -0400
committerIngo Molnar <mingo@kernel.org>2017-09-26 03:43:46 -0400
commitb89eda482d7849a1c146b6d0a42f4e76369bb08e (patch)
treeb38e82377700e300c0408cacfa210c6389b0586d
parent80d8ae86b36791a545ca28ddc95133ea59bba6e0 (diff)
x86/fpu: Eliminate the 'xfeatures' local variable in copy_kernel_to_xstate()
We have this information in the xstate_header. Signed-off-by: Eric Biggers <ebiggers@google.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Eric Biggers <ebiggers3@gmail.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Kees Cook <keescook@chromium.org> Cc: Kevin Hao <haokexin@gmail.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Michael Halcrow <mhalcrow@google.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Wanpeng Li <wanpeng.li@hotmail.com> Cc: Yu-cheng Yu <yu-cheng.yu@intel.com> Cc: kernel-hardening@lists.openwall.com Link: http://lkml.kernel.org/r/20170924105913.9157-6-mingo@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/kernel/fpu/xstate.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 02591b96bb25..c97c4a9db52a 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -1146,7 +1146,6 @@ int copy_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf)
1146{ 1146{
1147 unsigned int offset, size; 1147 unsigned int offset, size;
1148 int i; 1148 int i;
1149 u64 xfeatures;
1150 u64 allowed_features; 1149 u64 allowed_features;
1151 struct xstate_header hdr; 1150 struct xstate_header hdr;
1152 1151
@@ -1154,20 +1153,19 @@ int copy_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf)
1154 size = sizeof(hdr); 1153 size = sizeof(hdr);
1155 1154
1156 memcpy(&hdr, kbuf + offset, size); 1155 memcpy(&hdr, kbuf + offset, size);
1157 xfeatures = hdr.xfeatures;
1158 1156
1159 /* 1157 /*
1160 * Reject if the user sets any disabled or supervisor features: 1158 * Reject if the user sets any disabled or supervisor features:
1161 */ 1159 */
1162 allowed_features = xfeatures_mask & ~XFEATURE_MASK_SUPERVISOR; 1160 allowed_features = xfeatures_mask & ~XFEATURE_MASK_SUPERVISOR;
1163 1161
1164 if (xfeatures & ~allowed_features) 1162 if (hdr.xfeatures & ~allowed_features)
1165 return -EINVAL; 1163 return -EINVAL;
1166 1164
1167 for (i = 0; i < XFEATURE_MAX; i++) { 1165 for (i = 0; i < XFEATURE_MAX; i++) {
1168 u64 mask = ((u64)1 << i); 1166 u64 mask = ((u64)1 << i);
1169 1167
1170 if (xfeatures & mask) { 1168 if (hdr.xfeatures & mask) {
1171 void *dst = __raw_xsave_addr(xsave, 1 << i); 1169 void *dst = __raw_xsave_addr(xsave, 1 << i);
1172 1170
1173 offset = xstate_offsets[i]; 1171 offset = xstate_offsets[i];
@@ -1177,7 +1175,7 @@ int copy_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf)
1177 } 1175 }
1178 } 1176 }
1179 1177
1180 if (xfeatures_mxcsr_quirk(xfeatures)) { 1178 if (xfeatures_mxcsr_quirk(hdr.xfeatures)) {
1181 offset = offsetof(struct fxregs_state, mxcsr); 1179 offset = offsetof(struct fxregs_state, mxcsr);
1182 size = MXCSR_AND_FLAGS_SIZE; 1180 size = MXCSR_AND_FLAGS_SIZE;
1183 memcpy(&xsave->i387.mxcsr, kbuf + offset, size); 1181 memcpy(&xsave->i387.mxcsr, kbuf + offset, size);
@@ -1192,7 +1190,7 @@ int copy_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf)
1192 /* 1190 /*
1193 * Add back in the features that came in from userspace: 1191 * Add back in the features that came in from userspace:
1194 */ 1192 */
1195 xsave->header.xfeatures |= xfeatures; 1193 xsave->header.xfeatures |= hdr.xfeatures;
1196 1194
1197 return 0; 1195 return 0;
1198} 1196}