Skip to content

Commit abf0885

Browse files
dwindsorPeter Zijlstra
authored andcommitted
x86/uprobes: Keep shadow stack in sync for emulated CALLs
Uprobe CALL emulation updates the normal user stack, but not the CET user shadow stack. The subsequent RET then sees a stale shadow stack entry and raises #CP. Update the relative CALL emulation and XOL CALL fixup paths to keep the shadow stack in sync. Fixes: 488af8e ("x86/shstk: Wire in shadow stack interface") Signed-off-by: David Windsor <dwindsor@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Oleg Nesterov <oleg@redhat.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Jiri Olsa <jolsa@kernel.org> Link: https://patch.msgid.link/8b5b1c7407b98f31664ad7b6a6faf20d2d4a6cad.1782777969.git.dwindsor@gmail.com
1 parent 037a3c4 commit abf0885

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

arch/x86/kernel/uprobes.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,9 +1246,15 @@ static int default_post_xol_op(struct arch_uprobe *auprobe, struct pt_regs *regs
12461246
long correction = utask->vaddr - utask->xol_vaddr;
12471247
regs->ip += correction;
12481248
} else if (auprobe->defparam.fixups & UPROBE_FIX_CALL) {
1249+
unsigned long retaddr = utask->vaddr + auprobe->defparam.ilen;
1250+
int err;
1251+
12491252
regs->sp += sizeof_long(regs); /* Pop incorrect return address */
1250-
if (emulate_push_stack(regs, utask->vaddr + auprobe->defparam.ilen))
1253+
if (emulate_push_stack(regs, retaddr))
12511254
return -ERESTART;
1255+
err = shstk_update_last_frame(retaddr);
1256+
if (err)
1257+
return err;
12521258
}
12531259
/* popf; tell the caller to not touch TF */
12541260
if (auprobe->defparam.fixups & UPROBE_FIX_SETF)
@@ -1338,6 +1344,10 @@ static bool branch_emulate_op(struct arch_uprobe *auprobe, struct pt_regs *regs)
13381344
*/
13391345
if (emulate_push_stack(regs, new_ip))
13401346
return false;
1347+
if (shstk_push(new_ip) == -EFAULT) {
1348+
regs->sp += sizeof_long(regs);
1349+
return false;
1350+
}
13411351
} else if (!check_jmp_cond(auprobe, regs)) {
13421352
offs = 0;
13431353
}

0 commit comments

Comments
 (0)