Skip to content

Commit 3f4aa1c

Browse files
author
Francesco Lavra
committed
x86 restore_ucontext(): Protect against invalid pointer to extended frame
A signal handler can modify the pointer to the floating-point register frame in the thread context. If a modified pointer is invalid, the kernel crashes; if a modified pointer points to kernel memory, kernel info is leaked to the user program. To prevent these issues, avoid copying from non-legitimate addresses when restoring the thread context after a signal handler.
1 parent 30f465a commit 3f4aa1c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/x86_64/unix_machine.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,13 @@ void restore_ucontext(struct ucontext * uctx, thread t)
202202
else
203203
f[FRAME_CS] &= ~1;
204204
t->signal_mask = normalize_signal_mask(mcontext->oldmask);
205-
if (mcontext->fpstate)
205+
if (validate_user_memory(mcontext->fpstate, extended_frame_size, false)) {
206+
context ctx = get_current_context(current_cpu());
207+
if (context_set_err(ctx))
208+
return;
206209
runtime_memcpy(frame_extended(t->context.frame), mcontext->fpstate, extended_frame_size);
210+
context_clear_err(ctx);
211+
}
207212
}
208213

209214
void reg_copy_out(struct core_regs *r, thread t)

0 commit comments

Comments
 (0)