|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v8 65/65] xen/wait: crash the domain if the saved stack is not this CPU's
check_wakeup_from_wait() copies the frames which __prepare_to_wait()
saved back to the absolute address they were taken from (wqv->esp), in
the stack the vCPU ran on when it went to wait. That is the stack it
runs on now only because the vCPU stayed pinned to the same pCPU, which
the function checks (VCPU_AFFINITY_WAIT), crashing the domain if the
pin was lost. Each pCPU's stack is at an address of its own (with
per-CPU stacks, at PCPU_STACK_VIRT()), so if anything else let the vCPU
resume elsewhere, the copy would write into another pCPU's stack, which
that pCPU may be using, and the vCPU would go on running on it; on the
page-tables of a cpu_stack vCPU, which map no other pCPU's stack there,
the copy would fault instead.
Check the address itself as well: crash the domain, as for a lost pin,
unless wqv->esp lies in the stack this CPU runs on
(ptr_on_current_stack(): one XOR and a test). The two failures share
the crash path.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: George Dunlap <gwd@xxxxxxxxxxxxxx>
---
Changes in v8:
- New in this version.
Changes since previously posted version ("x86: adventures in Address Space
Isolation", v2):
- New.
---
xen/common/wait.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/xen/common/wait.c b/xen/common/wait.c
index 2a12055f78..4e9145aa13 100644
--- a/xen/common/wait.c
+++ b/xen/common/wait.c
@@ -197,12 +197,19 @@ void check_wakeup_from_wait(void)
if ( unlikely(!(curr->affinity_broken & VCPU_AFFINITY_WAIT)) )
{
gdprintk(XENLOG_ERR, "vcpu affinity lost\n");
- domain_crash(curr->domain);
+ goto crash;
+ }
- /* Re-initiate scheduler and don't longjmp(). */
- raise_softirq(SCHEDULE_SOFTIRQ);
- for ( ; ; )
- do_softirq();
+ /*
+ * The frames go back to the address they were taken from, which must lie
+ * in the stack this CPU runs on, not in another CPU's.
+ */
+ if ( unlikely(!ptr_on_current_stack(wqv->esp)) )
+ {
+ gdprintk(XENLOG_ERR,
+ "saved stack pointer %p not on this CPU's stack\n",
+ wqv->esp);
+ goto crash;
}
/*
@@ -247,6 +254,14 @@ void check_wakeup_from_wait(void)
"c" ((char *)get_cpu_info() - (char *)wqv->esp)
: "memory" );
unreachable();
+
+ crash:
+ domain_crash(curr->domain);
+
+ /* Re-initiate scheduler and don't longjmp(). */
+ raise_softirq(SCHEDULE_SOFTIRQ);
+ for ( ; ; )
+ do_softirq();
}
#else /* !CONFIG_X86 */
--
2.56.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |