Index: sys/arm64/arm64/elf_machdep.c =================================================================== --- sys/arm64/arm64/elf_machdep.c +++ sys/arm64/arm64/elf_machdep.c @@ -55,20 +55,26 @@ #include #include "linker_if.h" +#include "vdso_offsets.h" u_long __read_frequently elf_hwcap; u_long __read_frequently elf_hwcap2; struct arm64_addr_mask elf64_addr_mask; +extern const char _binary_elf_vdso_so_1_start[]; +extern const char _binary_elf_vdso_so_1_end[]; +extern char _binary_elf_vdso_so_1_size; + static struct sysentvec elf64_freebsd_sysvec = { .sv_size = SYS_MAXSYSCALL, .sv_table = sysent, .sv_transtrap = NULL, .sv_fixup = __elfN(freebsd_fixup), .sv_sendsig = sendsig, - .sv_sigcode = sigcode, - .sv_szsigcode = &szsigcode, + .sv_sigcode = _binary_elf_vdso_so_1_start, + .sv_szsigcode = (int *)&_binary_elf_vdso_so_1_size, + .sv_sigcodeoff = VDSO_SIGCODE_OFFSET, .sv_name = "FreeBSD ELF64", .sv_coredump = __elfN(coredump), .sv_elf_core_osabi = ELFOSABI_FREEBSD, @@ -88,7 +94,7 @@ .sv_fixlimit = NULL, .sv_maxssiz = NULL, .sv_flags = SV_SHP | SV_TIMEKEEP | SV_ABI_FREEBSD | SV_LP64 | - SV_ASLR | SV_RNG_SEED_VER, + SV_ASLR | SV_RNG_SEED_VER | SV_DSO_SIG, .sv_set_syscall_retval = cpu_set_syscall_retval, .sv_fetch_syscall_args = cpu_fetch_syscall_args, .sv_syscallnames = syscallnames, Index: sys/arm64/arm64/genassym.c =================================================================== --- sys/arm64/arm64/genassym.c +++ sys/arm64/arm64/genassym.c @@ -67,6 +67,9 @@ ASSYM(PCB_FLAGS, offsetof(struct pcb, pcb_flags)); ASSYM(SF_UC, offsetof(struct sigframe, sf_uc)); +ASSYM(UC_X, offsetof(ucontext_t, uc_mcontext.mc_gpregs.gp_x)); +ASSYM(UC_LR, offsetof(ucontext_t, uc_mcontext.mc_gpregs.gp_lr)); +ASSYM(UC_SP, offsetof(ucontext_t, uc_mcontext.mc_gpregs.gp_sp)); ASSYM(TD_PROC, offsetof(struct thread, td_proc)); ASSYM(TD_PCB, offsetof(struct thread, td_pcb)); Index: sys/arm64/arm64/sigtramp.S =================================================================== --- sys/arm64/arm64/sigtramp.S +++ sys/arm64/arm64/sigtramp.S @@ -30,7 +30,50 @@ #include #include -ENTRY(sigcode) +.macro cfi_offset reg=0 + .cfi_offset x\reg, SF_UC + UC_X + \reg * 8 +.endm + + .text +/* + * Signal trampoline, mapped as vdso into shared page. + */ +ENTRY(__vdso_sigcode) + .cfi_signal_frame + .cfi_def_cfa sp, 0 + cfi_offset 0 + cfi_offset 1 + cfi_offset 2 + cfi_offset 3 + cfi_offset 4 + cfi_offset 5 + cfi_offset 6 + cfi_offset 7 + cfi_offset 8 + cfi_offset 9 + cfi_offset 10 + cfi_offset 11 + cfi_offset 12 + cfi_offset 13 + cfi_offset 14 + cfi_offset 15 + cfi_offset 16 + cfi_offset 17 + cfi_offset 18 + cfi_offset 19 + cfi_offset 20 + cfi_offset 21 + cfi_offset 22 + cfi_offset 23 + cfi_offset 24 + cfi_offset 25 + cfi_offset 26 + cfi_offset 27 + cfi_offset 28 + cfi_offset 29 + .cfi_offset lr, SF_UC + UC_LR + .cfi_offset sp, SF_UC + UC_SP + blr x8 mov x0, sp add x0, x0, #SF_UC @@ -44,13 +87,6 @@ svc 0 b 1b -END(sigcode) - /* This may be copied to the stack, keep it 16-byte aligned */ - .align 3 -esigcode: - - .data - .align 3 - .global szsigcode -szsigcode: - .quad esigcode - sigcode +END(__vdso_sigcode) + + .section .note.GNU-stack,"",%progbits Index: sys/conf/files.arm64 =================================================================== --- sys/conf/files.arm64 +++ sys/conf/files.arm64 @@ -4,6 +4,17 @@ ## Kernel ## +# The long compile-with and dependency lines are required because of +# limitations in config: backslash-newline doesn't work in strings, and +# dependency lines other than the first are silently ignored. +# +# +elf-vdso.so.o standard \ + dependency "$S/arm64/arm64/sigtramp.S assym.inc $S/tools/arm64_vdso.sh" \ + compile-with "env AWK='${AWK}' NM='${NM}' LD='${LD}' CC='${CC}' DEBUG='${DEBUG}' OBJCOPY='${OBJCOPY}' ELFDUMP='${ELFDUMP}' S='${S}' sh $S/tools/arm64_vdso.sh" \ + no-implicit-rule before-depend \ + clean "elf-vdso.so.o elf-vdso.so.1 vdso_offsets.h sigtramp.pico" + kern/msi_if.m optional intrng kern/pic_if.m optional intrng kern/subr_devmap.c standard @@ -70,7 +81,6 @@ compile-with "${NORMAL_C:N-mbranch-protection*}" arm64/arm64/pmap.c standard arm64/arm64/ptrace_machdep.c standard -arm64/arm64/sigtramp.S standard arm64/arm64/stack_machdep.c optional ddb | stack arm64/arm64/support.S standard arm64/arm64/swtch.S standard Index: sys/conf/vdso_arm64.ldscript =================================================================== --- /dev/null +++ sys/conf/vdso_arm64.ldscript @@ -0,0 +1,89 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2021 The FreeBSD Foundation + * + * This software was developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Linker script for amd64 vdso. + */ + +PHDRS +{ + text PT_LOAD FILEHDR PHDRS FLAGS(5); /* PF_R|PF_X */ + dynamic PT_DYNAMIC FLAGS(5); + eh_frame_hdr PT_GNU_EH_FRAME FLAGS(5); +} + +SECTIONS +{ + . = . + SIZEOF_HEADERS; + + .hash : { *(.hash) } :text + .gnu.hash : { *(.gnu.hash) } :text + .dynsym : { *(.dynsym) } :text + .dynstr : { *(.dynstr) } :text + .gnu.version : { *(.gnu.version) } :text + .gnu.version_d : { *(.gnu.version_d) } :text + .gnu.version_r : { *(.gnu.version_r) } :text + .eh_frame_hdr : { *(.eh_frame_hdr) } :text :eh_frame_hdr + .eh_frame : { KEEP (*(.eh_frame)) } :text + .dynamic : { *(.dynamic) } :text :dynamic + .rodata : { *(.rodata*) } :text + .data : { + *(.got.plt) *(.got) + } :text + /DISCARD/ /* .data */: { + *(.data*) + *(.sdata*) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + *(.ctors) + *(.dtors) + *(.jcr) + *(.init_array) + *(.init) + *(.fini) + *(.debug*) + *(.comment) + } + + . = ALIGN(0x10); + .text : { *(.text .text*) } :text =0xd420d420 +} + +VERSION +{ + FBSD_1.7 { + global: + __vdso_sigcode; + local: + *; + }; +} Index: sys/kern/imgact_elf.c =================================================================== --- sys/kern/imgact_elf.c +++ sys/kern/imgact_elf.c @@ -129,7 +129,7 @@ nxstack, CTLFLAG_RW, &__elfN(nxstack), 0, __XSTRING(__CONCAT(ELF, __ELF_WORD_SIZE)) ": enable non-executable stack"); -#if defined(__amd64__) +#if defined(__aarch64__) || defined(__amd64__) static int __elfN(vdso) = 1; SYSCTL_INT(__CONCAT(_kern_elf, __ELF_WORD_SIZE), OID_AUTO, vdso, CTLFLAG_RWTUN, &__elfN(vdso), 0, Index: sys/tools/arm64_vdso.sh =================================================================== --- /dev/null +++ sys/tools/arm64_vdso.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 The FreeBSD Foundation +# All rights reserved. +# +# This software was developed by Konstantin Belousov +# under sponsorship from the FreeBSD Foundation. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +ARCH=arm64 +SUBDIR=arm64 +COMPAT= +TARGET= +SIGTRAMP_ASM=sigtramp +CFLAGS= + +. $(dirname $0)/vdso.sh + Index: sys/tools/vdso.sh =================================================================== --- sys/tools/vdso.sh +++ sys/tools/vdso.sh @@ -67,7 +67,7 @@ "${S}"/tools/vdso_wrap.S case "${ARCH}${TARGET}" in -amd64) +amd64|arm64) ${NM} -D elf-vdso${COMPAT}.so.1 | \ ${AWK} '/__vdso_sigcode/{printf "#define VDSO_SIGCODE_OFFSET 0x%s",$1}' \ >vdso_offsets.h