Skip to content

Commit b1c2cb8

Browse files
committed
x86/xen: use new hypercall functions instead of hypercall page
Call the Xen hypervisor via the new xen_hypercall_func static-call instead of the hypercall page. This is part of XSA-466 / CVE-2024-53241. Reported-by: Andrew Cooper <[email protected]> Signed-off-by: Juergen Gross <[email protected]> Co-developed-by: Peter Zijlstra <[email protected]> Co-developed-by: Josh Poimboeuf <[email protected]>
1 parent b4845bb commit b1c2cb8

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

arch/x86/include/asm/xen/hypercall.h

+20-13
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@
3939
#include <linux/string.h>
4040
#include <linux/types.h>
4141
#include <linux/pgtable.h>
42+
#include <linux/instrumentation.h>
4243

4344
#include <trace/events/xen.h>
4445

46+
#include <asm/alternative.h>
4547
#include <asm/page.h>
4648
#include <asm/smap.h>
4749
#include <asm/nospec-branch.h>
@@ -91,9 +93,17 @@ extern struct { char _entry[32]; } hypercall_page[];
9193
void xen_hypercall_func(void);
9294
DECLARE_STATIC_CALL(xen_hypercall, xen_hypercall_func);
9395

94-
#define __HYPERCALL "call hypercall_page+%c[offset]"
95-
#define __HYPERCALL_ENTRY(x) \
96-
[offset] "i" (__HYPERVISOR_##x * sizeof(hypercall_page[0]))
96+
#ifdef MODULE
97+
#define __ADDRESSABLE_xen_hypercall
98+
#else
99+
#define __ADDRESSABLE_xen_hypercall __ADDRESSABLE_ASM_STR(__SCK__xen_hypercall)
100+
#endif
101+
102+
#define __HYPERCALL \
103+
__ADDRESSABLE_xen_hypercall \
104+
"call __SCT__xen_hypercall"
105+
106+
#define __HYPERCALL_ENTRY(x) "a" (x)
97107

98108
#ifdef CONFIG_X86_32
99109
#define __HYPERCALL_RETREG "eax"
@@ -151,7 +161,7 @@ DECLARE_STATIC_CALL(xen_hypercall, xen_hypercall_func);
151161
__HYPERCALL_0ARG(); \
152162
asm volatile (__HYPERCALL \
153163
: __HYPERCALL_0PARAM \
154-
: __HYPERCALL_ENTRY(name) \
164+
: __HYPERCALL_ENTRY(__HYPERVISOR_ ## name) \
155165
: __HYPERCALL_CLOBBER0); \
156166
(type)__res; \
157167
})
@@ -162,7 +172,7 @@ DECLARE_STATIC_CALL(xen_hypercall, xen_hypercall_func);
162172
__HYPERCALL_1ARG(a1); \
163173
asm volatile (__HYPERCALL \
164174
: __HYPERCALL_1PARAM \
165-
: __HYPERCALL_ENTRY(name) \
175+
: __HYPERCALL_ENTRY(__HYPERVISOR_ ## name) \
166176
: __HYPERCALL_CLOBBER1); \
167177
(type)__res; \
168178
})
@@ -173,7 +183,7 @@ DECLARE_STATIC_CALL(xen_hypercall, xen_hypercall_func);
173183
__HYPERCALL_2ARG(a1, a2); \
174184
asm volatile (__HYPERCALL \
175185
: __HYPERCALL_2PARAM \
176-
: __HYPERCALL_ENTRY(name) \
186+
: __HYPERCALL_ENTRY(__HYPERVISOR_ ## name) \
177187
: __HYPERCALL_CLOBBER2); \
178188
(type)__res; \
179189
})
@@ -184,7 +194,7 @@ DECLARE_STATIC_CALL(xen_hypercall, xen_hypercall_func);
184194
__HYPERCALL_3ARG(a1, a2, a3); \
185195
asm volatile (__HYPERCALL \
186196
: __HYPERCALL_3PARAM \
187-
: __HYPERCALL_ENTRY(name) \
197+
: __HYPERCALL_ENTRY(__HYPERVISOR_ ## name) \
188198
: __HYPERCALL_CLOBBER3); \
189199
(type)__res; \
190200
})
@@ -195,7 +205,7 @@ DECLARE_STATIC_CALL(xen_hypercall, xen_hypercall_func);
195205
__HYPERCALL_4ARG(a1, a2, a3, a4); \
196206
asm volatile (__HYPERCALL \
197207
: __HYPERCALL_4PARAM \
198-
: __HYPERCALL_ENTRY(name) \
208+
: __HYPERCALL_ENTRY(__HYPERVISOR_ ## name) \
199209
: __HYPERCALL_CLOBBER4); \
200210
(type)__res; \
201211
})
@@ -209,12 +219,9 @@ xen_single_call(unsigned int call,
209219
__HYPERCALL_DECLS;
210220
__HYPERCALL_5ARG(a1, a2, a3, a4, a5);
211221

212-
if (call >= PAGE_SIZE / sizeof(hypercall_page[0]))
213-
return -EINVAL;
214-
215-
asm volatile(CALL_NOSPEC
222+
asm volatile(__HYPERCALL
216223
: __HYPERCALL_5PARAM
217-
: [thunk_target] "a" (&hypercall_page[call])
224+
: __HYPERCALL_ENTRY(call)
218225
: __HYPERCALL_CLOBBER5);
219226

220227
return (long)__res;

0 commit comments

Comments
 (0)