diff options
author | Ingo Molnar <mingo@kernel.org> | 2015-05-25 04:59:31 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2015-05-27 08:11:28 -0400 |
commit | 43b287b3f4d8665cd5a4909132259b663cc1c0e3 (patch) | |
tree | a782f11d7934e451c57f1b7e9a8f1dd87e1cbd15 | |
parent | ce2a1e67f1738535b011a7b4bd42cc114b1d805f (diff) |
x86/fpu: Add debugging checks to all copy_kernel_to_*() functions
Copying from in-kernel FPU context buffers to FPU registers are
never supposed to fault.
Add debugging checks to copy_kernel_to_fxregs() and copy_kernel_to_fregs()
to double check this assumption.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Bobby Powers <bobbypowers@gmail.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | arch/x86/include/asm/fpu/internal.h | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h index e3bd93c84928..eb8fa0f9d279 100644 --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h | |||
@@ -143,14 +143,22 @@ static inline int copy_fxregs_to_user(struct fxregs_state __user *fx) | |||
143 | 143 | ||
144 | static inline int copy_kernel_to_fxregs(struct fxregs_state *fx) | 144 | static inline int copy_kernel_to_fxregs(struct fxregs_state *fx) |
145 | { | 145 | { |
146 | if (config_enabled(CONFIG_X86_32)) | 146 | int err; |
147 | return check_insn(fxrstor %[fx], "=m" (*fx), [fx] "m" (*fx)); | ||
148 | else if (config_enabled(CONFIG_AS_FXSAVEQ)) | ||
149 | return check_insn(fxrstorq %[fx], "=m" (*fx), [fx] "m" (*fx)); | ||
150 | 147 | ||
151 | /* See comment in copy_fxregs_to_kernel() below. */ | 148 | if (config_enabled(CONFIG_X86_32)) { |
152 | return check_insn(rex64/fxrstor (%[fx]), "=m" (*fx), [fx] "R" (fx), | 149 | err = check_insn(fxrstor %[fx], "=m" (*fx), [fx] "m" (*fx)); |
153 | "m" (*fx)); | 150 | } else { |
151 | if (config_enabled(CONFIG_AS_FXSAVEQ)) { | ||
152 | err = check_insn(fxrstorq %[fx], "=m" (*fx), [fx] "m" (*fx)); | ||
153 | } else { | ||
154 | /* See comment in copy_fxregs_to_kernel() below. */ | ||
155 | err = check_insn(rex64/fxrstor (%[fx]), "=m" (*fx), [fx] "R" (fx), "m" (*fx)); | ||
156 | } | ||
157 | } | ||
158 | /* Copying from a kernel buffer to FPU registers should never fail: */ | ||
159 | WARN_ON_FPU(err); | ||
160 | |||
161 | return err; | ||
154 | } | 162 | } |
155 | 163 | ||
156 | static inline int copy_user_to_fxregs(struct fxregs_state __user *fx) | 164 | static inline int copy_user_to_fxregs(struct fxregs_state __user *fx) |
@@ -167,7 +175,11 @@ static inline int copy_user_to_fxregs(struct fxregs_state __user *fx) | |||
167 | 175 | ||
168 | static inline int copy_kernel_to_fregs(struct fregs_state *fx) | 176 | static inline int copy_kernel_to_fregs(struct fregs_state *fx) |
169 | { | 177 | { |
170 | return check_insn(frstor %[fx], "=m" (*fx), [fx] "m" (*fx)); | 178 | int err = check_insn(frstor %[fx], "=m" (*fx), [fx] "m" (*fx)); |
179 | |||
180 | WARN_ON_FPU(err); | ||
181 | |||
182 | return err; | ||
171 | } | 183 | } |
172 | 184 | ||
173 | static inline int copy_user_to_fregs(struct fregs_state __user *fx) | 185 | static inline int copy_user_to_fregs(struct fregs_state __user *fx) |