git: 61b29720efed - stable/13 - amd64: centralize definitions of CS_SECURE and EFL_SECURE
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 10 Oct 2021 09:24:04 UTC
The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=61b29720efed21673e4777227e899eeb65c31078 commit 61b29720efed21673e4777227e899eeb65c31078 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2021-09-14 16:07:31 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2021-10-10 09:21:17 +0000 amd64: centralize definitions of CS_SECURE and EFL_SECURE (cherry picked from commit a42d362bb54af91d8b82dca086fa656f4624bae2) --- sys/amd64/amd64/machdep.c | 3 --- sys/amd64/ia32/ia32_reg.c | 3 --- sys/amd64/ia32/ia32_signal.c | 3 --- sys/amd64/include/frame.h | 5 +++++ sys/amd64/linux/linux_sysvec.c | 5 +---- sys/amd64/linux32/linux32_sysvec.c | 8 ++------ 6 files changed, 8 insertions(+), 19 deletions(-) diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 0c8234c9e917..da8a4f249e03 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -164,9 +164,6 @@ CTASSERT(PC_PTI_STACK_SZ * sizeof(register_t) >= 2 * sizeof(struct pti_frame) - extern u_int64_t hammer_time(u_int64_t, u_int64_t); -#define CS_SECURE(cs) (ISPL(cs) == SEL_UPL) -#define EFL_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0) - static void cpu_startup(void *); static void get_fpcontext(struct thread *td, mcontext_t *mcp, char *xfpusave, size_t xfpusave_len); diff --git a/sys/amd64/ia32/ia32_reg.c b/sys/amd64/ia32/ia32_reg.c index 0725936cf84d..f6333a65fb39 100644 --- a/sys/amd64/ia32/ia32_reg.c +++ b/sys/amd64/ia32/ia32_reg.c @@ -72,9 +72,6 @@ __FBSDID("$FreeBSD$"); #include <machine/pcb.h> #include <machine/cpufunc.h> -#define CS_SECURE(cs) (ISPL(cs) == SEL_UPL) -#define EFL_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0) - int fill_regs32(struct thread *td, struct reg32 *regs) { diff --git a/sys/amd64/ia32/ia32_signal.c b/sys/amd64/ia32/ia32_signal.c index c114cf1d240a..49b5797d68fd 100644 --- a/sys/amd64/ia32/ia32_signal.c +++ b/sys/amd64/ia32/ia32_signal.c @@ -85,9 +85,6 @@ __FBSDID("$FreeBSD$"); static void freebsd4_ia32_sendsig(sig_t, ksiginfo_t *, sigset_t *); #endif -#define CS_SECURE(cs) (ISPL(cs) == SEL_UPL) -#define EFL_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0) - static void ia32_get_fpcontext(struct thread *td, struct ia32_mcontext *mcp, char *xfpusave, size_t xfpusave_len) diff --git a/sys/amd64/include/frame.h b/sys/amd64/include/frame.h index f0a6fcf5bc9c..faf68a2008e4 100644 --- a/sys/amd64/include/frame.h +++ b/sys/amd64/include/frame.h @@ -47,4 +47,9 @@ struct pti_frame { register_t pti_ss; }; +#ifdef _KERNEL +#define CS_SECURE(cs) (ISPL(cs) == SEL_UPL) +#define EFL_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0) +#endif + #endif diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c index f8a06b08969e..28fac2ea7452 100644 --- a/sys/amd64/linux/linux_sysvec.c +++ b/sys/amd64/linux/linux_sysvec.c @@ -524,9 +524,7 @@ linux_rt_sigreturn(struct thread *td, struct linux_rt_sigreturn_args *args) * Corruption of the PSL_RF bit at worst causes one more or * one less debugger trap, so allowing it is fairly harmless. */ - -#define RFLAG_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0) - if (!RFLAG_SECURE(rflags & ~PSL_RF, regs->tf_rflags & ~PSL_RF)) { + if (!EFL_SECURE(rflags & ~PSL_RF, regs->tf_rflags & ~PSL_RF)) { printf("linux_rt_sigreturn: rflags = 0x%lx\n", rflags); return (EINVAL); } @@ -536,7 +534,6 @@ linux_rt_sigreturn(struct thread *td, struct linux_rt_sigreturn_args *args) * hardware check for invalid selectors, excess privilege in * other selectors, invalid %eip's and invalid %esp's. */ -#define CS_SECURE(cs) (ISPL(cs) == SEL_UPL) if (!CS_SECURE(context->sc_cs)) { printf("linux_rt_sigreturn: cs = 0x%x\n", context->sc_cs); ksiginfo_init_trap(&ksi); diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c index b20961e66b6a..9a8f86ecce10 100644 --- a/sys/amd64/linux32/linux32_sysvec.c +++ b/sys/amd64/linux32/linux32_sysvec.c @@ -497,9 +497,8 @@ linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args) return (EFAULT); /* Check for security violations. */ -#define EFLAGS_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0) eflags = frame.sf_sc.sc_eflags; - if (!EFLAGS_SECURE(eflags, regs->tf_rflags)) + if (!EFL_SECURE(eflags, regs->tf_rflags)) return(EINVAL); /* @@ -507,7 +506,6 @@ linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args) * hardware check for invalid selectors, excess privilege in * other selectors, invalid %eip's and invalid %esp's. */ -#define CS_SECURE(cs) (ISPL(cs) == SEL_UPL) if (!CS_SECURE(frame.sf_sc.sc_cs)) { ksiginfo_init_trap(&ksi); ksi.ksi_signo = SIGBUS; @@ -580,9 +578,8 @@ linux_rt_sigreturn(struct thread *td, struct linux_rt_sigreturn_args *args) context = &uc.uc_mcontext; /* Check for security violations. */ -#define EFLAGS_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0) eflags = context->sc_eflags; - if (!EFLAGS_SECURE(eflags, regs->tf_rflags)) + if (!EFL_SECURE(eflags, regs->tf_rflags)) return(EINVAL); /* @@ -590,7 +587,6 @@ linux_rt_sigreturn(struct thread *td, struct linux_rt_sigreturn_args *args) * hardware check for invalid selectors, excess privilege in * other selectors, invalid %eip's and invalid %esp's. */ -#define CS_SECURE(cs) (ISPL(cs) == SEL_UPL) if (!CS_SECURE(context->sc_cs)) { ksiginfo_init_trap(&ksi); ksi.ksi_signo = SIGBUS;