Skip to content

Commit 06c8173

Browse files
Quentin Casasnovasingomolnar
authored andcommitted
x86/fpu/xsaves: Fix improper uses of __ex_table
Commit: f31a9f7 ("x86/xsaves: Use xsaves/xrstors to save and restore xsave area") introduced alternative instructions for XSAVES/XRSTORS and commit: adb9d52 ("x86/xsaves: Add xsaves and xrstors support for booting time") added support for the XSAVES/XRSTORS instructions at boot time. Unfortunately both failed to properly protect them against faulting: The 'xstate_fault' macro will use the closest label named '1' backward and that ends up in the .altinstr_replacement section rather than in .text. This means that the kernel will never find in the __ex_table the .text address where this instruction might fault, leading to serious problems if userspace manages to trigger the fault. Signed-off-by: Quentin Casasnovas <quentin.casasnovas@oracle.com> Signed-off-by: Jamie Iles <jamie.iles@oracle.com> [ Improved the changelog, fixed some whitespace noise. ] Acked-by: Borislav Petkov <bp@alien8.de> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Cc: <stable@vger.kernel.org> Cc: Allan Xavier <mr.a.xavier@gmail.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Thomas Gleixner <tglx@linutronix.de> Fixes: adb9d52 ("x86/xsaves: Add xsaves and xrstors support for booting time") Fixes: f31a9f7 ("x86/xsaves: Use xsaves/xrstors to save and restore xsave area") Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 9ab6eb5 commit 06c8173

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

‎arch/x86/include/asm/xsave.h‎

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,15 @@ static inline int xsave_state_booting(struct xsave_struct *fx, u64 mask)
8282
if (boot_cpu_has(X86_FEATURE_XSAVES))
8383
asm volatile("1:"XSAVES"\n\t"
8484
"2:\n\t"
85-
: : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
85+
xstate_fault
86+
: "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
8687
: "memory");
8788
else
8889
asm volatile("1:"XSAVE"\n\t"
8990
"2:\n\t"
90-
: : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
91+
xstate_fault
92+
: "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
9193
: "memory");
92-
93-
asm volatile(xstate_fault
94-
: "0" (0)
95-
: "memory");
96-
9794
return err;
9895
}
9996

@@ -112,18 +109,15 @@ static inline int xrstor_state_booting(struct xsave_struct *fx, u64 mask)
112109
if (boot_cpu_has(X86_FEATURE_XSAVES))
113110
asm volatile("1:"XRSTORS"\n\t"
114111
"2:\n\t"
115-
: : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
112+
xstate_fault
113+
: "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
116114
: "memory");
117115
else
118116
asm volatile("1:"XRSTOR"\n\t"
119117
"2:\n\t"
120-
: : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
118+
xstate_fault
119+
: "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
121120
: "memory");
122-
123-
asm volatile(xstate_fault
124-
: "0" (0)
125-
: "memory");
126-
127121
return err;
128122
}
129123

@@ -149,9 +143,9 @@ static inline int xsave_state(struct xsave_struct *fx, u64 mask)
149143
*/
150144
alternative_input_2(
151145
"1:"XSAVE,
152-
"1:"XSAVEOPT,
146+
XSAVEOPT,
153147
X86_FEATURE_XSAVEOPT,
154-
"1:"XSAVES,
148+
XSAVES,
155149
X86_FEATURE_XSAVES,
156150
[fx] "D" (fx), "a" (lmask), "d" (hmask) :
157151
"memory");
@@ -178,7 +172,7 @@ static inline int xrstor_state(struct xsave_struct *fx, u64 mask)
178172
*/
179173
alternative_input(
180174
"1: " XRSTOR,
181-
"1: " XRSTORS,
175+
XRSTORS,
182176
X86_FEATURE_XSAVES,
183177
"D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
184178
: "memory");

0 commit comments

Comments
 (0)