From: kettenis Date: Sun, 16 Apr 2023 10:14:59 +0000 (+0000) Subject: Clear BTYPE bits when setting up a signal handler and when handling a X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=98a8a58a8f51400acf32a042cfa61b62c11317b4;p=openbsd Clear BTYPE bits when setting up a signal handler and when handling a PT_CONTINUE ptrace(2) request. Otherwise we would trap if userland was interrupted at a point where it is doing an indirect branch that has set the bits but before it has executed the BTI instruction at the branch target. The PT_SETREGS request may need similar treatment, at least when the PC is changed. But Linux doesn't do this and debuggers might want full control over the BTYPE bits. So leave this alone for now. ok guenther@ --- diff --git a/sys/arch/arm64/arm64/process_machdep.c b/sys/arch/arm64/arm64/process_machdep.c index 8703a9178ae..26671a70093 100644 --- a/sys/arch/arm64/arm64/process_machdep.c +++ b/sys/arch/arm64/arm64/process_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: process_machdep.c,v 1.6 2022/01/01 18:52:36 kettenis Exp $ */ +/* $OpenBSD: process_machdep.c,v 1.7 2023/04/16 10:14:59 kettenis Exp $ */ /* * Copyright (c) 2014 Patrick Wildt * @@ -128,7 +128,10 @@ int process_set_pc(struct proc *p, caddr_t addr) { struct trapframe *tf = p->p_addr->u_pcb.pcb_tf; + tf->tf_elr = (uint64_t)addr; + tf->tf_spsr &= ~PSR_BTYPE; + return (0); } diff --git a/sys/arch/arm64/arm64/sig_machdep.c b/sys/arch/arm64/arm64/sig_machdep.c index 69006f72827..e0368ff2635 100644 --- a/sys/arch/arm64/arm64/sig_machdep.c +++ b/sys/arch/arm64/arm64/sig_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sig_machdep.c,v 1.8 2021/10/06 15:46:03 claudio Exp $ */ +/* $OpenBSD: sig_machdep.c,v 1.9 2023/04/16 10:14:59 kettenis Exp $ */ /* * Copyright (c) 1990 The Regents of the University of California. @@ -157,6 +157,7 @@ sendsig(sig_t catcher, int sig, sigset_t mask, const siginfo_t *ksip, tf->tf_sp = (register_t)fp; tf->tf_elr = p->p_p->ps_sigcode; + tf->tf_spsr &= ~PSR_BTYPE; return 0; } diff --git a/sys/arch/arm64/include/armreg.h b/sys/arch/arm64/include/armreg.h index bffe8cccacf..7c5be0c6da9 100644 --- a/sys/arch/arm64/include/armreg.h +++ b/sys/arch/arm64/include/armreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: armreg.h,v 1.27 2023/03/27 19:02:48 kettenis Exp $ */ +/* $OpenBSD: armreg.h,v 1.28 2023/04/16 10:14:59 kettenis Exp $ */ /*- * Copyright (c) 2013, 2014 Andrew Turner * Copyright (c) 2015 The FreeBSD Foundation @@ -673,6 +673,7 @@ #define PSR_I 0x00000080 #define PSR_A 0x00000100 #define PSR_D 0x00000200 +#define PSR_BTYPE 0x00000c00 #define PSR_SSBS 0x00001000 #define PSR_IL 0x00100000 #define PSR_SS 0x00200000