Skip to content

Commit 6ddd115

Browse files
Quentin Casasnovassashalevin
authored andcommitted
x86/fpu/xsaves: Fix improper uses of __ex_table
commit 06c8173 upstream. 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: 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> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
1 parent ce5dd33 commit 6ddd115

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
@@ -81,18 +81,15 @@ static inline int xsave_state_booting(struct xsave_struct *fx, u64 mask)
8181
if (boot_cpu_has(X86_FEATURE_XSAVES))
8282
asm volatile("1:"XSAVES"\n\t"
8383
"2:\n\t"
84-
: : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
84+
xstate_fault
85+
: "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
8586
: "memory");
8687
else
8788
asm volatile("1:"XSAVE"\n\t"
8889
"2:\n\t"
89-
: : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
90+
xstate_fault
91+
: "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
9092
: "memory");
91-
92-
asm volatile(xstate_fault
93-
: "0" (0)
94-
: "memory");
95-
9693
return err;
9794
}
9895

@@ -111,18 +108,15 @@ static inline int xrstor_state_booting(struct xsave_struct *fx, u64 mask)
111108
if (boot_cpu_has(X86_FEATURE_XSAVES))
112109
asm volatile("1:"XRSTORS"\n\t"
113110
"2:\n\t"
114-
: : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
111+
xstate_fault
112+
: "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
115113
: "memory");
116114
else
117115
asm volatile("1:"XRSTOR"\n\t"
118116
"2:\n\t"
119-
: : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
117+
xstate_fault
118+
: "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
120119
: "memory");
121-
122-
asm volatile(xstate_fault
123-
: "0" (0)
124-
: "memory");
125-
126120
return err;
127121
}
128122

@@ -148,9 +142,9 @@ static inline int xsave_state(struct xsave_struct *fx, u64 mask)
148142
*/
149143
alternative_input_2(
150144
"1:"XSAVE,
151-
"1:"XSAVEOPT,
145+
XSAVEOPT,
152146
X86_FEATURE_XSAVEOPT,
153-
"1:"XSAVES,
147+
XSAVES,
154148
X86_FEATURE_XSAVES,
155149
[fx] "D" (fx), "a" (lmask), "d" (hmask) :
156150
"memory");
@@ -177,7 +171,7 @@ static inline int xrstor_state(struct xsave_struct *fx, u64 mask)
177171
*/
178172
alternative_input(
179173
"1: " XRSTOR,
180-
"1: " XRSTORS,
174+
XRSTORS,
181175
X86_FEATURE_XSAVES,
182176
"D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
183177
: "memory");

0 commit comments

Comments
 (0)