x86: Support for CET Indirect Branch Tracking
v3 cover x86: Support for CET Indirect Branch Tracking
To avoid spamming everyone, I have only re-sent patches with changes in v3.
CET Indirect Branch Tracking is a hardware feature designed to protect against forward-edge control flow hijacking (Call/Jump oriented programming), and is a companion feature to CET Shadow Stacks added in Xen 4.14.
Patches 1 thru 5 are prerequisites. Patches 6 thru 59 are fairly mechanical annotations of function pointer targets. Patches 60 thru 70 are the final enablement of CET-IBT.
This series functions correctly with GCC 9 and later, although an experimental GCC patch is required to get more helpful typechecking at build time. A container with this fix has been added to CI.
Tested on a TigerLake NUC by me, and by Marek also.
CI pipelines:
https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/476819536
https://cirrus-ci.com/build/4634902334275584
Andrew Cooper (67):
xen/sort: Switch to an extern inline implementation xen/xsm: Move {do,compat}_flask_op() declarations into a header x86/kexec: Annotate embedded data with ELF metadata
x86: Introduce support for CET-IBT
xen: CFI hardening for x86 hypercalls
xen: CFI hardening for custom_param()
xen: CFI hardening for __initcall()
xen: CFI hardening for notifier callbacks
xen: CFI hardening for acpi_table_parse()
xen: CFI hardening for continue_hypercall_on_cpu()
xen: CFI hardening for init_timer()
xen: CFI hardening for call_rcu()
xen: CFI hardening for IPIs
xen: CFI hardening for open_softirq()
xsm/flask/ss: CFI hardening
xsm: CFI hardening
xen/sched: CFI hardening
xen/evtchn: CFI hardening
xen/hypfs: CFI hardening
xen/tasklet: CFI hardening
xen/keyhandler: CFI hardening
xen/vpci: CFI hardening
xen/decompress: CFI hardening
xen/iommu: CFI hardening
xen/video: CFI hardening
xen/console: CFI hardening
xen/misc: CFI hardening
x86: CFI hardening for request_irq()
x86/hvm: CFI hardening for hvm_funcs
x86/hvm: CFI hardening for device emulation
x86/emul: CFI hardening
x86/ucode: CFI hardening
x86/power: CFI hardening
x86/apic: CFI hardening
x86/nmi: CFI hardening
x86/mtrr: CFI hardening
x86/idle: CFI hardening
x86/quirks: CFI hardening
x86/hvmsave: CFI hardening
x86/mce: CFI hardening
x86/pmu: CFI hardening
x86/cpu: CFI hardening
x86/guest: CFI hardening
x86/logdirty: CFI hardening
x86/shadow: CFI hardening
x86/hap: CFI hardening
x86/p2m: CFI hardening
x86/irq: CFI hardening
x86/apei: CFI hardening
x86/psr: CFI hardening
x86/dpci: CFI hardening
x86/pt: CFI hardening
x86/time: CFI hardening
x86/misc: CFI hardening
x86/stack: CFI hardening
x86/bugframe: CFI hardening
x86: Use control flow typechecking where possible x86/setup: Read CR4 earlier in __start_xen() x86/alternatives: Clear CR4.CET when clearing CR0.WP x86/traps: Rework write_stub_trampoline() to not hardcode the jmp
x86: Introduce helpers/checks for endbr64 instructions x86/emul: Update emulation stubs to be CET-IBT compatible x86/entry: Make syscall/sysenter entrypoints CET-IBT compatible x86/entry: Make IDT entrypoints CET-IBT compatible x86/setup: Rework MSR_S_CET handling for CET-IBT x86/efi: Disable CET-IBT around Runtime Services calls
x86: Enable CET Indirect Branch Tracking
Juergen Gross (2):
x86/pv-shim: Don't modify the hypercall table
x86: Don't use the hypercall table for calling compat hypercalls
Marek Marczykowski-Górecki (1):
x86: Build check for embedded endbr64 instructions
Config.mk | 1 - README | 1 + automation/build/debian/buster-gcc-ibt.dockerfile | 66 ++++ automation/gitlab-ci/build.yaml | 6 + automation/scripts/containerize | 1 + docs/misc/xen-command-line.pandoc | 16 +- tools/firmware/Makefile | 2 + tools/libs/guest/xg_dom_decompress_unsafe.h | 2 + tools/tests/x86_emulator/x86-emulate.h | 2 + xen/arch/arm/bootfdt.c | 9 +- xen/arch/arm/io.c | 9 +- xen/arch/x86/Kconfig | 17 + xen/arch/x86/Makefile | 6 + xen/arch/x86/acpi/boot.c | 24 +- xen/arch/x86/acpi/cpu_idle.c | 43 ++- xen/arch/x86/acpi/cpufreq/cpufreq.c | 24 +- xen/arch/x86/acpi/cpufreq/powernow.c | 21 +- xen/arch/x86/acpi/cpuidle_menu.c | 6 +- xen/arch/x86/acpi/lib.c | 2 +- xen/arch/x86/acpi/power.c | 4 +- xen/arch/x86/acpi/wakeup_prot.S | 38 +- xen/arch/x86/alternative.c | 13 +- xen/arch/x86/apic.c | 12 +- xen/arch/x86/arch.mk | 7 + xen/arch/x86/boot/x86_64.S | 30 +- xen/arch/x86/compat.c | 21 +- xen/arch/x86/configs/pvshim_defconfig | 1 + xen/arch/x86/cpu/amd.c | 8 +- xen/arch/x86/cpu/centaur.c | 2 +- xen/arch/x86/cpu/common.c | 3 +- xen/arch/x86/cpu/cpu.h | 2 +- xen/arch/x86/cpu/hygon.c | 2 +- xen/arch/x86/cpu/intel.c | 6 +- xen/arch/x86/cpu/mcheck/amd_nonfatal.c | 4 +- xen/arch/x86/cpu/mcheck/mce.c | 22 +- xen/arch/x86/cpu/mcheck/mce.h | 2 +- xen/arch/x86/cpu/mcheck/mce_amd.c | 9 +- xen/arch/x86/cpu/mcheck/mce_amd.h | 4 +- xen/arch/x86/cpu/mcheck/mce_intel.c | 49 ++- xen/arch/x86/cpu/mcheck/non-fatal.c | 6 +- xen/arch/x86/cpu/mcheck/vmce.c | 4 +- xen/arch/x86/cpu/microcode/amd.c | 9 +- xen/arch/x86/cpu/microcode/core.c | 15 +- xen/arch/x86/cpu/microcode/intel.c | 10 +- xen/arch/x86/cpu/mtrr/generic.c | 20 +- xen/arch/x86/cpu/mtrr/main.c | 4 +- xen/arch/x86/cpu/mtrr/mtrr.h | 8 +- xen/arch/x86/cpu/mwait-idle.c | 12 +- xen/arch/x86/cpu/shanghai.c | 2 +- xen/arch/x86/cpu/vpmu.c | 13 +- xen/arch/x86/cpu/vpmu_amd.c | 16 +- xen/arch/x86/cpu/vpmu_intel.c | 16 +- xen/arch/x86/cpuid.c | 8 +- xen/arch/x86/crash.c | 7 +- xen/arch/x86/dmi_scan.c | 10 +- xen/arch/x86/dom0_build.c | 8 +- xen/arch/x86/domain.c | 16 +- xen/arch/x86/emul-i8254.c | 14 +- xen/arch/x86/extable.c | 18 +- xen/arch/x86/genapic/bigsmp.c | 4 +- xen/arch/x86/genapic/delivery.c | 12 +- xen/arch/x86/genapic/probe.c | 2 +- xen/arch/x86/genapic/x2apic.c | 18 +- xen/arch/x86/guest/hyperv/hyperv.c | 10 +- xen/arch/x86/guest/xen/xen.c | 15 +- xen/arch/x86/hpet.c | 29 +- xen/arch/x86/hvm/dm.c | 5 +- xen/arch/x86/hvm/dom0_build.c | 16 +- xen/arch/x86/hvm/emulate.c | 93 +++-- xen/arch/x86/hvm/hpet.c | 12 +- xen/arch/x86/hvm/hvm.c | 47 +-- xen/arch/x86/hvm/hypercall.c | 5 +- xen/arch/x86/hvm/intercept.c | 28 +- xen/arch/x86/hvm/io.c | 38 +- xen/arch/x86/hvm/ioreq.c | 2 +- xen/arch/x86/hvm/irq.c | 16 +- xen/arch/x86/hvm/mtrr.c | 8 +- xen/arch/x86/hvm/nestedhvm.c | 6 +- xen/arch/x86/hvm/pmtimer.c | 10 +- xen/arch/x86/hvm/quirks.c | 4 +- xen/arch/x86/hvm/rtc.c | 18 +- xen/arch/x86/hvm/stdvga.c | 19 +- xen/arch/x86/hvm/svm/nestedsvm.c | 22 +- xen/arch/x86/hvm/svm/svm.c | 404 +++++++++++----------- xen/arch/x86/hvm/svm/vmcb.c | 2 +- xen/arch/x86/hvm/vioapic.c | 12 +- xen/arch/x86/hvm/viridian/time.c | 2 +- xen/arch/x86/hvm/viridian/viridian.c | 17 +- xen/arch/x86/hvm/vlapic.c | 25 +- xen/arch/x86/hvm/vmsi.c | 16 +- xen/arch/x86/hvm/vmx/intr.c | 2 +- xen/arch/x86/hvm/vmx/vmcs.c | 22 +- xen/arch/x86/hvm/vmx/vmx.c | 155 +++++---- xen/arch/x86/hvm/vmx/vvmx.c | 16 +- xen/arch/x86/hvm/vpic.c | 8 +- xen/arch/x86/hvm/vpt.c | 2 +- xen/arch/x86/i8259.c | 10 +- xen/arch/x86/include/asm/asm-defns.h | 6 + xen/arch/x86/include/asm/bug.h | 10 +- xen/arch/x86/include/asm/cpufeature.h | 1 + xen/arch/x86/include/asm/cpufeatures.h | 1 + xen/arch/x86/include/asm/cpuidle.h | 4 +- xen/arch/x86/include/asm/current.h | 6 +- xen/arch/x86/include/asm/endbr.h | 55 +++ xen/arch/x86/include/asm/flushtlb.h | 2 +- xen/arch/x86/include/asm/genapic.h | 18 +- xen/arch/x86/include/asm/hpet.h | 8 +- xen/arch/x86/include/asm/hvm/emulate.h | 8 +- xen/arch/x86/include/asm/hvm/save.h | 2 +- xen/arch/x86/include/asm/hvm/svm/nestedsvm.h | 18 +- xen/arch/x86/include/asm/hvm/svm/svm.h | 1 - xen/arch/x86/include/asm/hvm/vioapic.h | 2 +- xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 8 +- xen/arch/x86/include/asm/hvm/vmx/vmx.h | 4 +- xen/arch/x86/include/asm/hvm/vmx/vvmx.h | 18 +- xen/arch/x86/include/asm/hypercall.h | 81 +++-- xen/arch/x86/include/asm/irq.h | 24 +- xen/arch/x86/include/asm/machine_kexec.h | 2 +- xen/arch/x86/include/asm/mm.h | 16 +- xen/arch/x86/include/asm/msi.h | 8 +- xen/arch/x86/include/asm/msr-index.h | 1 + xen/arch/x86/include/asm/mtrr.h | 2 +- xen/arch/x86/include/asm/p2m.h | 4 +- xen/arch/x86/include/asm/paging.h | 2 +- xen/arch/x86/include/asm/processor.h | 4 +- xen/arch/x86/include/asm/pv/domain.h | 4 +- xen/arch/x86/include/asm/pv/shim.h | 11 +- xen/arch/x86/include/asm/shadow.h | 2 +- xen/arch/x86/include/asm/smp.h | 6 +- xen/arch/x86/include/asm/tboot.h | 2 +- xen/arch/x86/include/asm/time.h | 6 +- xen/arch/x86/io_apic.c | 28 +- xen/arch/x86/ioport_emulate.c | 4 +- xen/arch/x86/irq.c | 28 +- xen/arch/x86/livepatch.c | 2 +- xen/arch/x86/machine_kexec.c | 2 +- xen/arch/x86/mm.c | 35 +- xen/arch/x86/mm/hap/guest_walk.c | 4 +- xen/arch/x86/mm/hap/hap.c | 29 +- xen/arch/x86/mm/hap/nested_hap.c | 2 +- xen/arch/x86/mm/hap/private.h | 30 +- xen/arch/x86/mm/mem_sharing.c | 2 +- xen/arch/x86/mm/p2m-ept.c | 34 +- xen/arch/x86/mm/p2m-pt.c | 19 +- xen/arch/x86/mm/paging.c | 3 +- xen/arch/x86/mm/shadow/common.c | 33 +- xen/arch/x86/mm/shadow/hvm.c | 16 +- xen/arch/x86/mm/shadow/multi.c | 80 +++-- xen/arch/x86/mm/shadow/multi.h | 20 +- xen/arch/x86/mm/shadow/none.c | 20 +- xen/arch/x86/mm/shadow/private.h | 12 +- xen/arch/x86/mm/shadow/pv.c | 4 +- xen/arch/x86/msi.c | 18 +- xen/arch/x86/nmi.c | 16 +- xen/arch/x86/numa.c | 10 +- xen/arch/x86/oprofile/nmi_int.c | 16 +- xen/arch/x86/oprofile/op_model_athlon.c | 18 +- xen/arch/x86/oprofile/op_model_p4.c | 14 +- xen/arch/x86/oprofile/op_model_ppro.c | 26 +- xen/arch/x86/percpu.c | 6 +- xen/arch/x86/physdev.c | 2 +- xen/arch/x86/platform_hypercall.c | 11 +- xen/arch/x86/psr.c | 41 +-- xen/arch/x86/pv/callback.c | 25 +- xen/arch/x86/pv/descriptor-tables.c | 14 +- xen/arch/x86/pv/domain.c | 12 +- xen/arch/x86/pv/emul-gate-op.c | 9 +- xen/arch/x86/pv/emul-priv-op.c | 71 ++-- xen/arch/x86/pv/emulate.h | 7 - xen/arch/x86/pv/hypercall.c | 11 +- xen/arch/x86/pv/iret.c | 4 +- xen/arch/x86/pv/misc-hypercalls.c | 10 +- xen/arch/x86/pv/ro-page-fault.c | 31 +- xen/arch/x86/pv/shim.c | 60 ++-- xen/arch/x86/pv/traps.c | 2 +- xen/arch/x86/setup.c | 80 ++++- xen/arch/x86/shutdown.c | 10 +- xen/arch/x86/smp.c | 20 +- xen/arch/x86/smpboot.c | 2 +- xen/arch/x86/spec_ctrl.c | 6 +- xen/arch/x86/srat.c | 4 +- xen/arch/x86/sysctl.c | 4 +- xen/arch/x86/tboot.c | 2 +- xen/arch/x86/time.c | 68 ++-- xen/arch/x86/traps.c | 8 +- xen/arch/x86/tsx.c | 2 +- xen/arch/x86/x86_64/acpi_mmcfg.c | 2 +- xen/arch/x86/x86_64/compat.c | 1 - xen/arch/x86/x86_64/compat/entry.S | 1 + xen/arch/x86/x86_64/compat/mm.c | 7 +- xen/arch/x86/x86_64/entry.S | 49 ++- xen/arch/x86/x86_64/kexec_reloc.S | 23 +- xen/arch/x86/x86_64/mmconfig-shared.c | 10 +- xen/arch/x86/x86_64/mmconfig.h | 2 +- xen/arch/x86/x86_64/platform_hypercall.c | 2 +- xen/arch/x86/x86_64/traps.c | 42 ++- xen/arch/x86/x86_emulate.c | 34 +- xen/arch/x86/x86_emulate/x86_emulate.c | 10 +- xen/arch/x86/x86_emulate/x86_emulate.h | 33 +- xen/arch/x86/xen.lds.S | 3 +- xen/common/argo.c | 6 +- xen/common/bunzip2.c | 2 +- xen/common/compat/domain.c | 3 +- xen/common/compat/grant_table.c | 5 +- xen/common/compat/kernel.c | 2 +- xen/common/compat/memory.c | 7 +- xen/common/compat/multicall.c | 3 +- xen/common/core_parking.c | 10 +- xen/common/coverage/gcov.c | 8 +- xen/common/cpu.c | 4 +- xen/common/debugtrace.c | 10 +- xen/common/decompress.c | 2 +- xen/common/dm.c | 6 +- xen/common/domain.c | 15 +- xen/common/domctl.c | 2 +- xen/common/efi/boot.c | 6 +- xen/common/efi/runtime.c | 18 + xen/common/event_2l.c | 21 +- xen/common/event_channel.c | 18 +- xen/common/event_fifo.c | 30 +- xen/common/gdbstub.c | 9 +- xen/common/grant_table.c | 29 +- xen/common/hypfs.c | 63 ++-- xen/common/irq.c | 6 +- xen/common/kernel.c | 6 +- xen/common/kexec.c | 18 +- xen/common/keyhandler.c | 47 +-- xen/common/livepatch.c | 15 +- xen/common/memory.c | 8 +- xen/common/multicall.c | 2 +- xen/common/page_alloc.c | 14 +- xen/common/perfc.c | 4 +- xen/common/radix-tree.c | 8 +- xen/common/random.c | 2 +- xen/common/rangeset.c | 2 +- xen/common/rcupdate.c | 8 +- xen/common/sched/arinc653.c | 20 +- xen/common/sched/compat.c | 2 +- xen/common/sched/core.c | 40 +-- xen/common/sched/cpupool.c | 35 +- xen/common/sched/credit.c | 59 ++-- xen/common/sched/credit2.c | 55 ++- xen/common/sched/null.c | 60 ++-- xen/common/sched/rt.c | 47 +-- xen/common/spinlock.c | 12 +- xen/common/stop_machine.c | 6 +- xen/common/sysctl.c | 2 +- xen/common/tasklet.c | 4 +- xen/common/timer.c | 6 +- xen/common/trace.c | 4 +- xen/common/unlzma.c | 2 +- xen/common/vm_event.c | 6 +- xen/common/xenoprof.c | 2 +- xen/common/xmalloc_tlsf.c | 4 +- xen/common/zstd/zstd_common.c | 4 +- xen/common/zstd/zstd_internal.h | 4 +- xen/drivers/acpi/apei/apei-base.c | 32 +- xen/drivers/acpi/apei/apei-internal.h | 20 +- xen/drivers/acpi/apei/erst.c | 57 ++- xen/drivers/acpi/apei/hest.c | 4 +- xen/drivers/acpi/numa.c | 10 +- xen/drivers/acpi/tables.c | 2 +- xen/drivers/char/console.c | 36 +- xen/drivers/char/ehci-dbgp.c | 28 +- xen/drivers/char/ns16550.c | 34 +- xen/drivers/cpufreq/cpufreq.c | 6 +- xen/drivers/cpufreq/cpufreq_misc_governors.c | 22 +- xen/drivers/cpufreq/cpufreq_ondemand.c | 10 +- xen/drivers/passthrough/amd/iommu.h | 45 +-- xen/drivers/passthrough/amd/iommu_acpi.c | 15 +- xen/drivers/passthrough/amd/iommu_guest.c | 12 +- xen/drivers/passthrough/amd/iommu_init.c | 49 +-- xen/drivers/passthrough/amd/iommu_intr.c | 20 +- xen/drivers/passthrough/amd/iommu_map.c | 22 +- xen/drivers/passthrough/amd/pci_amd_iommu.c | 32 +- xen/drivers/passthrough/iommu.c | 56 ++- xen/drivers/passthrough/pci.c | 18 +- xen/drivers/passthrough/vtd/dmar.c | 7 +- xen/drivers/passthrough/vtd/extern.h | 38 +- xen/drivers/passthrough/vtd/intremap.c | 14 +- xen/drivers/passthrough/vtd/iommu.c | 94 ++--- xen/drivers/passthrough/vtd/qinval.c | 28 +- xen/drivers/passthrough/vtd/quirks.c | 2 +- xen/drivers/passthrough/vtd/utils.c | 2 +- xen/drivers/passthrough/vtd/x86/hvm.c | 4 +- xen/drivers/passthrough/x86/hvm.c | 14 +- xen/drivers/video/lfb.c | 4 +- xen/drivers/video/lfb.h | 4 +- xen/drivers/video/vesa.c | 6 +- xen/drivers/video/vga.c | 6 +- xen/drivers/vpci/header.c | 18 +- xen/drivers/vpci/msi.c | 42 +-- xen/drivers/vpci/msix.c | 20 +- xen/drivers/vpci/vpci.c | 16 +- xen/include/acpi/cpufreq/cpufreq.h | 1 - xen/include/xen/acpi.h | 2 +- xen/include/xen/compiler.h | 6 + xen/include/xen/domain.h | 2 +- xen/include/xen/hypercall.h | 69 ++-- xen/include/xen/hypfs.h | 49 ++- xen/include/xen/irq.h | 6 +- xen/include/xen/lib.h | 2 +- xen/include/xen/perfc.h | 4 +- xen/include/xen/sched.h | 2 +- xen/include/xen/sort.h | 55 ++- xen/include/xen/spinlock.h | 4 +- xen/include/xen/vpci.h | 8 +- xen/include/xsm/dummy.h | 211 +++++------ xen/lib/sort.c | 80 +---- xen/tools/check-endbr.sh | 85 +++++ xen/xsm/flask/avc.c | 2 +- xen/xsm/flask/flask_op.c | 8 +- xen/xsm/flask/hooks.c | 236 +++++++------ xen/xsm/flask/private.h | 9 + xen/xsm/flask/ss/avtab.c | 4 +- xen/xsm/flask/ss/conditional.c | 10 +- xen/xsm/flask/ss/conditional.h | 6 +- xen/xsm/flask/ss/policydb.c | 53 +-- xen/xsm/flask/ss/services.c | 6 +- xen/xsm/flask/ss/symtab.c | 5 +- xen/xsm/silo.c | 24 +- xen/xsm/xsm_core.c | 6 +- 322 files changed, 3316 insertions(+), 2739 deletions(-) create mode 100644 automation/build/debian/buster-gcc-ibt.dockerfile create mode 100644 xen/arch/x86/include/asm/endbr.h create mode 100755 xen/tools/check-endbr.sh create mode 100644 xen/xsm/flask/private.h
Signature · 1 line
2.11.0
PATCH v3 1/70 xen/sort: Switch to an extern inline implementation
There are exactly 3 callers of sort() in the hypervisor. Callbacks in a tight loop like this are problematic for performance, especially with Spectre v2 protections, which is why extern inline is used commonly by libraries.
Both ARM callers pass in NULL for the swap function, and while this might seem like an attractive option at first, it causes generic_swap() to be used, which forced a byte-wise copy. Provide real swap functions so the compiler can optimise properly, which is very important for ARM downstreams where milliseconds until the system is up matters.
This is also important for Control Flow Integrity schemes (e.g. x86 CET-IBT, ARM BTI), because tagged function(s) performing an arbitrary length swap of two arbitrary pointers is a very valuable gadget for an attacker.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
v2:
* Adjust commit message
v3:
* Adjust comment
* Adjust commit message again
--- xen/arch/arm/bootfdt.c | 9 +++++- xen/arch/arm/io.c | 9 +++++- xen/include/xen/sort.h | 55 +++++++++++++++++++++++++++++++++- xen/lib/sort.c | 80 ++------------------------------------------------ 4 files changed, 72 insertions(+), 81 deletions(-)
xen/arch/arm/bootfdt.c +8 -1
@@ -448,6 +448,13 @@ static int __init cmp_memory_node(const void *key, const void *elem)return 0 ; } +static void __init swap_memory_node (void *_a,void *_b,size_t size) +{ +struct membank *a = _a, *b = _b; + +SWAP (*a, *b); +} +/** * boot_fdt_info - initialize bootinfo from a DTB * @fdt: flattened device tree binary
@@ -472,7 +479,7 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t paddr)* the banks sorted in ascending order. So sort them through. */ sort (bootinfo.mem.bank, bootinfo.mem.nr_banks,sizeof (struct membank ), - cmp_memory_node,NULL ); + cmp_memory_node, swap_memory_node);early_print_info ();
xen/arch/arm/io.c +8 -1
@@ -80,6 +80,13 @@ static int cmp_mmio_handler(const void *key, const void *elem)return 0 ; } +static void swap_mmio_handler (void *_a,void *_b,size_t size) +{ +struct mmio_handler *a = _a, *b = _b; + +SWAP (*a, *b); +} +static const struct mmio_handler *find_mmio_handler (struct domain *d,paddr_t gpa) {
@@ -170,7 +177,7 @@ void register_mmio_handler(struct domain *d,/* Sort mmio handlers in ascending order based on base address */ sort (vmmio->handlers, vmmio->num_entries,sizeof (struct mmio_handler ), - cmp_mmio_handler,NULL ); + cmp_mmio_handler, swap_mmio_handler);write_unlock (&vmmio->lock); }
xen/include/xen/sort.h +54 -1
62 lines not on this page · raw message
xen/lib/sort.c +2 -78
83 lines not on this page · raw message
Signature · 1 line
2.11.0
Re: [PATCH v3 01/70] xen/sort: Switch to an extern inline implementation
Hi,
Quoted 9 lines · Andrew Cooper
There are exactly 3 callers of
sort()in the hypervisor. Callbacks in a tight loop like this are problematic for performance, especially with Spectre v2 protections, which is why extern inline is used commonly by libraries.Both ARM callers pass in NULL for the swap function, and while this might seem like an attractive option at first, it causes
generic_swap()to be used, which forced a byte-wise copy. Provide real swap functions so the compiler can optimise properly, which is very important for ARM downstreams where milliseconds until the system is up matters.
After the previous discussion, I was expecting the sentence "Provide real..." to be completely dropped. Instead the change should be justified with...
Quoted 3 lines
This is also important for Control Flow Integrity schemes (e.g. x86 CET-IBT, ARM BTI), because tagged function(s) performing an arbitrary length swap of two arbitrary pointers is a very valuable gadget for an attacker.
... this one as this is the real reason of the change. Not the performance (unless you have numbers proving it).
Quoted 6 lines
No functional change.
Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Jan Beulich <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>
To be pedantic, my Nacked-by hasn't been yet revoked (see [1]). So you should have kept it in the new version.
Anyway, given that the patch makes sense for BTI, I am willing to replace the Nacked-by with an Acked-by:
[1] https://lore.kernel.org/xen-devel/[email protected]/
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 3/70 x86/pv-shim: Don't modify the hypercall table
In reply to Andrew CooperFrom: Juergen Gross <[email protected]>
When running as pv-shim the hypercall is modified today in order to replace the functions for __HYPERVISOR_event_channel_op and __HYPERVISOR_grant_table_op hypercalls.
Change this to call the related functions from the normal handlers instead when running as shim. The performance implications are not really relevant, as a normal production hypervisor will not be configured to support shim mode, so the related calls will be dropped due to optimisation of the compiler.
Note that for the CONFIG_PV_SHIM_EXCLUSIVE case there is a dummy wrapper do_grant_table_op() needed, as in this case grant_table.c isn't being built.
---
v3:
* Identify that it is modified as a side effect of pulling it out of the middle of Juergen's series.
--- xen/arch/x86/include/asm/hypercall.h | 4 ++- xen/arch/x86/include/asm/pv/shim.h | 3 ++ xen/arch/x86/pv/hypercall.c | 2 +- xen/arch/x86/pv/shim.c | 54 ++++++++++++++++---------------- xen/arch/x86/x86_64/platform_hypercall.c | 2 +- xen/common/compat/multicall.c | 3 +- xen/common/event_channel.c | 9 ++++++ xen/common/grant_table.c | 9 ++++++ 8 files changed, 54 insertions(+), 32 deletions(-)
xen/arch/x86/include/asm/hypercall.h +3 -1
@@ -145,6 +145,7 @@ do_set_segment_base(#include <compat/arch-x86/xen.h> #include <compat/physdev.h> +#include <compat/platform.h> extern int compat_physdev_op(
@@ -161,8 +162,9 @@ extern int compat_mmuext_op(XEN_GUEST_HANDLE_PARAM (uint) pdone, unsigned int foreigndom); +DEFINE_XEN_GUEST_HANDLE (compat_platform_op_t);extern int compat_platform_op ( -XEN_GUEST_HANDLE_PARAM (void ) u_xenpf_op); +XEN_GUEST_HANDLE_PARAM (compat_platform_op_t) u_xenpf_op);extern long compat_callback_op (int cmd,XEN_GUEST_HANDLE (void ) arg);
xen/arch/x86/include/asm/pv/shim.h +3 -0
@@ -19,6 +19,7 @@#ifndef __X86_PV_SHIM_H__#define __X86_PV_SHIM_H__ +#include <xen/hypercall.h> #include <xen/types.h> #if defined(CONFIG_PV_SHIM_EXCLUSIVE )
@@ -45,6 +46,8 @@ domid_t get_initial_domain_id(void);uint64_t pv_shim_mem (uint64_t avail);void pv_shim_fixup_e820 (struct e820map *e820);const struct platform_bad_page *pv_shim_reserved_pages (unsigned int *size); +typeof (do_event_channel_op) pv_shim_event_channel_op; +typeof (do_grant_table_op) pv_shim_grant_table_op;#else
xen/arch/x86/pv/hypercall.c +1 -1
@@ -64,7 +64,7 @@ const pv_hypercall_table_t pv_hypercall_table[] = {COMPAT_CALL (xen_version),HYPERCALL (console_io ),COMPAT_CALL (physdev_op_compat ), -#ifdef CONFIG_GRANT_TABLE +#if defined(CONFIG_GRANT_TABLE) || defined(CONFIG_PV_SHIM)COMPAT_CALL (grant_table_op ), #endif HYPERCALL(vm_assist),
xen/arch/x86/pv/shim.c +27 -27
90 lines not on this page · raw message
xen/arch/x86/x86_64/platform_hypercall.c +1 -1
@@ -6,8 +6,8 @@ EMIT_FILE;#include <xen/lib.h> #include <compat/platform.h> +#include <xen/hypercall.h> -DEFINE_XEN_GUEST_HANDLE (compat_platform_op_t);#define xen_platform_op compat_platform_op#define xen_platform_op_t compat_platform_op_t#define do_platform_op (x) compat_platform_op(_##x)
xen/common/compat/multicall.c +1 -2
@@ -5,7 +5,7 @@EMIT_FILE ;#include <xen/types.h> -#include <xen/multicall.h> +#include <xen/hypercall.h> #include <xen/trace.h> #define COMPAT
@@ -19,7 +19,6 @@ static inline void xlat_multicall_entry(struct mc_state *mcs) mcs->compat_call.args[i] = mcs->call.args[i]; } -DEFINE_XEN_GUEST_HANDLE (multicall_entry_compat_t);#define multicall_entry compat_multicall_entry#define multicall_entry_t multicall_entry_compat_t#define do_multicall_call compat_multicall_call
xen/common/event_channel.c +9 -0
@@ -31,6 +31,10 @@#include <public/event_channel.h> #include <xsm/xsm.h> +#ifdef CONFIG_PV_SHIM +#include <asm/guest.h> +#endif +#define ERROR_EXIT (_errno) \ do { \ gdprintk(XENLOG_WARNING, \
@@ -1189,6 +1193,11 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) {int rc; +#ifdef CONFIG_PV_SHIM +if (unlikely (pv_shim) ) +return pv_shim_event_channel_op (cmd, arg); +#endif +switch ( cmd ) {case EVTCHNOP_alloc_unbound: {
xen/common/grant_table.c +9 -0
@@ -44,6 +44,10 @@#include <asm/flushtlb.h> #include <asm/guest_atomics.h> +#ifdef CONFIG_PV_SHIM +#include <asm/guest.h> +#endif +/* Per-domain grant information. */ struct grant_table {/*
@@ -3561,6 +3565,11 @@ do_grant_table_op(long rc;unsigned int opaque_in = cmd &GNTTABOP_ARG_MASK , opaque_out =0 ; +#ifdef CONFIG_PV_SHIM +if (unlikely (pv_shim) ) +return pv_shim_grant_table_op (cmd, uop, count); +#endif +if ( (int )count <0 )return -EINVAL ;
Signature · 1 line
2.11.0
Re: [PATCH v3 03/70] x86/pv-shim: Don't modify the hypercall table
Quoted 12 lines · Andrew Cooper
From: Juergen Gross <[email protected]>
When running as pv-shim the hypercall is modified today in order to replace the functions for
__HYPERVISOR_event_channel_opand__HYPERVISOR_grant_table_ophypercalls.Change this to call the related functions from the normal handlers instead when running as shim. The performance implications are not really relevant, as a normal production hypervisor will not be configured to support shim mode, so the related calls will be dropped due to optimisation of the compiler.
Quoted 7 lines
Note that for the
CONFIG_PV_SHIM_EXCLUSIVEcase there is a dummy wrapperdo_grant_table_op()needed, as in this casegrant_table.cisn't being built.Signed-off-by Juergen Gross <[email protected]>[Split out of series. Make compile in isolation]Signed-off-by Andrew Cooper <[email protected]>
As said, somewhat hesitantly
"Make compile in isolation", while describing the changes which weren't in Jürgen's original patch, is quite terse. But anyway.
Jan
PATCH v3 5/70 x86/kexec: Annotate embedded data with ELF metadata
In reply to Andrew CooperScanning for embedded endbranch instructions involves parsing the .text disassembly. Data in the kexec trampoline has no ELF metadata, so objdump treats it as instructions and tries to disassemble. Convert:
ffff82d040396108 <compatibility_mode_far>:
ffff82d040396108: 00 00 add %al,(%rax) ffff82d04039610a: 00 00 add %al,(%rax) ffff82d04039610c: 10 00 adc %al,(%rax)
ffff82d04039610e <compat_mode_gdt_desc>:
ffff82d04039610e: 17 (bad)
...
ffff82d040396118 <compat_mode_gdt>:
...
ffff82d040396120: ff (bad)
ffff82d040396121: ff 00 incl (%rax)
ffff82d040396123: 00 00 add %al,(%rax)
ffff82d040396125: 93 xchg %eax,%ebx
ffff82d040396126: cf iret
ffff82d040396127: 00 ff add %bh,%bh
ffff82d040396129: ff 00 incl (%rax)
ffff82d04039612b: 00 00 add %al,(%rax)
ffff82d04039612d: 9b fwait
ffff82d04039612e: cf iret
... ffff82d040396130 <compat_mode_idt>:
...
ffff82d0403961b6 <kexec_reloc_size>:
ffff82d0403961b6: b6 01 mov $0x1,%dh
...
to:
ffff82d040396108 <compatibility_mode_far>:
ffff82d040396108: 00 00 00 00 10 00 ......
ffff82d04039610e <compat_mode_gdt_desc>:
ffff82d04039610e: 17 00 00 00 00 00 00 00 00 00 ..........
ffff82d040396118 <compat_mode_gdt>:
...
ffff82d040396120: ff ff 00 00 00 93 cf 00 ff ff 00 00 00 9b cf 00 ................
ffff82d040396130 <compat_mode_idt>:
ffff82d040396130: 00 00 00 00 00 00 ......
ffff82d040396136 <reloc_stack>:
...
Most data just gains type and size metadata.
The reloc_stack label is the wrong end of the data block to have a size, so move it to the lowest address and introduce .Lreloc_stack_base as a replacement. Also, fix the fact that it is misaligned by 2 bytes.
While kexec_reloc_size could gain metadata, it's use in the linker assertion (while correct) is deeply confusing to follow. Drop it entirely, using a linker symbol instead to denote the end of the trampoline.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
The remainder of the 32bit code has mode-invariant lengths, so disassembles safely as 64bit. The only differences come from 32/64bit implicit register sizes.
v2.1:
* New
v2.2:
* Fix stack alignment
--- xen/arch/x86/include/asm/machine_kexec.h | 2 +- xen/arch/x86/machine_kexec.c | 2 +- xen/arch/x86/x86_64/kexec_reloc.S | 23 ++++++++++++++++++----- xen/arch/x86/xen.lds.S | 3 ++- 4 files changed, 22 insertions(+), 8 deletions(-)
xen/arch/x86/include/asm/machine_kexec.h +1 -1
@@ -9,7 +9,7 @@ extern void kexec_reloc(unsigned long reloc_code, unsigned long reloc_pt, unsigned long ind_maddr, unsigned long entry_maddr, unsigned long flags); -extern unsigned int kexec_reloc_size; +extern const char kexec_reloc_end[];#endif
xen/arch/x86/machine_kexec.c +1 -1
@@ -117,7 +117,7 @@ int machine_kexec_load(struct kexec_image *image) } code_page =__map_domain_page (image->control_code_page); -memcpy (code_page, kexec_reloc, kexec_reloc_size); +memcpy (code_page, kexec_reloc, kexec_reloc_end - (char *)kexec_reloc);unmap_domain_page (code_page);/*
xen/arch/x86/x86_64/kexec_reloc.S +18 -5
@@ -34,7 +34,7 @@ ENTRY(kexec_reloc) movq %rcx, %rbp /* Setup stack. */ - leaq (reloc_stack - kexec_reloc)(%rdi), %rsp + leaq (.Lreloc_stack_base - kexec_reloc)(%rdi), %rsp /* Load reloc page table. */ movq %rsi, %cr3
@@ -175,10 +175,16 @@ compatibility_mode_far: .long 0x00000000 /* set in call_32_bit above */ .word 0x0010 + .type compatibility_mode_far, @object + .size compatibility_mode_far, . - compatibility_mode_far + compat_mode_gdt_desc: .word .Lcompat_mode_gdt_end - compat_mode_gdt -1 .quad 0x0000000000000000 /* set in call_32_bit above */ + .type compat_mode_gdt_desc, @object + .size compat_mode_gdt_desc, . - compat_mode_gdt_desc + .align 8 compat_mode_gdt: .quad 0x0000000000000000 /* null */
@@ -186,16 +192,23 @@ compat_mode_gdt: .quad 0x00cf9b000000ffff /* 0x0010 ring 0 code, compatibility */ .Lcompat_mode_gdt_end: + .type compat_mode_gdt, @object + .size compat_mode_gdt, . - compat_mode_gdt + compat_mode_idt: .word 0 /* limit */ .long 0 /* base */ + .type compat_mode_idt, @object + .size compat_mode_idt, . - compat_mode_idt + /* * 16 words of stack are more than enough. */ - .fill 16,8,0 + .align 8 reloc_stack: + .fill 16,8,0 +.Lreloc_stack_base: - .globl kexec_reloc_size -kexec_reloc_size: - .long . - kexec_reloc + .type reloc_stack, @object + .size reloc_stack, . - reloc_stack
xen/arch/x86/xen.lds.S +2 -1
@@ -84,6 +84,7 @@ SECTIONS _etextentry = .; *(.text.kexec) /* Page aligned in the object file. */ + kexec_reloc_end = .; *(.text.cold) *(.text.unlikely)
@@ -428,7 +429,7 @@ ASSERT(__2M_rwdata_end <= XEN_VIRT_END - XEN_VIRT_START + __XEN_VIRT_START - "Xen image overlaps stubs area") #ifdef CONFIG_KEXEC -ASSERT(kexec_reloc_size - kexec_reloc <= PAGE_SIZE, "kexec_reloc is too large") +ASSERT(kexec_reloc_end - kexec_reloc <= PAGE_SIZE, "kexec_reloc is too large") #endif /* The Multiboot setup paths relies on this to simplify superpage PTE creation. */
Signature · 1 line
2.11.0
PATCH v3 6/70 x86: Introduce support for CET-IBT
In reply to Andrew CooperCET Indirect Branch Tracking is a hardware feature designed to provide forward-edge control flow integrity, protecting against jump/call oriented programming.
IBT requires the placement of ENDBR{32,64} instructions at the target of every indirect call/jmp, and every entrypoint.
However, the default -fcf-protection=branch places an ENDBR on every function which far more than necessary, and reduces the quantity of protection afforded. Therefore, we use manual placement using the cf_check attribute.
It is necessary to check for both compiler and assembler support, as the notrack prefix can be emitted in certain cases.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
Clang/LLVM support for -mmanual-endbr is in progress:
https://reviews.llvm.org/D118355
v2:
* Correct CONFIG_HAS_CC_CET_IBT to CONFIG_XEN_IBT in some places
* Move cf_check compatibility into tools/tests/x86_emulator/x86-emulate.h
v3:
* Extend commit message
* Disable IBT for pvshim defconfig
--- Config.mk | 1 - tools/firmware/Makefile | 2 ++ tools/libs/guest/xg_dom_decompress_unsafe.h | 2 ++ tools/tests/x86_emulator/x86-emulate.h | 2 ++ xen/arch/x86/Kconfig | 17 +++++++++++++++++ xen/arch/x86/arch.mk | 6 ++++++ xen/arch/x86/configs/pvshim_defconfig | 1 + xen/arch/x86/include/asm/asm-defns.h | 6 ++++++ xen/arch/x86/include/asm/cpufeature.h | 1 + xen/arch/x86/include/asm/cpufeatures.h | 1 + xen/include/xen/compiler.h | 6 ++++++ 11 files changed, 44 insertions(+), 1 deletion(-)
Config.mk +0 -1
@@ -190,7 +190,6 @@ APPEND_CFLAGS += $(foreach i, $(APPEND_INCLUDES), -I$(i)) EMBEDDED_EXTRA_CFLAGS := -nopie -fno-stack-protector -fno-stack-protector-all EMBEDDED_EXTRA_CFLAGS += -fno-exceptions -fno-asynchronous-unwind-tables -EMBEDDED_EXTRA_CFLAGS += -fcf-protection=none XEN_EXTFILES_URL ?= http://xenbits.xen.org/xen-extfiles # All the files at that location were downloaded from elsewhere on
tools/firmware/Makefile +2 -0
@@ -6,6 +6,8 @@ TARGET := hvmloader/hvmloader INST_DIR := $(DESTDIR)$(XENFIRMWAREDIR) DEBG_DIR := $(DESTDIR)$(DEBUG_DIR)$(XENFIRMWAREDIR) +EMBEDDED_EXTRA_CFLAGS += -fcf-protection=none + SUBDIRS-y := SUBDIRS-$(CONFIG_OVMF) += ovmf-dir SUBDIRS-$(CONFIG_SEABIOS) += seabios-dir
tools/libs/guest/xg_dom_decompress_unsafe.h +2 -0
@@ -8,6 +8,8 @@ typedef int decompress_fn(unsigned char *inbuf, unsigned int len, void (*error)(const char *x));#endif +#define cf_check/* No Control Flow Integriy checking */ +int xc_dom_decompress_unsafe (decompress_fn fn,struct xc_dom_image *dom,void **blob,size_t *size) __attribute__((visibility ("internal" )));
tools/tests/x86_emulator/x86-emulate.h +2 -0
@@ -54,6 +54,8 @@#define likely (x) __builtin_expect(!!(x), true)#define unlikely (x) __builtin_expect(!!(x), false) +#define cf_check/* No Control Flow Integriy checking */ +#define container_of (ptr, type, member) ({ \ typeof(((type *)0)->member) *mptr__ = (ptr); \ (type *)((char *)mptr__ - offsetof(type, member)); \
xen/arch/x86/Kconfig +17 -0
@@ -40,6 +40,11 @@ config HAS_AS_CET_SS # binutils >= 2.29 or LLVM >= 6 def_bool $(as-instr,wrssq %rax$(comma)0;setssbsy) +config HAS_CC_CET_IBT + # GCC >= 9 and binutils >= 2.29 + # Retpoline check to work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93654 + def_bool $(cc-option,-fcf-protection=branch -mmanual-endbr -mindirect-branch=thunk-extern) && $(as-instr,endbr64) + menu "Architecture Features" source "arch/Kconfig"
@@ -125,6 +130,18 @@ config XEN_SHSTK When CET-SS is active, 32bit PV guests cannot be used. Backwards compatiblity can be provided via the PV Shim mechanism. +config XEN_IBT + bool "Supervisor Indirect Branch Tracking" + depends on HAS_CC_CET_IBT + default y + help + Control-flow Enforcement Technology (CET) is a set of features in + hardware designed to combat Return-oriented Programming (ROP, also + call/jump COP/JOP) attacks. Indirect Branch Tracking is one CET + feature designed to provide function pointer protection. + + This option arranges for Xen to use CET-IBT for its own protection. + config SHADOW_PAGING bool "Shadow Paging" default !PV_SHIM_EXCLUSIVE
xen/arch/x86/arch.mk +6 -0
@@ -52,6 +52,12 @@ CFLAGS-$(CONFIG_CC_IS_GCC) += -fno-jump-tables CFLAGS-$(CONFIG_CC_IS_CLANG) += -mretpoline-external-thunk endif +ifdef CONFIG_XEN_IBT +CFLAGS += -fcf-protection=branch -mmanual-endbr +else +$(call cc-option-add,CFLAGS,CC,-fcf-protection=none) +endif + # If supported by the compiler, reduce stack alignment to 8 bytes. But allow # this to be overridden elsewhere. $(call cc-option-add,CFLAGS_stack_boundary,CC,-mpreferred-stack-boundary=3)
xen/arch/x86/configs/pvshim_defconfig +1 -0
@@ -8,6 +8,7 @@ CONFIG_NR_CPUS=32 CONFIG_EXPERT=y # Disable features not used by the PV shim # CONFIG_XEN_SHSTK is not set +# CONFIG_XEN_IBT is not set # CONFIG_GRANT_TABLE is not set # CONFIG_HYPFS is not set # CONFIG_BIGMEM is not set
xen/arch/x86/include/asm/asm-defns.h +6 -0
@@ -57,6 +57,12 @@ INDIRECT_BRANCH jmp \arg .endm +#ifdef CONFIG_XEN_IBT +# define ENDBR64 endbr64 +#else +# define ENDBR64 +#endif + .macro guest_access_mask_ptr ptr:req, scratch1:req, scratch2:req#if defined(CONFIG_SPECULATIVE_HARDEN_GUEST_ACCESS )/*
xen/arch/x86/include/asm/cpufeature.h +1 -0
@@ -152,6 +152,7 @@#define cpu_has_nscb boot_cpu_has(X86_FEATURE_NSCB)#define cpu_has_xen_lbr boot_cpu_has(X86_FEATURE_XEN_LBR)#define cpu_has_xen_shstk boot_cpu_has(X86_FEATURE_XEN_SHSTK) +#define cpu_has_xen_ibt boot_cpu_has(X86_FEATURE_XEN_IBT)#define cpu_has_msr_tsc_aux (cpu_has_rdtscp || cpu_has_rdpid)
xen/arch/x86/include/asm/cpufeatures.h +1 -0
@@ -39,6 +39,7 @@ XEN_CPUFEATURE(SC_VERW_PV, X86_SYNTH(23)) /* VERW used by Xen for PV */ XEN_CPUFEATURE(SC_VERW_HVM, X86_SYNTH(24)) /* VERW used by Xen for HVM */ XEN_CPUFEATURE(SC_VERW_IDLE, X86_SYNTH(25)) /* VERW used by Xen for idle */ XEN_CPUFEATURE(XEN_SHSTK, X86_SYNTH(26)) /* Xen uses CET Shadow Stacks */ +XEN_CPUFEATURE (XEN_IBT ,X86_SYNTH (27 ))/* Xen uses CET Indirect Branch Tracking */ /* Bug words follow the synthetic words. */#define X86_NR_BUG 1
xen/include/xen/compiler.h +6 -0
@@ -37,6 +37,12 @@# define nocall#endif +#ifdef CONFIG_XEN_IBT +# define cf_check __attribute__((__cf_check__)) +#else +# define cf_check +#endif +#if (!defined(__clang__) && (__GNUC__ ==4 ) && (__GNUC_MINOR__ <5 ))#define unreachable () do {} while (1)#else
Signature · 1 line
2.11.0
Re: [PATCH v3 06/70] x86: Introduce support for CET-IBT
xen/arch/x86/Kconfig config HAS_AS_CET_SS · line 46
Quoted 10 lines · Andrew Cooper
xen/arch/x86/Kconfig +4
-0@@ -40,6 +40,11 @@ config HAS_AS_CET_SS # binutils >= 2.29 or LLVM >= 6 def_bool $(as-instr,wrssq %rax$(comma)0;setssbsy) +config HAS_CC_CET_IBT + # GCC >= 9 and binutils >= 2.29 + # Retpoline check to work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93654 + def_bool $(cc-option,-fcf-protection=branch -mmanual-endbr -mindirect-branch=thunk-extern) && $(as-instr,endbr64)
Noticed only now: Since the commit message doesn't say anything either way, was it intentional for this to differ from XEN_SHSTK in the EXPERT dependency?
Jan
PATCH v3 8/70 xen: CFI hardening for custom_param()
In reply to Andrew CooperControl Flow Integrity schemes use toolchain and optionally hardware support to help protect against call/jump/return oriented programming attacks.
Use cf_check to annotate function pointer targets for the toolchain.
The "watchdog_timeout" and "cpu_type" handlers were missing __init.
The "numa", "acpi", "irq_vector_map" and "flask" handlers can skip forward declarations by altering the custom_param() position.
---
v3:
* Rebase over recent "vesa" changes.
--- xen/arch/x86/acpi/cpu_idle.c | 2 +- xen/arch/x86/acpi/power.c | 2 +- xen/arch/x86/apic.c | 4 ++-- xen/arch/x86/cpu/mcheck/mce.c | 2 +- xen/arch/x86/cpu/microcode/core.c | 2 +- xen/arch/x86/cpu/vpmu.c | 2 +- xen/arch/x86/cpuid.c | 8 ++++---- xen/arch/x86/dom0_build.c | 8 ++++---- xen/arch/x86/genapic/probe.c | 2 +- xen/arch/x86/hpet.c | 2 +- xen/arch/x86/hvm/viridian/viridian.c | 2 +- xen/arch/x86/hvm/vmx/vmcs.c | 8 ++++---- xen/arch/x86/io_apic.c | 2 +- xen/arch/x86/irq.c | 6 ++---- xen/arch/x86/mm.c | 2 +- xen/arch/x86/nmi.c | 4 ++-- xen/arch/x86/numa.c | 6 ++---- xen/arch/x86/oprofile/nmi_int.c | 2 +- xen/arch/x86/psr.c | 2 +- xen/arch/x86/pv/domain.c | 8 ++++---- xen/arch/x86/pv/shim.c | 2 +- xen/arch/x86/setup.c | 11 +++++------ xen/arch/x86/shutdown.c | 2 +- xen/arch/x86/spec_ctrl.c | 6 +++--- xen/arch/x86/time.c | 2 +- xen/arch/x86/tsx.c | 2 +- xen/arch/x86/x86_64/mmconfig-shared.c | 2 +- xen/common/argo.c | 2 +- xen/common/core_parking.c | 2 +- xen/common/debugtrace.c | 2 +- xen/common/domain.c | 2 +- xen/common/efi/boot.c | 2 +- xen/common/grant_table.c | 14 +++++++------- xen/common/kexec.c | 6 +++--- xen/common/memory.c | 2 +- xen/common/page_alloc.c | 2 +- xen/common/sched/cpupool.c | 2 +- xen/common/sched/credit2.c | 2 +- xen/drivers/acpi/tables.c | 2 +- xen/drivers/char/console.c | 18 +++++++++--------- xen/drivers/cpufreq/cpufreq.c | 2 +- xen/drivers/passthrough/amd/iommu_acpi.c | 6 +++--- xen/drivers/passthrough/iommu.c | 4 ++-- xen/drivers/passthrough/pci.c | 4 ++-- xen/drivers/passthrough/vtd/dmar.c | 2 +- xen/drivers/passthrough/vtd/quirks.c | 2 +- xen/drivers/video/vesa.c | 2 +- xen/xsm/flask/flask_op.c | 5 ++--- xen/xsm/xsm_core.c | 2 +- 49 files changed, 92 insertions(+), 98 deletions(-)
xen/arch/x86/acpi/cpu_idle.c +1 -1
@@ -106,7 +106,7 @@ void (*__read_mostly pm_idle_save)(void);unsigned int max_cstate__read_mostly =UINT_MAX ;unsigned int max_csubstate__read_mostly =UINT_MAX ; -static int __init parse_cstate (const char *s) +static int __init cf_check parse_cstate(const char *s) { max_cstate =simple_strtoul (s, &s,0 );if ( *s ==',' )
xen/arch/x86/acpi/power.c +1 -1
@@ -35,7 +35,7 @@uint32_t system_reset_counter =1 ; -static int __init parse_acpi_sleep (const char *s) +static int __init cf_check parse_acpi_sleep(const char *s) {const char *ss;unsigned int flag =0 ;
xen/arch/x86/apic.c +2 -2
@@ -775,7 +775,7 @@ int lapic_resume(void)* Original code written by Keir Fraser. */ -static int __init lapic_disable (const char *str) +static int __init cf_check lapic_disable(const char *str) { enable_local_apic =-1 ;setup_clear_cpu_cap (X86_FEATURE_APIC );
@@ -784,7 +784,7 @@ static int __init lapic_disable(const char *str)custom_param ("nolapic" , lapic_disable);boolean_param ("lapic" , enable_local_apic); -static int __init apic_set_verbosity (const char *str) +static int __init cf_check apic_set_verbosity(const char *str) {if (strcmp ("debug" , str) ==0 ) apic_verbosity =APIC_DEBUG ;
xen/arch/x86/cpu/mcheck/mce.c +1 -1
@@ -63,7 +63,7 @@ struct mca_banks *mca_allbanks;#endif int mce_verbosity; -static int __init mce_set_verbosity (const char *str) +static int __init cf_check mce_set_verbosity(const char *str) {if (strcmp ("verbose" , str) ==0 ) mce_verbosity =MCE_VERBOSE ;
xen/arch/x86/cpu/microcode/core.c +1 -1
@@ -111,7 +111,7 @@ void __init microcode_set_module(unsigned int idx)* optional. If the EFI has forced which of the multiboot payloads is to be * used, only nmi=<bool> is parsed. */ -static int __init parse_ucode (const char *s) +static int __init cf_check parse_ucode(const char *s) {const char *ss;int val, rc =0 ;
xen/arch/x86/cpu/vpmu.c +1 -1
@@ -56,7 +56,7 @@ static unsigned vpmu_count; static DEFINE_PER_CPU(struct vcpu *, last_vcpu); -static int __init parse_vpmu_params (const char *s) +static int __init cf_check parse_vpmu_params(const char *s) {const char *ss;int rc =0 , val;
xen/arch/x86/cpuid.c +4 -4
@@ -101,7 +101,7 @@ static int __init always_inline parse_cpuid(return rc; } -static void __init _parse_xen_cpuid (unsigned int feat,bool val) +static void __init cf_check _parse_xen_cpuid(unsigned int feat, bool val) {if ( !val )setup_clear_cpu_cap (feat);
@@ -110,7 +110,7 @@ static void __init _parse_xen_cpuid(unsigned int feat, bool val)setup_force_cpu_cap (X86_FEATURE_RDRAND ); } -static int __init parse_xen_cpuid (const char *s) +static int __init cf_check parse_xen_cpuid(const char *s) {return parse_cpuid (s, _parse_xen_cpuid); }
@@ -120,13 +120,13 @@ static bool __initdata dom0_cpuid_cmdline;static uint32_t __initdata dom0_enable_feat[FSCAPINTS ];static uint32_t __initdata dom0_disable_feat[FSCAPINTS ]; -static void __init _parse_dom0_cpuid (unsigned int feat,bool val) +static void __init cf_check _parse_dom0_cpuid(unsigned int feat, bool val) {__set_bit (feat, val ? dom0_enable_feat : dom0_disable_feat);__clear_bit (feat, val ? dom0_disable_feat : dom0_enable_feat ); } -static int __init parse_dom0_cpuid (const char *s) +static int __init cf_check parse_dom0_cpuid(const char *s) { dom0_cpuid_cmdline = true;
xen/arch/x86/dom0_build.c +4 -4
@@ -115,7 +115,7 @@ static int __init parse_amt(const char *s, const char **ps, struct memsize *sz)return 0 ; } -static int __init parse_dom0_mem (const char *s) +static int __init cf_check parse_dom0_mem(const char *s) {int ret;
@@ -144,7 +144,7 @@ custom_param("dom0_mem", parse_dom0_mem);static unsigned int __initdata opt_dom0_max_vcpus_min =1 ;static unsigned int __initdata opt_dom0_max_vcpus_max =UINT_MAX ; -static int __init parse_dom0_max_vcpus (const char *s) +static int __init cf_check parse_dom0_max_vcpus(const char *s) {if ( *s =='-' )/* -M */ opt_dom0_max_vcpus_max =simple_strtoul (s +1 , &s,0 );
@@ -168,7 +168,7 @@ static __initdata unsigned int dom0_pxms[MAX_NUMNODES] = { [0 ... MAX_NUMNODES - 1] = ~0 };bool __initdata dom0_affinity_relaxed; -static int __init parse_dom0_nodes (const char *s) +static int __init cf_check parse_dom0_nodes(const char *s) {const char *ss;int rc =0 ;
@@ -266,7 +266,7 @@ bool __initdata opt_dom0_pvh = !IS_ENABLED(CONFIG_PV);bool __initdata opt_dom0_verbose =IS_ENABLED (CONFIG_VERBOSE_DEBUG );bool __initdata opt_dom0_msr_relaxed; -static int __init parse_dom0_param (const char *s) +static int __init cf_check parse_dom0_param(const char *s) {const char *ss;int rc =0 ;
xen/arch/x86/genapic/probe.c +1 -1
@@ -43,7 +43,7 @@ void __init generic_bigsmp_probe(void) } } -static int __init genapic_apic_force (const char *str) +static int __init cf_check genapic_apic_force(const char *str) {int i, rc = -EINVAL ;
xen/arch/x86/hpet.c +1 -1
@@ -65,7 +65,7 @@ u8 __initdata hpet_flags;static bool __initdata force_hpet_broadcast;boolean_param ("hpetbroadcast" , force_hpet_broadcast); -static int __init parse_hpet_param (const char *s) +static int __init cf_check parse_hpet_param(const char *s) {const char *ss;int val, rc =0 ;
xen/arch/x86/hvm/viridian/viridian.c +1 -1
@@ -1186,7 +1186,7 @@ static int viridian_load_vcpu_ctxt(struct domain *d,HVM_REGISTER_SAVE_RESTORE (VIRIDIAN_VCPU , viridian_save_vcpu_ctxt, viridian_load_vcpu_ctxt,1 ,HVMSR_PER_VCPU ); -static int __init parse_viridian_version (const char *arg) +static int __init cf_check parse_viridian_version(const char *arg) {const char *t;unsigned int n[3 ];
xen/arch/x86/hvm/vmx/vmcs.c +4 -4
@@ -71,7 +71,7 @@ static bool __read_mostly opt_ept_pml = true;static s8 __read_mostly opt_ept_ad =-1 ;int8_t __read_mostly opt_ept_exec_sp =-1 ; -static int __init parse_ept_param (const char *s) +static int __init cf_check parse_ept_param(const char *s) {const char *ss;int val, rc =0 ;
@@ -107,16 +107,16 @@ static void update_ept_param(void) opt_ept_exec_sp); } -static void __init init_ept_param (struct param_hypfs *par) +static void __init cf_check init_ept_param(struct param_hypfs *par) {update_ept_param ();custom_runtime_set_var (par, opt_ept_setting); } -static int parse_ept_param_runtime (const char *s); +static int cf_check parse_ept_param_runtime(const char *s);custom_runtime_only_param ("ept" , parse_ept_param_runtime, init_ept_param); -static int parse_ept_param_runtime (const char *s) +static int cf_check parse_ept_param_runtime(const char *s) {struct domain *d;int val;
xen/arch/x86/io_apic.c +1 -1
@@ -1601,7 +1601,7 @@ static unsigned int startup_level_ioapic_irq(struct irq_desc *desc)return 0 ;/* don't check for pending */ } -static int __init setup_ioapic_ack (const char *s) +static int __init cf_check setup_ioapic_ack(const char *s) {if ( !strcmp (s,"old" ) ) {
xen/arch/x86/irq.c +2 -4
@@ -28,8 +28,6 @@#include <irq_vectors.h> #include <public/physdev.h> -static int parse_irq_vector_map_param (const char *s); -/* opt_noirqbalance: If true, software IRQ balancing/affinity is disabled. */ bool __read_mostly opt_noirqbalance;boolean_param ("noirqbalance" , opt_noirqbalance);
@@ -40,7 +38,6 @@ integer_param("nr_irqs", nr_irqs);/* This default may be changed by the AMD IOMMU code */ int __read_mostly opt_irq_vector_map =OPT_IRQ_VECTOR_MAP_DEFAULT ; -custom_param ("irq_vector_map" , parse_irq_vector_map_param);/* Max number of guests IRQ could be shared with */ static unsigned char __read_mostly irq_max_guests;
@@ -66,7 +63,7 @@ static struct timer irq_ratelimit_timer;static unsigned int __read_mostly irq_ratelimit_threshold =10000 ;integer_param ("irq_ratelimit" , irq_ratelimit_threshold); -static int __init parse_irq_vector_map_param (const char *s) +static int __init cf_check parse_irq_vector_map_param(const char *s) {const char *ss;int rc =0 ;
@@ -90,6 +87,7 @@ static int __init parse_irq_vector_map_param(const char *s)return rc; } +custom_param ("irq_vector_map" , parse_irq_vector_map_param);/* Must be called when irq disabled */ void lock_vector_lock (void )
xen/arch/x86/mm.c +1 -1
@@ -189,7 +189,7 @@ static uint32_t base_disallow_mask;static s8 __read_mostly opt_mmio_relax; -static int __init parse_mmio_relax (const char *s) +static int __init cf_check parse_mmio_relax(const char *s) {if ( !*s ) opt_mmio_relax =1 ;
xen/arch/x86/nmi.c +2 -2
@@ -48,7 +48,7 @@ bool __initdata opt_watchdog;/* watchdog_force: If true, process unknown NMIs when running the watchdog. */ bool watchdog_force; -static int __init parse_watchdog (const char *s) +static int __init cf_check parse_watchdog(const char *s) {if ( !*s ) {
@@ -78,7 +78,7 @@ custom_param("watchdog", parse_watchdog);/* opt_watchdog_timeout: Number of seconds to wait before panic. */ static unsigned int opt_watchdog_timeout =5 ; -static int parse_watchdog_timeout (const char *s) +static int __init cf_check parse_watchdog_timeout(const char *s) {const char *q;
xen/arch/x86/numa.c +2 -4
@@ -19,9 +19,6 @@#include <xen/sched.h> #include <xen/softirq.h> -static int numa_setup (const char *s); -custom_param ("numa" , numa_setup); -#ifndef Dprintk #define Dprintk(x...)#endif
@@ -294,7 +291,7 @@ void numa_set_node(int cpu, nodeid_t node) }/* [numa=off] */ -static __init int numa_setup (const char *opt) +static int __init cf_check numa_setup(const char *opt) {if ( !strncmp (opt,"off" ,3 ) ) numa_off = true;
@@ -321,6 +318,7 @@ static __init int numa_setup(const char *opt)return 0 ; } +custom_param ("numa" , numa_setup);/* * Setup early cpu_to_node.
xen/arch/x86/oprofile/nmi_int.c +1 -1
@@ -340,7 +340,7 @@ static int __init p4_init(char ** cpu_type)static int force_arch_perfmon; -static int force_cpu_type (const char *str) +static int __init cf_check force_cpu_type(const char *str) {if (!strcmp (str,"arch_perfmon" )) { force_arch_perfmon =1 ;
xen/arch/x86/psr.c +1 -1
@@ -573,7 +573,7 @@ static bool __init parse_psr_bool(const char *s, const char *delim,return false; } -static int __init parse_psr_param (const char *s) +static int __init cf_check parse_psr_param(const char *s) {const char *ss, *val_delim;const char *q;
xen/arch/x86/pv/domain.c +4 -4
@@ -20,7 +20,7 @@int8_t __read_mostly opt_pv32 =-1 ;#endif -static __init int parse_pv (const char *s) +static int __init cf_check parse_pv(const char *s) {const char *ss;int val, rc =0 ;
@@ -63,16 +63,16 @@ static const char opt_pcid_2_string[][7] = { [PCID_NOXPTI] = "noxpti", }; -static void __init opt_pcid_init (struct param_hypfs *par) +static void __init cf_check opt_pcid_init(struct param_hypfs *par) {custom_runtime_set_var (par, opt_pcid_2_string[opt_pcid]); }#endif -static int parse_pcid (const char *s); +static int cf_check parse_pcid(const char *s);custom_runtime_param ("pcid" , parse_pcid, opt_pcid_init); -static int parse_pcid (const char *s) +static int cf_check parse_pcid(const char *s) {int rc =0 ;
xen/arch/x86/pv/shim.c +1 -1
@@ -73,7 +73,7 @@ static uint64_t __initdata shim_nrpages;static uint64_t __initdata shim_min_nrpages;static uint64_t __initdata shim_max_nrpages; -static int __init parse_shim_mem (const char *s) +static int __init cf_check parse_shim_mem(const char *s) { do { if ( !strncmp(s, "min:", 4) )
xen/arch/x86/setup.c +5 -6
@@ -81,8 +81,6 @@ unsigned long __read_mostly cr4_pv32_mask;/* "acpi=ht": Limit ACPI just to boot-time to enable HT. */ /* "acpi=noirq": Disables ACPI interrupt routing. */ /* "acpi=verbose": Enables more verbose ACPI boot time logging. */ -static int parse_acpi_param (const char *s); -custom_param ("acpi" , parse_acpi_param);/* **** Linux config option: propagated to domain0. */ /* noapic: Disable IOAPIC setup. */
@@ -104,7 +102,7 @@ static bool __initdata opt_xen_shstk = true;#define opt_xen_shstk false#endif -static int __init parse_cet (const char *s) +static int __init cf_check parse_cet(const char *s) {const char *ss;int val, rc =0 ;
@@ -159,7 +157,7 @@ static s8 __initdata opt_smep = -1;*/ static struct domain *__initdata dom0; -static int __init parse_smep_param (const char *s) +static int __init cf_check parse_smep_param(const char *s) {if ( !*s ) {
@@ -190,7 +188,7 @@ custom_param("smep", parse_smep_param);#define SMAP_HVM_ONLY (-2)static s8 __initdata opt_smap =-1 ; -static int __init parse_smap_param (const char *s) +static int __init cf_check parse_smap_param(const char *s) {if ( !*s ) {
@@ -221,7 +219,7 @@ bool __read_mostly acpi_disabled;bool __initdata acpi_force;static char __initdata acpi_param[10 ] ="" ; -static int __init parse_acpi_param (const char *s) +static int __init cf_check parse_acpi_param(const char *s) {/* Interpret the parameter for use within Xen. */ if ( !parse_bool (s,NULL ) )
@@ -257,6 +255,7 @@ static int __init parse_acpi_param(const char *s)return 0 ; } +custom_param ("acpi" , parse_acpi_param);static const module_t *__initdata initial_images;static unsigned int __initdata nr_initial_images;
xen/arch/x86/shutdown.c +1 -1
@@ -56,7 +56,7 @@ static int reboot_mode;*/ static enum reboot_type reboot_type =BOOT_INVALID ; -static int __init set_reboot_type (const char *str) +static int __init cf_check set_reboot_type(const char *str) {int rc =0 ;
xen/arch/x86/spec_ctrl.c +3 -3
@@ -68,7 +68,7 @@ static bool __initdata cpu_has_bug_mds; /* Any other M{LP,SB,FB}DS combination.static int8_t __initdata opt_srb_lock =-1 ; -static int __init parse_spec_ctrl (const char *s) +static int __init cf_check parse_spec_ctrl(const char *s) {const char *ss;int val, rc =0 ;
@@ -218,7 +218,7 @@ static __init void xpti_init_default(uint64_t caps) } } -static __init int parse_xpti (const char *s) +static int __init cf_check parse_xpti(const char *s) {const char *ss;int val, rc =0 ;
@@ -264,7 +264,7 @@ custom_param("xpti", parse_xpti);int8_t __read_mostly opt_pv_l1tf_hwdom =-1 ;int8_t __read_mostly opt_pv_l1tf_domu =-1 ; -static __init int parse_pv_l1tf (const char *s) +static int __init cf_check parse_pv_l1tf(const char *s) {const char *ss;int val, rc =0 ;
xen/arch/x86/time.c +1 -1
@@ -2354,7 +2354,7 @@ int hwdom_pit_access(struct ioreq *ioreq)* tsc=skewed: Assume TSCs are individually reliable, but skewed across CPUs. * tsc=stable:socket: Assume TSCs are reliable across sockets. */ -static int __init tsc_parse (const char *s) +static int __init cf_check tsc_parse(const char *s) {if ( !strcmp (s,"unstable" ) ) {
xen/arch/x86/tsx.c +1 -1
@@ -22,7 +22,7 @@ int8_t __read_mostly opt_tsx = -1;int8_t __read_mostly cpu_has_tsx_ctrl =-1 ;bool __read_mostly rtm_disabled; -static int __init parse_tsx (const char *s) +static int __init cf_check parse_tsx(const char *s) {int rc =0 , val =parse_bool (s,NULL );
xen/arch/x86/x86_64/mmconfig-shared.c +1 -1
@@ -29,7 +29,7 @@unsigned int pci_probe =PCI_PROBE_CONF1 |PCI_PROBE_MMCONF ; -static int __init parse_mmcfg (const char *s) +static int __init cf_check parse_mmcfg(const char *s) {const char *ss;int rc =0 ;
xen/common/argo.c +1 -1
@@ -78,7 +78,7 @@ DEFINE_COMPAT_HANDLE(compat_argo_iov_t);static bool __read_mostly opt_argo;static bool __read_mostly opt_argo_mac_permissive; -static int __init parse_argo (const char *s) +static int __init cf_check parse_argo(const char *s) {const char *ss;int val, rc =0 ;
xen/common/core_parking.c +1 -1
@@ -40,7 +40,7 @@ static enum core_parking_controller {PERFORMANCE_FIRST } core_parking_controller __initdata = POWER_FIRST; -static int __init setup_core_parking_option (const char *str) +static int __init cf_check setup_core_parking_option(const char *str) {if ( !strcmp (str,"power" ) ) core_parking_controller =POWER_FIRST ;
xen/common/debugtrace.c +1 -1
@@ -38,7 +38,7 @@ static bool debugtrace_buf_empty = true;static bool debugtrace_used;static DEFINE_SPINLOCK (debugtrace_lock); -static int __init debugtrace_parse_param (const char *s) +static int __init cf_check debugtrace_parse_param(const char *s) {unsigned long bytes;
xen/common/domain.c +1 -1
@@ -354,7 +354,7 @@ static int late_hwdom_init(struct domain *d)static unsigned int __read_mostly extra_hwdom_irqs;static unsigned int __read_mostly extra_domU_irqs =32 ; -static int __init parse_extra_guest_irqs (const char *s) +static int __init cf_check parse_extra_guest_irqs(const char *s) {if (isdigit (*s) ) extra_domU_irqs =simple_strtoul (s, &s,0 );
xen/common/efi/boot.c +1 -1
@@ -1417,7 +1417,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)static bool __initdata efi_map_uc; -static int __init parse_efi_param (const char *s) +static int __init cf_check parse_efi_param(const char *s) {const char *ss;int rc =0 , val;
xen/common/grant_table.c +7 -7
@@ -117,12 +117,12 @@ static void update_gnttab_par(unsigned int val, struct param_hypfs *par,custom_runtime_set_var_sz (par, parval,GRANT_CUSTOM_VAL_SZ ); } -static void __init gnttab_max_frames_init (struct param_hypfs *par) +static void __init cf_check gnttab_max_frames_init(struct param_hypfs *par) {update_gnttab_par (opt_max_grant_frames, par, opt_max_grant_frames_val); } -static void __init max_maptrack_frames_init (struct param_hypfs *par) +static void __init cf_check max_maptrack_frames_init(struct param_hypfs *par) {update_gnttab_par (opt_max_maptrack_frames, par, opt_max_maptrack_frames_val);
@@ -156,23 +156,23 @@ static int parse_gnttab_limit(const char *arg, unsigned int *valp,return 0 ; } -static int parse_gnttab_max_frames (const char *arg); +static int cf_check parse_gnttab_max_frames(const char *arg);custom_runtime_param ("gnttab_max_frames" , parse_gnttab_max_frames, gnttab_max_frames_init); -static int parse_gnttab_max_frames (const char *arg) +static int cf_check parse_gnttab_max_frames(const char *arg) {return parse_gnttab_limit (arg, &opt_max_grant_frames,param_2_parfs (parse_gnttab_max_frames), opt_max_grant_frames_val); } -static int parse_gnttab_max_maptrack_frames (const char *arg); +static int cf_check parse_gnttab_max_maptrack_frames(const char *arg);custom_runtime_param ("gnttab_max_maptrack_frames" , parse_gnttab_max_maptrack_frames, max_maptrack_frames_init); -static int parse_gnttab_max_maptrack_frames (const char *arg) +static int cf_check parse_gnttab_max_maptrack_frames(const char *arg) { return parse_gnttab_limit(arg, &opt_max_maptrack_frames, param_2_parfs(parse_gnttab_max_maptrack_frames),
@@ -191,7 +191,7 @@ static bool __ro_after_init opt_grant_transfer = true;#define opt_grant_transfer false#endif -static int __init parse_gnttab (const char *s) +static int __init cf_check parse_gnttab(const char *s) {const char *ss, *e;int val, rc =0 ;
xen/common/kexec.c +3 -3
@@ -104,7 +104,7 @@ static void *crash_heap_current = NULL, *crash_heap_end = NULL;* < and below are synonyomous, the latter being useful for grub2 systems * which would otherwise require escaping of the < option */ -static int __init parse_crashkernel (const char *str) +static int __init cf_check parse_crashkernel(const char *str) {const char *cur;int rc =0 ;
@@ -201,7 +201,7 @@ custom_param("crashkernel", parse_crashkernel);* - all will allocate additional structures such as domain and vcpu structs * low so the crash kernel can perform an extended analysis of state. */ -static int __init parse_low_crashinfo (const char *str) +static int __init cf_check parse_low_crashinfo(const char *str) {if ( !strlen (str) )
@@ -230,7 +230,7 @@ custom_param("low_crashinfo", parse_low_crashinfo);* * <addr> will be rounded down to the nearest power of two. Defaults to 64G */ -static int __init parse_crashinfo_maxaddr (const char *str) +static int __init cf_check parse_crashinfo_maxaddr(const char *str) {u64 addr;const char *q;
xen/common/memory.c +1 -1
@@ -62,7 +62,7 @@ static unsigned int __read_mostly hwdom_max_order = CONFIG_HWDOM_MAX_ORDER;static unsigned int __read_mostly ptdom_max_order =CONFIG_PTDOM_MAX_ORDER ;#endif -static int __init parse_max_order (const char *s) +static int __init cf_check parse_max_order(const char *s) {if ( *s !=',' ) domu_max_order =simple_strtoul (s, &s,0 );
xen/common/page_alloc.c +1 -1
@@ -179,7 +179,7 @@ enum bootscrub_mode {* https://bugs.llvm.org/show_bug.cgi?id=39707 */ static enum bootscrub_mode __read_mostly opt_bootscrub =BOOTSCRUB_IDLE ; -static int __init parse_bootscrub_param (const char *s) +static int __init cf_check parse_bootscrub_param(const char *s) {/* Interpret 'bootscrub' alone in its positive boolean form */ if ( *s =='\0' )
xen/common/sched/cpupool.c +1 -1
@@ -93,7 +93,7 @@ static int sched_gran_get(const char *str, enum sched_gran *mode)return -EINVAL ; } -static int __init sched_select_granularity (const char *str) +static int __init cf_check sched_select_granularity(const char *str) {return sched_gran_get (str, &opt_sched_granularity); }
xen/common/sched/credit2.c +1 -1
@@ -456,7 +456,7 @@ static const char *const opt_runqueue_str[] = { };static int __read_mostly opt_runqueue =OPT_RUNQUEUE_SOCKET ; -static int __init parse_credit2_runqueue (const char *s) +static int __init cf_check parse_credit2_runqueue(const char *s) {unsigned int i;
xen/drivers/acpi/tables.c +1 -1
@@ -472,7 +472,7 @@ int __init acpi_table_init(void)return 0 ; } -static int __init acpi_parse_apic_instance (const char *str) +static int __init cf_check acpi_parse_apic_instance(const char *str) {const char *q;
xen/drivers/char/console.c +9 -9
@@ -88,7 +88,7 @@ static const char con_timestamp_mode_2_string[][7] = { [TSM_RAW] = "raw", }; -static void con_timestamp_mode_upd (struct param_hypfs *par) +static void cf_check con_timestamp_mode_upd(struct param_hypfs *par) {const char *val = con_timestamp_mode_2_string[opt_con_timestamp_mode];
@@ -98,7 +98,7 @@ static void con_timestamp_mode_upd(struct param_hypfs *par)#define con_timestamp_mode_upd (par)#endif -static int parse_console_timestamps (const char *s); +static int cf_check parse_console_timestamps(const char *s);custom_runtime_param ("console_timestamps" , parse_console_timestamps, con_timestamp_mode_upd);
@@ -160,8 +160,8 @@ static int __read_mostly xenlog_guest_upper_thresh =static int __read_mostly xenlog_guest_lower_thresh =XENLOG_GUEST_LOWER_THRESHOLD ; -static int parse_loglvl (const char *s); -static int parse_guest_loglvl (const char *s); +static int cf_check parse_loglvl(const char *s); +static int cf_check parse_guest_loglvl(const char *s);#ifdef CONFIG_HYPFS #define LOGLVL_VAL_SZ 16
@@ -176,13 +176,13 @@ static void xenlog_update_val(int lower, int upper, char *val)snprintf (val,LOGLVL_VAL_SZ ,"%s/%s" , lvl2opt[lower], lvl2opt[upper]); } -static void __init xenlog_init (struct param_hypfs *par) +static void __init cf_check xenlog_init(struct param_hypfs *par) {xenlog_update_val (xenlog_lower_thresh, xenlog_upper_thresh, xenlog_val);custom_runtime_set_var (par, xenlog_val); } -static void __init xenlog_guest_init (struct param_hypfs *par) +static void __init cf_check xenlog_guest_init(struct param_hypfs *par) {xenlog_update_val (xenlog_guest_lower_thresh, xenlog_guest_upper_thresh, xenlog_guest_val);
@@ -240,7 +240,7 @@ static int _parse_loglvl(const char *s, int *lower, int *upper, char *val)return *s ? -EINVAL :0 ; } -static int parse_loglvl (const char *s) +static int cf_check parse_loglvl(const char *s) {int ret;
@@ -251,7 +251,7 @@ static int parse_loglvl(const char *s)return ret; } -static int parse_guest_loglvl (const char *s) +static int cf_check parse_guest_loglvl(const char *s) {int ret;
@@ -793,7 +793,7 @@ static int printk_prefix_check(char *p, char **pp) ((loglvl < upper_thresh) && printk_ratelimit())); } -static int parse_console_timestamps (const char *s) +static int cf_check parse_console_timestamps(const char *s) {switch (parse_bool (s,NULL ) ) {
xen/drivers/cpufreq/cpufreq.c +1 -1
@@ -65,7 +65,7 @@ enum cpufreq_controller cpufreq_controller = FREQCTL_xen;static int __init cpufreq_cmdline_parse (const char *s); -static int __init setup_cpufreq_option (const char *str) +static int __init cf_check setup_cpufreq_option(const char *str) {const char *arg =strpbrk (str,",:" );int choice;
xen/drivers/passthrough/amd/iommu_acpi.c +3 -3
@@ -704,7 +704,7 @@ static u16 __init parse_ivhd_device_extended_range(return dev_length; } -static int __init parse_ivrs_ioapic (const char *str) +static int __init cf_check parse_ivrs_ioapic(const char *str) {const char *s = str;unsigned long id;
@@ -742,7 +742,7 @@ static int __init parse_ivrs_ioapic(const char *str) }custom_param ("ivrs_ioapic[" , parse_ivrs_ioapic); -static int __init parse_ivrs_hpet (const char *str) +static int __init cf_check parse_ivrs_hpet(const char *str) {const char *s = str;unsigned long id;
@@ -1369,7 +1369,7 @@ int __init amd_iommu_get_supported_ivhd_type(void)* Format: * ivmd=<start>[-<end>][=<bdf1>[-<bdf1>'][,<bdf2>[-<bdf2>'][,...]]][;<start>...] */ -static int __init parse_ivmd_param (const char *s) +static int __init cf_check parse_ivmd_param(const char *s) { do { unsigned long start, end;
xen/drivers/passthrough/iommu.c +2 -2
@@ -64,7 +64,7 @@ bool_t __read_mostly amd_iommu_perdev_intremap = 1;DEFINE_PER_CPU (bool_t, iommu_dont_flush_iotlb); -static int __init parse_iommu_param (const char *s) +static int __init cf_check parse_iommu_param(const char *s) {const char *ss;int val, rc =0 ;
@@ -135,7 +135,7 @@ static int __init parse_iommu_param(const char *s) }custom_param ("iommu" , parse_iommu_param); -static int __init parse_dom0_iommu_param (const char *s) +static int __init cf_check parse_dom0_iommu_param(const char *s) {const char *ss;int rc =0 ;
xen/drivers/passthrough/pci.c +2 -2
@@ -146,7 +146,7 @@ static struct phantom_dev { } phantom_devs[8 ];static unsigned int nr_phantom_devs; -static int __init parse_phantom_dev (const char *str) +static int __init cf_check parse_phantom_dev(const char *str) {const char *s;unsigned int seg, bus, slot;
@@ -182,7 +182,7 @@ custom_param("pci-phantom", parse_phantom_dev);static u16 __read_mostly command_mask;static u16 __read_mostly bridge_ctl_mask; -static int __init parse_pci_param (const char *s) +static int __init cf_check parse_pci_param(const char *s) {const char *ss;int rc =0 ;
xen/drivers/passthrough/vtd/dmar.c +1 -1
@@ -1084,7 +1084,7 @@ int intel_iommu_get_reserved_device_memory(iommu_grdm_t *func, void *ctxt)* If a segment is specified for other than the first device, and it does not * match the one specified for the first one, an error will be reported. */ -static int __init parse_rmrr_param (const char *str) +static int __init cf_check parse_rmrr_param(const char *str) {const char *s = str, *cur, *stmp;unsigned int seg, bus, dev, func, dev_count;
xen/drivers/passthrough/vtd/quirks.c +1 -1
@@ -308,7 +308,7 @@ void vtd_ops_postamble_quirk(struct vtd_iommu *iommu) } } -static int __init parse_snb_timeout (const char *s) +static int __init cf_check parse_snb_timeout(const char *s) {int t;const char *q =NULL ;
xen/drivers/video/vesa.c +1 -1
@@ -29,7 +29,7 @@ integer_param("vesa-ram", vram_total);static unsigned int __initdata vram_remap;static unsigned int __initdata font_height; -static int __init parse_font_height (const char *s) +static int __init cf_check parse_font_height(const char *s) {if (simple_strtoul (s, &s,10 ) ==8 && (*s++ =='x' ) ) font_height =simple_strtoul (s, &s,10 );
xen/xsm/flask/flask_op.c +2 -3
@@ -28,8 +28,6 @@#define _copy_from_guest copy_from_guestenum flask_bootparam_t __read_mostly flask_bootparam =FLASK_BOOTPARAM_ENFORCING ; -static int parse_flask_param (const char *s); -custom_param ("flask" , parse_flask_param);bool __read_mostly flask_enforcing = true;
@@ -60,7 +58,7 @@ static int flask_security_make_bools(void);extern int ss_initialized; -static int __init parse_flask_param (const char *s) +static int __init cf_check parse_flask_param(const char *s) {if ( !strcmp (s,"enforcing" ) ) flask_bootparam =FLASK_BOOTPARAM_ENFORCING ;
@@ -75,6 +73,7 @@ static int __init parse_flask_param(const char *s)return (flask_bootparam ==FLASK_BOOTPARAM_INVALID ) ? -EINVAL :0 ; } +custom_param ("flask" , parse_flask_param);static int domain_has_security (struct domain *d,u32 perms) {
xen/xsm/xsm_core.c +1 -1
@@ -55,7 +55,7 @@ static enum xsm_bootparam __initdata xsm_bootparam =XSM_BOOTPARAM_DUMMY ;#endif -static int __init parse_xsm_param (const char *s) +static int __init cf_check parse_xsm_param(const char *s) {int rc =0 ;
Signature · 1 line
2.11.0
PATCH v3 12/70 xen: CFI hardening for continue_hypercall_on_cpu()
In reply to Andrew CooperControl Flow Integrity schemes use toolchain and optionally hardware support to help protect against call/jump/return oriented programming attacks.
Use cf_check to annotate function pointer targets for the toolchain.
---
v3:
* Fix !CONFIG_PV_SHIM build. Annotate pv_shim_cpu_{up,down}() stubs.
--- xen/arch/x86/acpi/power.c | 2 +- xen/arch/x86/cpu/microcode/core.c | 2 +- xen/arch/x86/include/asm/pv/shim.h | 8 ++++---- xen/arch/x86/include/asm/smp.h | 6 +++--- xen/arch/x86/platform_hypercall.c | 4 ++-- xen/arch/x86/pv/shim.c | 4 ++-- xen/arch/x86/smp.c | 4 ++-- xen/arch/x86/sysctl.c | 2 +- xen/common/core_parking.c | 2 +- xen/common/kexec.c | 2 +- xen/common/sched/cpupool.c | 2 +- 11 files changed, 19 insertions(+), 19 deletions(-)
xen/arch/x86/acpi/power.c +1 -1
@@ -326,7 +326,7 @@ static int enter_state(u32 state)return error; } -static long enter_state_helper (void *data) +static long cf_check enter_state_helper (void *data) {struct acpi_sleep_info *sinfo = (struct acpi_sleep_info *)data;return enter_state (sinfo->sleep_state);
xen/arch/x86/cpu/microcode/core.c +1 -1
@@ -558,7 +558,7 @@ struct ucode_buf {char buffer[]; }; -static long microcode_update_helper (void *data) +static long cf_check microcode_update_helper (void *data) {int ret;struct ucode_buf *buffer = data;
xen/arch/x86/include/asm/pv/shim.h +4 -4
@@ -38,8 +38,8 @@ void pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start, start_info_t *si);int pv_shim_shutdown (uint8_t reason);void pv_shim_inject_evtchn (unsigned int port); -long pv_shim_cpu_up (void *data); -long pv_shim_cpu_down (void *data); +long cf_check pv_shim_cpu_up (void *data); +long cf_check pv_shim_cpu_down (void *data);void pv_shim_online_memory (unsigned int nr,unsigned int order);void pv_shim_offline_memory (unsigned int nr,unsigned int order);domid_t get_initial_domain_id (void );
@@ -69,12 +69,12 @@ static inline void pv_shim_inject_evtchn(unsigned int port) {ASSERT_UNREACHABLE (); } -static inline long pv_shim_cpu_up (void *data) +static inline long cf_check pv_shim_cpu_up (void *data) {ASSERT_UNREACHABLE ();return 0 ; } -static inline long pv_shim_cpu_down (void *data) +static inline long cf_check pv_shim_cpu_down (void *data) {ASSERT_UNREACHABLE ();return 0 ;
xen/arch/x86/include/asm/smp.h +3 -3
@@ -57,10 +57,10 @@ int cpu_add(uint32_t apic_id, uint32_t acpi_id, uint32_t pxm);void __stop_this_cpu (void ); -long cpu_up_helper (void *data); -long cpu_down_helper (void *data); +long cf_check cpu_up_helper (void *data); +long cf_check cpu_down_helper (void *data); -long core_parking_helper (void *data); +long cf_check core_parking_helper (void *data);bool core_parking_remove (unsigned int cpu);uint32_t get_cur_idle_nums (void );
xen/arch/x86/platform_hypercall.c +2 -2
@@ -45,7 +45,7 @@ struct resource_access {xenpf_resource_entry_t *entries; }; -long cpu_frequency_change_helper (void *); +long cf_check cpu_frequency_change_helper (void *);void check_resource_access (struct resource_access *);void resource_access (void *);
@@ -59,7 +59,7 @@ DEFINE_SPINLOCK(xenpf_lock);# undef guest_from_compat_handle# define guest_from_compat_handle (x,y) ((x)=(y)) -long cpu_frequency_change_helper (void *data) +long cf_check cpu_frequency_change_helper (void *data) {return cpu_frequency_change ((uint64_t )data); }
xen/arch/x86/pv/shim.c +2 -2
@@ -845,7 +845,7 @@ int cf_check compat_grant_table_op(#endif #endif -long pv_shim_cpu_up (void *data) +long cf_check pv_shim_cpu_up (void *data) {struct vcpu *v = data;struct domain *d = v->domain;
@@ -883,7 +883,7 @@ long pv_shim_cpu_up(void *data)return 0 ; } -long pv_shim_cpu_down (void *data) +long cf_check pv_shim_cpu_down (void *data) {struct vcpu *v = data;long rc;
xen/arch/x86/smp.c +2 -2
@@ -399,7 +399,7 @@ void call_function_interrupt(struct cpu_user_regs *regs)smp_call_function_interrupt (); } -long cpu_up_helper (void *data) +long cf_check cpu_up_helper (void *data) {unsigned int cpu = (unsigned long )data;int ret =cpu_up (cpu);
@@ -422,7 +422,7 @@ long cpu_up_helper(void *data)return ret; } -long cpu_down_helper (void *data) +long cf_check cpu_down_helper (void *data) {int cpu = (unsigned long )data;int ret =cpu_down (cpu);
xen/arch/x86/sysctl.c +1 -1
@@ -79,7 +79,7 @@ static void l3_cache_get(void *arg) l3_info->size = info.size /1024 ;/* in KB unit */ } -static long smt_up_down_helper (void *data) +static long cf_check smt_up_down_helper (void *data) {bool up = (bool )data;unsigned int cpu, sibling_mask = boot_cpu_data.x86_num_siblings -1 ;
xen/common/core_parking.c +1 -1
@@ -169,7 +169,7 @@ static unsigned int core_parking_power(unsigned int event)return cpu; } -long core_parking_helper (void *data) +long cf_check core_parking_helper (void *data) {uint32_t idle_nums = (unsigned long )data;unsigned int cpu;
xen/common/kexec.c +1 -1
@@ -395,7 +395,7 @@ void kexec_crash(enum crash_reason reason)BUG (); } -static long kexec_reboot (void *_image) +static long cf_check kexec_reboot (void *_image) {struct kexec_image *image = _image;
xen/common/sched/cpupool.c +1 -1
@@ -544,7 +544,7 @@ static int cpupool_unassign_cpu_start(struct cpupool *c, unsigned int cpu)return ret; } -static long cpupool_unassign_cpu_helper (void *info) +static long cf_check cpupool_unassign_cpu_helper (void *info) {struct cpupool *c = info;long ret;
Signature · 1 line
2.11.0
PATCH v3 26/70 xen/iommu: CFI hardening
In reply to Andrew CooperControl Flow Integrity schemes use toolchain and optionally hardware support to help protect against call/jump/return oriented programming attacks.
Use cf_check to annotate function pointer targets for the toolchain.
AMD's parse_ppr_log_entry() has no external callers, so becomes static.
---
v3:
* Rebase over recent commits
--- xen/common/compat/memory.c | 4 +- xen/drivers/passthrough/amd/iommu.h | 41 ++++++++-------- xen/drivers/passthrough/amd/iommu_init.c | 22 ++++----- xen/drivers/passthrough/amd/iommu_intr.c | 18 +++---- xen/drivers/passthrough/amd/iommu_map.c | 22 +++++---- xen/drivers/passthrough/amd/pci_amd_iommu.c | 32 ++++++------- xen/drivers/passthrough/pci.c | 7 +-- xen/drivers/passthrough/vtd/dmar.c | 3 +- xen/drivers/passthrough/vtd/extern.h | 36 +++++++------- xen/drivers/passthrough/vtd/intremap.c | 14 +++--- xen/drivers/passthrough/vtd/iommu.c | 73 +++++++++++++++-------------- xen/drivers/passthrough/vtd/qinval.c | 28 +++++------ 12 files changed, 152 insertions(+), 148 deletions(-)
xen/common/compat/memory.c +2 -2
@@ -23,8 +23,8 @@ struct get_reserved_device_memory {unsigned int used_entries; }; -static int get_reserved_device_memory (xen_pfn_t start,xen_ulong_t nr, -u32 id,void *ctxt) +static int cf_check get_reserved_device_memory( +xen_pfn_t start,xen_ulong_t nr,u32 id,void *ctxt) {struct get_reserved_device_memory *grdm = ctxt; uint32_t sbdf = PCI_SBDF3(grdm->map.dev.pci.seg, grdm->map.dev.pci.bus,
xen/drivers/passthrough/amd/iommu.h +21 -20
76 lines not on this page · raw message
xen/drivers/passthrough/amd/iommu_init.c +11 -11
@@ -258,8 +258,8 @@ static void register_iommu_exclusion_range(struct amd_iommu *iommu)writel (entry, iommu->mmio_base+IOMMU_EXCLUSION_BASE_LOW_OFFSET ); } -static void set_iommu_event_log_control (struct amd_iommu *iommu, -bool enable) +static void cf_check set_iommu_event_log_control( +struct amd_iommu *iommu,bool enable) {/* Reset head and tail pointer manually before enablement */ if ( enable )
@@ -275,8 +275,8 @@ static void set_iommu_event_log_control(struct amd_iommu *iommu,writeq (iommu->ctrl.raw, iommu->mmio_base +IOMMU_CONTROL_MMIO_OFFSET ); } -static void set_iommu_ppr_log_control (struct amd_iommu *iommu, -bool enable) +static void cf_check set_iommu_ppr_log_control( +struct amd_iommu *iommu,bool enable) {/* Reset head and tail pointer manually before enablement */ if ( enable )
@@ -527,7 +527,7 @@ static hw_irq_controller iommu_x2apic_type = { .set_affinity = set_x2apic_affinity, }; -static void parse_event_log_entry (struct amd_iommu *iommu,u32 entry[]) +static void cf_check parse_event_log_entry(struct amd_iommu *iommu, u32 entry[]) {u32 code;static const char *const event_str[] = {
@@ -628,7 +628,7 @@ static void iommu_check_event_log(struct amd_iommu *iommu)spin_unlock_irqrestore (&iommu->lock, flags); } -void parse_ppr_log_entry (struct amd_iommu *iommu,u32 entry[]) +static void cf_check parse_ppr_log_entry(struct amd_iommu *iommu, u32 entry[]) {u16 device_id;
@@ -1243,7 +1243,7 @@ static int __init alloc_ivrs_mappings(u16 seg)return 0 ; } -static int __init amd_iommu_setup_device_table ( +static int __init cf_check amd_iommu_setup_device_table(u16 seg,struct ivrs_mappings *ivrs_mappings) {struct amd_iommu_dte *dt =IVRS_MAPPINGS_DEVTAB (ivrs_mappings);
@@ -1543,7 +1543,7 @@ static void invalidate_all_domain_pages(void)amd_iommu_flush_all_pages (d); } -static int _invalidate_all_devices ( +static int cf_check _invalidate_all_devices(u16 seg,struct ivrs_mappings *ivrs_mappings) {unsigned int bdf;
@@ -1569,14 +1569,14 @@ static void invalidate_all_devices(void)iterate_ivrs_mappings (_invalidate_all_devices); } -int amd_iommu_suspend (void ) +int cf_check amd_iommu_suspend(void) {amd_iommu_crash_shutdown ();return 0 ; } -void amd_iommu_crash_shutdown (void ) +void cf_check amd_iommu_crash_shutdown(void) {struct amd_iommu *iommu;
@@ -1584,7 +1584,7 @@ void amd_iommu_crash_shutdown(void)disable_iommu (iommu); } -void amd_iommu_resume (void ) +void cf_check amd_iommu_resume(void) {struct amd_iommu *iommu;
xen/drivers/passthrough/amd/iommu_intr.c +9 -9
@@ -349,7 +349,7 @@ static int update_intremap_entry_from_ioapic(return 0 ; } -void amd_iommu_ioapic_update_ire ( +void cf_check amd_iommu_ioapic_update_ire(unsigned int apic,unsigned int reg,unsigned int value) {struct IO_APIC_route_entry old_rte = {0 };
@@ -455,7 +455,7 @@ void amd_iommu_ioapic_update_ire( } } -unsigned int amd_iommu_read_ioapic_from_ire ( +unsigned int cf_check amd_iommu_read_ioapic_from_ire(unsigned int apic,unsigned int reg) {unsigned int idx;
@@ -608,7 +608,7 @@ static struct amd_iommu *_find_iommu_for_device(int seg, int bdf)return ERR_PTR (-EINVAL ); } -int amd_iommu_msi_msg_update_ire ( +int cf_check amd_iommu_msi_msg_update_ire(struct msi_desc *msi_desc,struct msi_msg *msg) {struct pci_dev *pdev = msi_desc->dev;
@@ -653,7 +653,7 @@ int amd_iommu_msi_msg_update_ire(return rc; } -int amd_iommu_free_intremap_table ( +int cf_check amd_iommu_free_intremap_table(const struct amd_iommu *iommu,struct ivrs_mappings *ivrs_mapping,uint16_t bdf) {
@@ -727,7 +727,7 @@ void *amd_iommu_alloc_intremap_table(return tb; } -bool __init iov_supports_xt (void ) +bool __init cf_check iov_supports_xt(void) {unsigned int apic;
@@ -756,7 +756,7 @@ bool __init iov_supports_xt(void)return true; } -int __init amd_setup_hpet_msi (struct msi_desc *msi_desc) +int __init cf_check amd_setup_hpet_msi(struct msi_desc *msi_desc) {const struct amd_iommu *iommu;spinlock_t *lock;
@@ -826,9 +826,9 @@ static void dump_intremap_table(const struct amd_iommu *iommu, } } -static int dump_intremap_mapping (const struct amd_iommu *iommu, -struct ivrs_mappings *ivrs_mapping, -uint16_t unused) +static int cf_check dump_intremap_mapping( +const struct amd_iommu *iommu,struct ivrs_mappings *ivrs_mapping, +uint16_t unused) {unsigned long flags;
xen/drivers/passthrough/amd/iommu_map.c +12 -10
@@ -276,8 +276,9 @@ static int iommu_pde_from_dfn(struct domain *d, unsigned long dfn,return 0 ; } -int amd_iommu_map_page (struct domain *d,dfn_t dfn,mfn_t mfn, -unsigned int flags,unsigned int *flush_flags) +int cf_check amd_iommu_map_page( +struct domain *d,dfn_t dfn,mfn_t mfn,unsigned int flags, +unsigned int *flush_flags) {struct domain_iommu *hd =dom_iommu (d);int rc;
@@ -326,8 +327,8 @@ int amd_iommu_map_page(struct domain *d, dfn_t dfn, mfn_t mfn,return 0 ; } -int amd_iommu_unmap_page (struct domain *d,dfn_t dfn, -unsigned int *flush_flags) +int cf_check amd_iommu_unmap_page( +struct domain *d,dfn_t dfn,unsigned int *flush_flags) {unsigned long pt_mfn =0 ;struct domain_iommu *hd =dom_iommu (d);
@@ -370,9 +371,9 @@ static unsigned long flush_count(unsigned long dfn, unsigned long page_count,return end - start; } -int amd_iommu_flush_iotlb_pages (struct domain *d,dfn_t dfn, -unsigned long page_count, -unsigned int flush_flags) +int cf_check amd_iommu_flush_iotlb_pages( +struct domain *d,dfn_t dfn,unsigned long page_count, +unsigned int flush_flags) {unsigned long dfn_l =dfn_x (dfn);
@@ -410,7 +411,7 @@ int amd_iommu_flush_iotlb_pages(struct domain *d, dfn_t dfn,return 0 ; } -int amd_iommu_flush_iotlb_all (struct domain *d) +int cf_check amd_iommu_flush_iotlb_all(struct domain *d) {amd_iommu_flush_all_pages (d);
@@ -462,7 +463,8 @@ int amd_iommu_reserve_domain_unity_unmap(struct domain *d,return rc; } -int amd_iommu_get_reserved_device_memory (iommu_grdm_t *func,void *ctxt) +int cf_check amd_iommu_get_reserved_device_memory( +iommu_grdm_t *func,void *ctxt) {unsigned int seg =0 /* XXX */ , bdf;const struct ivrs_mappings *ivrs_mappings =get_ivrs_mappings (seg);
@@ -537,7 +539,7 @@ int amd_iommu_get_reserved_device_memory(iommu_grdm_t *func, void *ctxt)return 0 ; } -int __init amd_iommu_quarantine_init (struct domain *d) +int __init cf_check amd_iommu_quarantine_init(struct domain *d) {struct domain_iommu *hd =dom_iommu (d); unsigned long end_gfn =
xen/drivers/passthrough/amd/pci_amd_iommu.c +16 -16
@@ -197,7 +197,7 @@ int __init acpi_ivrs_init(void)return 0 ; } -static int __init iov_detect (void ) +static int __init cf_check iov_detect(void) {if ( !iommu_enable && !iommu_intremap )return 0 ;
@@ -217,7 +217,7 @@ static int __init iov_detect(void)return 0 ; } -static int iov_enable_xt (void ) +static int cf_check iov_enable_xt(void) {int rc;
@@ -253,7 +253,7 @@ int amd_iommu_alloc_root(struct domain *d)unsigned int __read_mostly amd_iommu_max_paging_mode =6 ;int __read_mostly amd_iommu_min_paging_mode =1 ; -static int amd_iommu_domain_init (struct domain *d) +static int cf_check amd_iommu_domain_init(struct domain *d) {struct domain_iommu *hd =dom_iommu (d);
@@ -275,9 +275,9 @@ static int amd_iommu_domain_init(struct domain *d)return 0 ; } -static int amd_iommu_add_device (u8 devfn,struct pci_dev *pdev); +static int cf_check amd_iommu_add_device(u8 devfn, struct pci_dev *pdev); -static void __hwdom_init amd_iommu_hwdom_init(struct domain *d) +static void __hwdom_init cf_check amd_iommu_hwdom_init(struct domain *d) {const struct amd_iommu *iommu;
@@ -350,8 +350,9 @@ static void amd_iommu_disable_domain_device(const struct domain *domain,spin_unlock_irqrestore (&iommu->lock, flags); } -static int reassign_device (struct domain *source,struct domain *target, -u8 devfn,struct pci_dev *pdev) +static int cf_check reassign_device( +struct domain *source,struct domain *target,u8 devfn, +struct pci_dev *pdev) {struct amd_iommu *iommu;int bdf, rc;
@@ -404,9 +405,8 @@ static int reassign_device(struct domain *source, struct domain *target,return 0 ; } -static int amd_iommu_assign_device (struct domain *d,u8 devfn, -struct pci_dev *pdev, -u32 flag) +static int cf_check amd_iommu_assign_device( +struct domain *d,u8 devfn,struct pci_dev *pdev,u32 flag) {struct ivrs_mappings *ivrs_mappings =get_ivrs_mappings (pdev->seg);int bdf =PCI_BDF2 (pdev->bus, devfn);
@@ -435,7 +435,7 @@ static int amd_iommu_assign_device(struct domain *d, u8 devfn,return rc; } -static void amd_iommu_clear_root_pgtable (struct domain *d) +static void cf_check amd_iommu_clear_root_pgtable(struct domain *d) {struct domain_iommu *hd =dom_iommu (d);
@@ -444,13 +444,13 @@ static void amd_iommu_clear_root_pgtable(struct domain *d)spin_unlock (&hd->arch.mapping_lock); } -static void amd_iommu_domain_destroy (struct domain *d) +static void cf_check amd_iommu_domain_destroy(struct domain *d) {iommu_identity_map_teardown (d);ASSERT (!dom_iommu (d)->arch.amd.root_table); } -static int amd_iommu_add_device (u8 devfn,struct pci_dev *pdev) +static int cf_check amd_iommu_add_device(u8 devfn, struct pci_dev *pdev) {struct amd_iommu *iommu;u16 bdf;
@@ -525,7 +525,7 @@ static int amd_iommu_add_device(u8 devfn, struct pci_dev *pdev)return amd_iommu_setup_domain_device (pdev->domain, iommu, devfn, pdev); } -static int amd_iommu_remove_device (u8 devfn,struct pci_dev *pdev) +static int cf_check amd_iommu_remove_device(u8 devfn, struct pci_dev *pdev) {struct amd_iommu *iommu;u16 bdf;
@@ -562,7 +562,7 @@ static int amd_iommu_remove_device(u8 devfn, struct pci_dev *pdev)return 0 ; } -static int amd_iommu_group_id (u16 seg,u8 bus,u8 devfn) +static int cf_check amd_iommu_group_id(u16 seg, u8 bus, u8 devfn) {int bdf =PCI_BDF2 (bus, devfn);
@@ -616,7 +616,7 @@ static void amd_dump_page_table_level(struct page_info *pg, int level,unmap_domain_page (table_vaddr); } -static void amd_dump_page_tables (struct domain *d) +static void cf_check amd_dump_page_tables(struct domain *d) {const struct domain_iommu *hd =dom_iommu (d);
xen/drivers/passthrough/pci.c +4 -3
@@ -1098,7 +1098,7 @@ void pci_check_disable_device(u16 seg, u8 bus, u8 devfn)* scan pci devices to add all existed PCI devices to alldevs_list, * and setup pci hierarchy in array bus2bridge. */ -static int __init _scan_pci_devices (struct pci_seg *pseg,void *arg) +static int __init cf_check _scan_pci_devices(struct pci_seg *pseg, void *arg) {struct pci_dev *pdev;int bus, dev, func;
@@ -1176,7 +1176,8 @@ static void __hwdom_init setup_one_hwdom_device(const struct setup_hwdom *ctxt, ctxt->d->domain_id, err); } -static int __hwdom_init _setup_hwdom_pci_devices(struct pci_seg *pseg, void *arg) +static int __hwdom_init cf_check _setup_hwdom_pci_devices( +struct pci_seg *pseg,void *arg) {struct setup_hwdom *ctxt = arg;int bus, devfn;
@@ -1333,7 +1334,7 @@ bool_t pcie_aer_get_firmware_first(const struct pci_dev *pdev) }#endif -static int _dump_pci_devices (struct pci_seg *pseg,void *arg) +static int cf_check _dump_pci_devices(struct pci_seg *pseg, void *arg) {struct pci_dev *pdev;
xen/drivers/passthrough/vtd/dmar.c +2 -1
@@ -1046,7 +1046,8 @@ bool_t __init platform_supports_x2apic(void)return cpu_has_x2apic && ((dmar_flags & mask) ==ACPI_DMAR_INTR_REMAP ); } -int intel_iommu_get_reserved_device_memory (iommu_grdm_t *func,void *ctxt) +int cf_check intel_iommu_get_reserved_device_memory( +iommu_grdm_t *func,void *ctxt) {struct acpi_rmrr_unit *rmrr, *rmrr_cur =NULL ;unsigned int i;
xen/drivers/passthrough/vtd/extern.h +18 -18
@@ -33,9 +33,9 @@ void print_iommu_regs(struct acpi_drhd_unit *drhd);void print_vtd_entries (struct vtd_iommu *iommu,int bus,int devfn,u64 gmfn); keyhandler_fn_t cf_check vtd_dump_iommu_info; -bool intel_iommu_supports_eim (void ); -int intel_iommu_enable_eim (void ); -void intel_iommu_disable_eim (void ); +bool cf_check intel_iommu_supports_eim(void); +int cf_check intel_iommu_enable_eim(void); +void cf_check intel_iommu_disable_eim(void);int enable_qinval (struct vtd_iommu *iommu);void disable_qinval (struct vtd_iommu *iommu);
@@ -51,15 +51,13 @@ int iommu_flush_iec_global(struct vtd_iommu *iommu);int iommu_flush_iec_index (struct vtd_iommu *iommu,u8 im,u16 iidx);void clear_fault_bits (struct vtd_iommu *iommu); -int __must_check vtd_flush_context_reg (struct vtd_iommu *iommu,uint16_t did, -uint16_t source_id, -uint8_t function_mask,uint64_t type, -bool flush_non_present_entry); -int __must_check vtd_flush_iotlb_reg (struct vtd_iommu *iommu,uint16_t did, -uint64_t addr,unsigned int size_order, -uint64_t type, -bool flush_non_present_entry, -bool flush_dev_iotlb); +int __must_check cf_check vtd_flush_context_reg( +struct vtd_iommu *iommu,uint16_t did,uint16_t source_id, +uint8_t function_mask,uint64_t type,bool flush_non_present_entry); +int __must_check cf_check vtd_flush_iotlb_reg( +struct vtd_iommu *iommu,uint16_t did,uint64_t addr, +unsigned int size_order,uint64_t type,bool flush_non_present_entry, +bool flush_dev_iotlb);struct vtd_iommu *ioapic_to_iommu (unsigned int apic_id);struct vtd_iommu *hpet_to_iommu (unsigned int hpet_id);
@@ -86,17 +84,19 @@ int domain_context_mapping_one(struct domain *domain, struct vtd_iommu *iommu, u8 bus, u8 devfn, const struct pci_dev *);int domain_context_unmap_one (struct domain *domain,struct vtd_iommu *iommu,u8 bus,u8 devfn); -int intel_iommu_get_reserved_device_memory (iommu_grdm_t *func,void *ctxt); +int cf_check intel_iommu_get_reserved_device_memory( +iommu_grdm_t *func,void *ctxt); -unsigned int io_apic_read_remap_rte (unsigned int apic,unsigned int reg); -void io_apic_write_remap_rte (unsigned int apic, -unsigned int reg,unsigned int value); +unsigned int cf_check io_apic_read_remap_rte( +unsigned int apic,unsigned int reg); +void cf_check io_apic_write_remap_rte( +unsigned int apic,unsigned int reg,unsigned int value);struct msi_desc ;struct msi_msg ; -int msi_msg_write_remap_rte (struct msi_desc *,struct msi_msg *); +int cf_check msi_msg_write_remap_rte(struct msi_desc *, struct msi_msg *); -int intel_setup_hpet_msi (struct msi_desc *); +int cf_check intel_setup_hpet_msi(struct msi_desc *);int is_igd_vt_enabled_quirk (void );bool is_azalia_tlb_enabled (const struct acpi_drhd_unit *);
xen/drivers/passthrough/vtd/intremap.c +7 -7
@@ -142,7 +142,7 @@ static void set_hpet_source_id(unsigned int id, struct iremap_entry *ire)set_ire_sid (ire,SVT_VERIFY_SID_SQ ,SQ_13_IGNORE_3 ,hpetid_to_bdf (id)); } -bool __init intel_iommu_supports_eim (void ) +bool __init cf_check intel_iommu_supports_eim(void) {struct acpi_drhd_unit *drhd;unsigned int apic;
@@ -414,7 +414,7 @@ static int ioapic_rte_to_remap_entry(struct vtd_iommu *iommu,return 0 ; } -unsigned int io_apic_read_remap_rte ( +unsigned int cf_check io_apic_read_remap_rte(unsigned int apic,unsigned int reg) {unsigned int ioapic_pin = (reg -0x10 ) /2 ;
@@ -438,7 +438,7 @@ unsigned int io_apic_read_remap_rte(return (*(((u32 *)&old_rte) +0 )); } -void io_apic_write_remap_rte ( +void cf_check io_apic_write_remap_rte(unsigned int apic,unsigned int reg,unsigned int value) {unsigned int ioapic_pin = (reg -0x10 ) /2 ;
@@ -639,7 +639,7 @@ static int msi_msg_to_remap_entry(return 0 ; } -int msi_msg_write_remap_rte ( +int cf_check msi_msg_write_remap_rte(struct msi_desc *msi_desc,struct msi_msg *msg) {struct pci_dev *pdev = msi_desc->dev;
@@ -651,7 +651,7 @@ int msi_msg_write_remap_rte( : -EINVAL; } -int __init intel_setup_hpet_msi (struct msi_desc *msi_desc) +int __init cf_check intel_setup_hpet_msi(struct msi_desc *msi_desc) {struct vtd_iommu *iommu =hpet_to_iommu (msi_desc->hpet_id);unsigned long flags;
@@ -802,7 +802,7 @@ void disable_intremap(struct vtd_iommu *iommu)* This function is used to enable Interrupt remapping when * enable x2apic */ -int intel_iommu_enable_eim (void ) +int cf_check intel_iommu_enable_eim(void) {struct acpi_drhd_unit *drhd;struct vtd_iommu *iommu;
@@ -856,7 +856,7 @@ int intel_iommu_enable_eim(void)* This function is used to disable Interrupt remapping when * suspend local apic */ -void intel_iommu_disable_eim (void ) +void cf_check intel_iommu_disable_eim(void) {struct acpi_drhd_unit *drhd;
xen/drivers/passthrough/vtd/iommu.c +37 -36
223 lines not on this page · raw message
xen/drivers/passthrough/vtd/qinval.c +13 -15
@@ -322,9 +322,9 @@ int iommu_flush_iec_index(struct vtd_iommu *iommu, u8 im, u16 iidx)return queue_invalidate_iec_sync (iommu,IEC_INDEX_INVL , im, iidx); } -static int __must_check flush_context_qi (struct vtd_iommu *iommu,u16 did, -u16 sid,u8 fm,u64 type, -bool flush_non_present_entry) +static int __must_check cf_check flush_context_qi( +struct vtd_iommu *iommu,u16 did,u16 sid,u8 fm,u64 type, +bool flush_non_present_entry) {ASSERT (iommu->qinval_maddr);
@@ -346,11 +346,9 @@ static int __must_check flush_context_qi(struct vtd_iommu *iommu, u16 did, type >> DMA_CCMD_INVL_GRANU_OFFSET); } -static int __must_check flush_iotlb_qi (struct vtd_iommu *iommu,u16 did, -u64 addr, -unsigned int size_order,u64 type, -bool flush_non_present_entry, -bool flush_dev_iotlb) +static int __must_check cf_check flush_iotlb_qi( +struct vtd_iommu *iommu,u16 did,u64 addr,unsigned int size_order, +u64 type,bool flush_non_present_entry,bool flush_dev_iotlb) {u8 dr =0 , dw =0 ;int ret =0 , rc;
@@ -461,18 +459,18 @@ int enable_qinval(struct vtd_iommu *iommu)return 0 ; } -static int vtd_flush_context_noop (struct vtd_iommu *iommu,uint16_t did, -uint16_t source_id,uint8_t function_mask, -uint64_t type,bool flush_non_present_entry) +static int cf_check vtd_flush_context_noop( +struct vtd_iommu *iommu,uint16_t did,uint16_t source_id, +uint8_t function_mask,uint64_t type,bool flush_non_present_entry) {WARN ();return -EIO ; } -static int vtd_flush_iotlb_noop (struct vtd_iommu *iommu,uint16_t did, -uint64_t addr,unsigned int size_order, -uint64_t type,bool flush_non_present_entry, -bool flush_dev_iotlb) +static int cf_check vtd_flush_iotlb_noop( +struct vtd_iommu *iommu,uint16_t did,uint64_t addr, +unsigned int size_order,uint64_t type,bool flush_non_present_entry, +bool flush_dev_iotlb) {WARN ();return -EIO ;
Signature · 1 line
2.11.0
PATCH v3 27/70 xen/video: CFI hardening
In reply to Andrew CooperControl Flow Integrity schemes use toolchain and optionally hardware support to help protect against call/jump/return oriented programming attacks.
Use cf_check to annotate function pointer targets for the toolchain.
---
v3:
* Rebase over recent commits
--- xen/drivers/video/lfb.c | 4 ++-- xen/drivers/video/lfb.h | 4 ++-- xen/drivers/video/vesa.c | 4 ++-- xen/drivers/video/vga.c | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-)
xen/drivers/video/lfb.c +2 -2
@@ -53,7 +53,7 @@ static void lfb_show_line( }/* Fast mode which redraws all modified parts of a 2D text buffer. */ -void lfb_redraw_puts (const char *s,size_t nr) +void cf_check lfb_redraw_puts(const char *s, size_t nr) {unsigned int i, min_redraw_y = lfb.ypos;
@@ -98,7 +98,7 @@ void lfb_redraw_puts(const char *s, size_t nr) }/* Slower line-based scroll mode which interacts better with dom0. */ -void lfb_scroll_puts (const char *s,size_t nr) +void cf_check lfb_scroll_puts(const char *s, size_t nr) {unsigned int i;
xen/drivers/video/lfb.h +2 -2
@@ -35,8 +35,8 @@ struct lfb_prop {unsigned int text_rows; }; -void lfb_redraw_puts (const char *s,size_t nr); -void lfb_scroll_puts (const char *s,size_t nr); +void cf_check lfb_redraw_puts(const char *s, size_t nr); +void cf_check lfb_scroll_puts(const char *s, size_t nr);void lfb_carriage_return (void );void lfb_free (void );
xen/drivers/video/vesa.c +2 -2
@@ -17,7 +17,7 @@#define vlfb_info vga_console_info.u.vesa_lfb -static void lfb_flush (void ); +static void cf_check lfb_flush(void);static unsigned char *__read_mostly lfb;static const struct font_desc *__initdata font;
@@ -140,7 +140,7 @@ void __init vesa_init(void) video_puts = lfb_redraw_puts; } -static void lfb_flush (void ) +static void cf_check lfb_flush(void) { __asm__ __volatile__ ("sfence" : : :"memory" ); }
xen/drivers/video/vga.c +3 -3
@@ -19,8 +19,8 @@ static int vgacon_keep;static unsigned int xpos, ypos;static unsigned char *video; -static void vga_text_puts (const char *s,size_t nr); -static void vga_noop_puts (const char *s,size_t nr) {} +static void cf_check vga_text_puts(const char *s, size_t nr); +static void cf_check vga_noop_puts(const char *s, size_t nr) {}void (*video_puts)(const char *,size_t nr) = vga_noop_puts;/*
@@ -179,7 +179,7 @@ void __init video_endboot(void) } } -static void vga_text_puts (const char *s,size_t nr) +static void cf_check vga_text_puts(const char *s, size_t nr) {for ( ; nr >0 ; nr--, s++ ) {
Signature · 1 line
2.11.0
PATCH v3 29/70 xen/misc: CFI hardening
In reply to Andrew CooperControl Flow Integrity schemes use toolchain and optionally hardware support to help protect against call/jump/return oriented programming attacks.
Use cf_check to annotate function pointer targets for the toolchain.
---
v3
* Annotations for gcov
--- xen/arch/x86/mm.c | 6 ++++-- xen/arch/x86/setup.c | 4 ++-- xen/common/coverage/gcov.c | 8 ++++---- xen/common/domain.c | 2 +- xen/common/gdbstub.c | 5 ++--- xen/common/livepatch.c | 7 +++---- xen/common/memory.c | 4 ++-- xen/common/page_alloc.c | 2 +- xen/common/radix-tree.c | 4 ++-- xen/common/rangeset.c | 2 +- xen/common/spinlock.c | 6 +++--- xen/common/vm_event.c | 6 +++--- xen/common/xmalloc_tlsf.c | 4 ++-- xen/drivers/passthrough/amd/iommu_init.c | 2 +- xen/include/xen/domain.h | 2 +- 15 files changed, 32 insertions(+), 32 deletions(-)
xen/arch/x86/mm.c +4 -2
@@ -835,7 +835,8 @@ struct mmio_emul_range_ctxt {unsigned long mfn; }; -static int print_mmio_emul_range (unsigned long s,unsigned long e,void *arg) +static int cf_check print_mmio_emul_range( +unsigned long s,unsigned long e,void *arg) {const struct mmio_emul_range_ctxt *ctxt = arg;
@@ -4606,7 +4607,8 @@ static int _handle_iomem_range(unsigned long s, unsigned long e,return 0 ; } -static int handle_iomem_range (unsigned long s,unsigned long e,void *p) +static int cf_check handle_iomem_range( +unsigned long s,unsigned long e,void *p) {int err =0 ;
xen/arch/x86/setup.c +2 -2
@@ -2021,8 +2021,8 @@ int __hwdom_init xen_in_range(unsigned long mfn)return 0 ; } -static int __hwdom_init io_bitmap_cb(unsigned long s, unsigned long e, -void *ctx) +static int __hwdom_init cf_check io_bitmap_cb( +unsigned long s,unsigned long e,void *ctx) {struct domain *d = ctx;unsigned int i;
xen/common/coverage/gcov.c +4 -4
@@ -120,7 +120,7 @@ static int gcov_info_dump_payload(const struct gcov_info *info, } -static uint32_t gcov_get_size (void ) +static uint32_t cf_check gcov_get_size(void) {uint32_t total_size =sizeof (uint32_t );/* Magic number XCOV */ struct gcov_info *info =NULL ;
@@ -140,7 +140,7 @@ static uint32_t gcov_get_size(void)return total_size; } -static void gcov_reset_all_counters (void ) +static void cf_check gcov_reset_all_counters(void) {struct gcov_info *info =NULL ;
@@ -172,8 +172,8 @@ static int gcov_dump_one_record(const struct gcov_info *info,return gcov_info_dump_payload (info, buffer, off); } -static int gcov_dump_all (XEN_GUEST_HANDLE_PARAM (char ) buffer, -uint32_t *buffer_size) +static int cf_check gcov_dump_all( +XEN_GUEST_HANDLE_PARAM (char ) buffer,uint32_t *buffer_size) {uint32_t off;uint32_t magic =XEN_GCOV_FORMAT_MAGIC ;
xen/common/domain.c +1 -1
@@ -1803,7 +1803,7 @@ static void cf_check _free_pirq_struct(struct rcu_head *head)xfree (container_of(head ,struct pirq ,rcu_head )); } -void free_pirq_struct (void *ptr) +void cf_check free_pirq_struct(void *ptr) {struct pirq *pirq = ptr;
xen/common/gdbstub.c +2 -3
@@ -69,7 +69,7 @@ static void gdb_smp_resume(void);static char __initdata opt_gdb[30 ];string_param ("gdb" , opt_gdb); -static void gdbstub_console_puts (const char *str,size_t nr); +static void cf_check gdbstub_console_puts(const char *str, size_t nr);/* value <-> char (de)serialzers */ static char
@@ -546,8 +546,7 @@ __gdb_ctx = { };static struct gdb_context *gdb_ctx = &__gdb_ctx; -static void -gdbstub_console_puts (const char *str,size_t nr) +static void cf_check gdbstub_console_puts(const char *str, size_t nr) {const char *p;
xen/common/livepatch.c +3 -4
@@ -157,10 +157,9 @@ unsigned long livepatch_symbols_lookup_by_name(const char *symname)return 0 ; } -static const char *livepatch_symbols_lookup (unsigned long addr, -unsigned long *symbolsize, -unsigned long *offset, -char *namebuf) +static const char *cf_check livepatch_symbols_lookup( +unsigned long addr,unsigned long *symbolsize,unsigned long *offset, +char *namebuf) {const struct payload *data;unsigned int i, best;
xen/common/memory.c +2 -2
@@ -1051,8 +1051,8 @@ struct get_reserved_device_memory {unsigned int used_entries; }; -static int get_reserved_device_memory (xen_pfn_t start,xen_ulong_t nr, -u32 id,void *ctxt) +static int cf_check get_reserved_device_memory( +xen_pfn_t start,xen_ulong_t nr,u32 id,void *ctxt) {struct get_reserved_device_memory *grdm = ctxt; uint32_t sbdf = PCI_SBDF3(grdm->map.dev.pci.seg, grdm->map.dev.pci.bus,
xen/common/page_alloc.c +1 -1
@@ -1238,7 +1238,7 @@ struct scrub_wait_state {bool drop; }; -static void scrub_continue (void *data) +static void cf_check scrub_continue(void *data) {struct scrub_wait_state *st = data;
xen/common/radix-tree.c +2 -2
@@ -52,7 +52,7 @@ struct rcu_node {struct rcu_head rcu_head; }; -static struct radix_tree_node *rcu_node_alloc (void *arg) +static struct radix_tree_node *cf_check rcu_node_alloc(void *arg) { struct rcu_node *rcu_node = xmalloc(struct rcu_node);return rcu_node ? &rcu_node->node :NULL ;
@@ -65,7 +65,7 @@ static void cf_check _rcu_node_free(struct rcu_head *head)xfree (rcu_node); } -static void rcu_node_free (struct radix_tree_node *node,void *arg) +static void cf_check rcu_node_free(struct radix_tree_node *node, void *arg) { struct rcu_node *rcu_node = container_of(node, struct rcu_node, node);call_rcu (&rcu_node->rcu_head, _rcu_node_free);
xen/common/rangeset.c +1 -1
@@ -384,7 +384,7 @@ int rangeset_consume_ranges(struct rangeset *r,return rc; } -static int merge (unsigned long s,unsigned long e,void *data) +static int cf_check merge(unsigned long s, unsigned long e, void *data) {struct rangeset *r = data;
xen/common/spinlock.c +3 -3
@@ -375,7 +375,7 @@ static void spinlock_profile_iterate(lock_profile_subfunc *sub, void *par)spin_unlock (&lock_profile_lock); } -static void spinlock_profile_print_elem (struct lock_profile *data, +static void cf_check spinlock_profile_print_elem(struct lock_profile *data,int32_t type,int32_t idx,void *par) {struct spinlock *lock = data->lock;
@@ -404,7 +404,7 @@ void cf_check spinlock_profile_printall(unsigned char key)spinlock_profile_iterate (spinlock_profile_print_elem,NULL ); } -static void spinlock_profile_reset_elem (struct lock_profile *data, +static void cf_check spinlock_profile_reset_elem(struct lock_profile *data,int32_t type,int32_t idx,void *par) { data->lock_cnt =0 ;
@@ -428,7 +428,7 @@ typedef struct {int rc; } spinlock_profile_ucopy_t; -static void spinlock_profile_ucopy_elem (struct lock_profile *data, +static void cf_check spinlock_profile_ucopy_elem(struct lock_profile *data,int32_t type,int32_t idx,void *par) {spinlock_profile_ucopy_t *p = par;
xen/common/vm_event.c +3 -3
@@ -523,21 +523,21 @@ int __vm_event_claim_slot(struct domain *d, struct vm_event_domain *ved,#ifdef CONFIG_MEM_PAGING /* Registered with Xen-bound event channel for incoming notifications. */ -static void mem_paging_notification (struct vcpu *v,unsigned int port) +static void cf_check mem_paging_notification(struct vcpu *v, unsigned int port) {vm_event_resume (v->domain, v->domain->vm_event_paging); }#endif /* Registered with Xen-bound event channel for incoming notifications. */ -static void monitor_notification (struct vcpu *v,unsigned int port) +static void cf_check monitor_notification(struct vcpu *v, unsigned int port) {vm_event_resume (v->domain, v->domain->vm_event_monitor); }#ifdef CONFIG_MEM_SHARING /* Registered with Xen-bound event channel for incoming notifications. */ -static void mem_sharing_notification (struct vcpu *v,unsigned int port) +static void cf_check mem_sharing_notification(struct vcpu *v, unsigned int port) {vm_event_resume (v->domain, v->domain->vm_event_share); }
xen/common/xmalloc_tlsf.c +2 -2
@@ -512,13 +512,13 @@ int xmem_pool_maxalloc(struct xmem_pool *pool)static struct xmem_pool *xenpool; -static void *xmalloc_pool_get (unsigned long size) +static void *cf_check xmalloc_pool_get(unsigned long size) {ASSERT (size ==PAGE_SIZE );return alloc_xenheap_page (); } -static void xmalloc_pool_put (void *p) +static void cf_check xmalloc_pool_put(void *p) {free_xenheap_page (p); }
xen/drivers/passthrough/amd/iommu_init.c +1 -1
@@ -1073,7 +1073,7 @@ static void * __init allocate_ppr_log(struct amd_iommu *iommu)#define IVRS_MAPPINGS_DEVTAB (m) (m)[ivrs_bdf_entries].intremap_table/* Gets passed to radix_tree_destroy(), so its param needs to be void *. */ -static void __init free_ivrs_mapping_callback (void *ptr) +static void __init cf_check free_ivrs_mapping_callback(void *ptr) {const struct ivrs_mappings *ivrs_mappings = ptr;
xen/include/xen/domain.h +1 -1
@@ -52,7 +52,7 @@ void free_vcpu_struct(struct vcpu *v);#ifndef alloc_pirq_structstruct pirq *alloc_pirq_struct (struct domain *);#endif -void free_pirq_struct (void *); +void cf_check free_pirq_struct(void *);/* * Initialise/destroy arch-specific details of a VCPU.
Signature · 1 line
2.11.0
Re: [PATCH v3 29/70] xen/misc: CFI hardening
Quoted 10 lines · Andrew Cooper
Control Flow Integrity schemes use toolchain and optionally hardware support to help protect against call/jump/return oriented programming attacks.
Use
cf_checkto annotate function pointer targets for the toolchain.Signed-off-by Andrew Cooper <[email protected]>Acked-by Jan Beulich <[email protected]>---
v3
* Annotations for gcov
Hmm, ...
Quoted 4 lines
--- xen/arch/x86/mm.c | 6 ++++-- xen/arch/x86/setup.c | 4 ++-- xen/common/coverage/gcov.c | 8 ++++----
... what about llvm.c then?
Jan
Re: [PATCH v3 29/70] xen/misc: CFI hardening
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Andrew Cooper
Control Flow Integrity schemes use toolchain and optionally hardware support to help protect against call/jump/return oriented programming attacks.
Use
cf_checkto annotate function pointer targets for the toolchain.Signed-off-by Andrew Cooper <[email protected]>Acked-by Jan Beulich <[email protected]>---
v3
* Annotations for gcov
Quoted 7 lines
Hmm, ...
Quoted 4 lines
--- xen/arch/x86/mm.c | 6 ++++-- xen/arch/x86/setup.c | 4 ++-- xen/common/coverage/gcov.c | 8 ++++----... what about
llvm.cthen?
Good point. I'll fix up.
There's currently no Clang toolchain capable of spotting/complaining at this, but the Clang devs are working on this.
~Andrew
Quoted 1 line · Andrew Cooper
To avoid spamming everyone, I have only re-sent patches with changes in v3.
Could you enumerate which ones these are? Otherwise it's hard to tell whether everything you did send did arrive in the recipients' mailboxes.
Thanks, Jan
Quoted 422 lines
CET Indirect Branch Tracking is a hardware feature designed to protect against forward-edge control flow hijacking (Call/Jump oriented programming), and is a companion feature to CET Shadow Stacks added in Xen 4.14.
Patches 1 thru 5 are prerequisites. Patches 6 thru 59 are fairly mechanical annotations of function pointer targets. Patches 60 thru 70 are the final enablement of CET-IBT.
This series functions correctly with GCC 9 and later, although an experimental GCC patch is required to get more helpful typechecking at build time. A container with this fix has been added to CI.
Tested on a TigerLake NUC by me, and by Marek also.
CI pipelines:
https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/476819536
https://cirrus-ci.com/build/4634902334275584Andrew Cooper (67):
xen/sort: Switch to an extern inline implementation xen/xsm: Move {do,compat}_flask_op() declarations into a header x86/kexec: Annotate embedded data with ELF metadata
x86: Introduce support for CET-IBT
xen: CFI hardening for x86 hypercalls
xen: CFI hardening forcustom_param()
xen: CFI hardening for__initcall()
xen: CFI hardening for notifier callbacks
xen: CFI hardening foracpi_table_parse()
xen: CFI hardening forcontinue_hypercall_on_cpu()
xen: CFI hardening forinit_timer()
xen: CFI hardening forcall_rcu()
xen: CFI hardening for IPIs
xen: CFI hardening foropen_softirq()
xsm/flask/ss: CFI hardening
xsm: CFI hardening
xen/sched: CFI hardening
xen/evtchn: CFI hardening
xen/hypfs: CFI hardening
xen/tasklet: CFI hardening
xen/keyhandler: CFI hardening
xen/vpci: CFI hardening
xen/decompress: CFI hardening
xen/iommu: CFI hardening
xen/video: CFI hardening
xen/console: CFI hardening
xen/misc: CFI hardening
x86: CFI hardening forrequest_irq()
x86/hvm: CFI hardening forhvm_funcs
x86/hvm: CFI hardening for device emulation
x86/emul: CFI hardening
x86/ucode: CFI hardening
x86/power: CFI hardening
x86/apic: CFI hardening
x86/nmi: CFI hardening
x86/mtrr: CFI hardening
x86/idle: CFI hardening
x86/quirks: CFI hardening
x86/hvmsave: CFI hardening
x86/mce: CFI hardening
x86/pmu: CFI hardening
x86/cpu: CFI hardening
x86/guest: CFI hardening
x86/logdirty: CFI hardening
x86/shadow: CFI hardening
x86/hap: CFI hardening
x86/p2m: CFI hardening
x86/irq: CFI hardening
x86/apei: CFI hardening
x86/psr: CFI hardening
x86/dpci: CFI hardening
x86/pt: CFI hardening
x86/time: CFI hardening
x86/misc: CFI hardening
x86/stack: CFI hardening
x86/bugframe: CFI hardening
x86: Use control flow typechecking where possible x86/setup: Read CR4 earlier in__start_xen()x86/alternatives: Clear CR4.CET when clearing CR0.WP x86/traps: Reworkwrite_stub_trampoline()to not hardcode the jmp
x86: Introduce helpers/checks for endbr64 instructions x86/emul: Update emulation stubs to be CET-IBT compatible x86/entry: Make syscall/sysenter entrypoints CET-IBT compatible x86/entry: Make IDT entrypoints CET-IBT compatible x86/setup: ReworkMSR_S_CEThandling for CET-IBT x86/efi: Disable CET-IBT around Runtime Services calls
x86: Enable CET Indirect Branch TrackingJuergen Gross (2):
x86/pv-shim: Don't modify the hypercall table
x86: Don't use the hypercall table for calling compat hypercallsMarek Marczykowski-Górecki (1):
x86: Build check for embedded endbr64 instructionsConfig.mk | 1 - README | 1 + automation/build/debian/buster-gcc-ibt.dockerfile | 66 ++++ automation/gitlab-ci/build.yaml | 6 + automation/scripts/containerize | 1 + docs/misc/xen-command-line.pandoc | 16 +- tools/firmware/Makefile | 2 + tools/libs/guest/xg_dom_decompress_unsafe.h | 2 + tools/tests/x86_emulator/x86-emulate.h | 2 + xen/arch/arm/bootfdt.c | 9 +- xen/arch/arm/io.c | 9 +- xen/arch/x86/Kconfig | 17 + xen/arch/x86/Makefile | 6 + xen/arch/x86/acpi/boot.c | 24 +- xen/arch/x86/acpi/cpu_idle.c | 43 ++- xen/arch/x86/acpi/cpufreq/cpufreq.c | 24 +- xen/arch/x86/acpi/cpufreq/powernow.c | 21 +- xen/arch/x86/acpi/cpuidle_menu.c | 6 +- xen/arch/x86/acpi/lib.c | 2 +- xen/arch/x86/acpi/power.c | 4 +- xen/arch/x86/acpi/wakeup_prot.S | 38 +- xen/arch/x86/alternative.c | 13 +- xen/arch/x86/apic.c | 12 +- xen/arch/x86/arch.mk | 7 + xen/arch/x86/boot/x86_64.S | 30 +- xen/arch/x86/compat.c | 21 +- xen/arch/x86/configs/pvshim_defconfig | 1 + xen/arch/x86/cpu/amd.c | 8 +- xen/arch/x86/cpu/centaur.c | 2 +- xen/arch/x86/cpu/common.c | 3 +- xen/arch/x86/cpu/cpu.h | 2 +- xen/arch/x86/cpu/hygon.c | 2 +- xen/arch/x86/cpu/intel.c | 6 +- xen/arch/x86/cpu/mcheck/amd_nonfatal.c | 4 +- xen/arch/x86/cpu/mcheck/mce.c | 22 +- xen/arch/x86/cpu/mcheck/mce.h | 2 +- xen/arch/x86/cpu/mcheck/mce_amd.c | 9 +- xen/arch/x86/cpu/mcheck/mce_amd.h | 4 +- xen/arch/x86/cpu/mcheck/mce_intel.c | 49 ++- xen/arch/x86/cpu/mcheck/non-fatal.c | 6 +- xen/arch/x86/cpu/mcheck/vmce.c | 4 +- xen/arch/x86/cpu/microcode/amd.c | 9 +- xen/arch/x86/cpu/microcode/core.c | 15 +- xen/arch/x86/cpu/microcode/intel.c | 10 +- xen/arch/x86/cpu/mtrr/generic.c | 20 +- xen/arch/x86/cpu/mtrr/main.c | 4 +- xen/arch/x86/cpu/mtrr/mtrr.h | 8 +- xen/arch/x86/cpu/mwait-idle.c | 12 +- xen/arch/x86/cpu/shanghai.c | 2 +- xen/arch/x86/cpu/vpmu.c | 13 +- xen/arch/x86/cpu/vpmu_amd.c | 16 +- xen/arch/x86/cpu/vpmu_intel.c | 16 +- xen/arch/x86/cpuid.c | 8 +- xen/arch/x86/crash.c | 7 +- xen/arch/x86/dmi_scan.c | 10 +- xen/arch/x86/dom0_build.c | 8 +- xen/arch/x86/domain.c | 16 +- xen/arch/x86/emul-i8254.c | 14 +- xen/arch/x86/extable.c | 18 +- xen/arch/x86/genapic/bigsmp.c | 4 +- xen/arch/x86/genapic/delivery.c | 12 +- xen/arch/x86/genapic/probe.c | 2 +- xen/arch/x86/genapic/x2apic.c | 18 +- xen/arch/x86/guest/hyperv/hyperv.c | 10 +- xen/arch/x86/guest/xen/xen.c | 15 +- xen/arch/x86/hpet.c | 29 +- xen/arch/x86/hvm/dm.c | 5 +- xen/arch/x86/hvm/dom0_build.c | 16 +- xen/arch/x86/hvm/emulate.c | 93 +++-- xen/arch/x86/hvm/hpet.c | 12 +- xen/arch/x86/hvm/hvm.c | 47 +-- xen/arch/x86/hvm/hypercall.c | 5 +- xen/arch/x86/hvm/intercept.c | 28 +- xen/arch/x86/hvm/io.c | 38 +- xen/arch/x86/hvm/ioreq.c | 2 +- xen/arch/x86/hvm/irq.c | 16 +- xen/arch/x86/hvm/mtrr.c | 8 +- xen/arch/x86/hvm/nestedhvm.c | 6 +- xen/arch/x86/hvm/pmtimer.c | 10 +- xen/arch/x86/hvm/quirks.c | 4 +- xen/arch/x86/hvm/rtc.c | 18 +- xen/arch/x86/hvm/stdvga.c | 19 +- xen/arch/x86/hvm/svm/nestedsvm.c | 22 +- xen/arch/x86/hvm/svm/svm.c | 404 +++++++++++----------- xen/arch/x86/hvm/svm/vmcb.c | 2 +- xen/arch/x86/hvm/vioapic.c | 12 +- xen/arch/x86/hvm/viridian/time.c | 2 +- xen/arch/x86/hvm/viridian/viridian.c | 17 +- xen/arch/x86/hvm/vlapic.c | 25 +- xen/arch/x86/hvm/vmsi.c | 16 +- xen/arch/x86/hvm/vmx/intr.c | 2 +- xen/arch/x86/hvm/vmx/vmcs.c | 22 +- xen/arch/x86/hvm/vmx/vmx.c | 155 +++++---- xen/arch/x86/hvm/vmx/vvmx.c | 16 +- xen/arch/x86/hvm/vpic.c | 8 +- xen/arch/x86/hvm/vpt.c | 2 +- xen/arch/x86/i8259.c | 10 +- xen/arch/x86/include/asm/asm-defns.h | 6 + xen/arch/x86/include/asm/bug.h | 10 +- xen/arch/x86/include/asm/cpufeature.h | 1 + xen/arch/x86/include/asm/cpufeatures.h | 1 + xen/arch/x86/include/asm/cpuidle.h | 4 +- xen/arch/x86/include/asm/current.h | 6 +- xen/arch/x86/include/asm/endbr.h | 55 +++ xen/arch/x86/include/asm/flushtlb.h | 2 +- xen/arch/x86/include/asm/genapic.h | 18 +- xen/arch/x86/include/asm/hpet.h | 8 +- xen/arch/x86/include/asm/hvm/emulate.h | 8 +- xen/arch/x86/include/asm/hvm/save.h | 2 +- xen/arch/x86/include/asm/hvm/svm/nestedsvm.h | 18 +- xen/arch/x86/include/asm/hvm/svm/svm.h | 1 - xen/arch/x86/include/asm/hvm/vioapic.h | 2 +- xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 8 +- xen/arch/x86/include/asm/hvm/vmx/vmx.h | 4 +- xen/arch/x86/include/asm/hvm/vmx/vvmx.h | 18 +- xen/arch/x86/include/asm/hypercall.h | 81 +++-- xen/arch/x86/include/asm/irq.h | 24 +- xen/arch/x86/include/asm/machine_kexec.h | 2 +- xen/arch/x86/include/asm/mm.h | 16 +- xen/arch/x86/include/asm/msi.h | 8 +- xen/arch/x86/include/asm/msr-index.h | 1 + xen/arch/x86/include/asm/mtrr.h | 2 +- xen/arch/x86/include/asm/p2m.h | 4 +- xen/arch/x86/include/asm/paging.h | 2 +- xen/arch/x86/include/asm/processor.h | 4 +- xen/arch/x86/include/asm/pv/domain.h | 4 +- xen/arch/x86/include/asm/pv/shim.h | 11 +- xen/arch/x86/include/asm/shadow.h | 2 +- xen/arch/x86/include/asm/smp.h | 6 +- xen/arch/x86/include/asm/tboot.h | 2 +- xen/arch/x86/include/asm/time.h | 6 +- xen/arch/x86/io_apic.c | 28 +- xen/arch/x86/ioport_emulate.c | 4 +- xen/arch/x86/irq.c | 28 +- xen/arch/x86/livepatch.c | 2 +- xen/arch/x86/machine_kexec.c | 2 +- xen/arch/x86/mm.c | 35 +- xen/arch/x86/mm/hap/guest_walk.c | 4 +- xen/arch/x86/mm/hap/hap.c | 29 +- xen/arch/x86/mm/hap/nested_hap.c | 2 +- xen/arch/x86/mm/hap/private.h | 30 +- xen/arch/x86/mm/mem_sharing.c | 2 +- xen/arch/x86/mm/p2m-ept.c | 34 +- xen/arch/x86/mm/p2m-pt.c | 19 +- xen/arch/x86/mm/paging.c | 3 +- xen/arch/x86/mm/shadow/common.c | 33 +- xen/arch/x86/mm/shadow/hvm.c | 16 +- xen/arch/x86/mm/shadow/multi.c | 80 +++-- xen/arch/x86/mm/shadow/multi.h | 20 +- xen/arch/x86/mm/shadow/none.c | 20 +- xen/arch/x86/mm/shadow/private.h | 12 +- xen/arch/x86/mm/shadow/pv.c | 4 +- xen/arch/x86/msi.c | 18 +- xen/arch/x86/nmi.c | 16 +- xen/arch/x86/numa.c | 10 +- xen/arch/x86/oprofile/nmi_int.c | 16 +- xen/arch/x86/oprofile/op_model_athlon.c | 18 +- xen/arch/x86/oprofile/op_model_p4.c | 14 +- xen/arch/x86/oprofile/op_model_ppro.c | 26 +- xen/arch/x86/percpu.c | 6 +- xen/arch/x86/physdev.c | 2 +- xen/arch/x86/platform_hypercall.c | 11 +- xen/arch/x86/psr.c | 41 +-- xen/arch/x86/pv/callback.c | 25 +- xen/arch/x86/pv/descriptor-tables.c | 14 +- xen/arch/x86/pv/domain.c | 12 +- xen/arch/x86/pv/emul-gate-op.c | 9 +- xen/arch/x86/pv/emul-priv-op.c | 71 ++-- xen/arch/x86/pv/emulate.h | 7 - xen/arch/x86/pv/hypercall.c | 11 +- xen/arch/x86/pv/iret.c | 4 +- xen/arch/x86/pv/misc-hypercalls.c | 10 +- xen/arch/x86/pv/ro-page-fault.c | 31 +- xen/arch/x86/pv/shim.c | 60 ++-- xen/arch/x86/pv/traps.c | 2 +- xen/arch/x86/setup.c | 80 ++++- xen/arch/x86/shutdown.c | 10 +- xen/arch/x86/smp.c | 20 +- xen/arch/x86/smpboot.c | 2 +- xen/arch/x86/spec_ctrl.c | 6 +- xen/arch/x86/srat.c | 4 +- xen/arch/x86/sysctl.c | 4 +- xen/arch/x86/tboot.c | 2 +- xen/arch/x86/time.c | 68 ++-- xen/arch/x86/traps.c | 8 +- xen/arch/x86/tsx.c | 2 +- xen/arch/x86/x86_64/acpi_mmcfg.c | 2 +- xen/arch/x86/x86_64/compat.c | 1 - xen/arch/x86/x86_64/compat/entry.S | 1 + xen/arch/x86/x86_64/compat/mm.c | 7 +- xen/arch/x86/x86_64/entry.S | 49 ++- xen/arch/x86/x86_64/kexec_reloc.S | 23 +- xen/arch/x86/x86_64/mmconfig-shared.c | 10 +- xen/arch/x86/x86_64/mmconfig.h | 2 +- xen/arch/x86/x86_64/platform_hypercall.c | 2 +- xen/arch/x86/x86_64/traps.c | 42 ++- xen/arch/x86/x86_emulate.c | 34 +- xen/arch/x86/x86_emulate/x86_emulate.c | 10 +- xen/arch/x86/x86_emulate/x86_emulate.h | 33 +- xen/arch/x86/xen.lds.S | 3 +- xen/common/argo.c | 6 +- xen/common/bunzip2.c | 2 +- xen/common/compat/domain.c | 3 +- xen/common/compat/grant_table.c | 5 +- xen/common/compat/kernel.c | 2 +- xen/common/compat/memory.c | 7 +- xen/common/compat/multicall.c | 3 +- xen/common/core_parking.c | 10 +- xen/common/coverage/gcov.c | 8 +- xen/common/cpu.c | 4 +- xen/common/debugtrace.c | 10 +- xen/common/decompress.c | 2 +- xen/common/dm.c | 6 +- xen/common/domain.c | 15 +- xen/common/domctl.c | 2 +- xen/common/efi/boot.c | 6 +- xen/common/efi/runtime.c | 18 + xen/common/event_2l.c | 21 +- xen/common/event_channel.c | 18 +- xen/common/event_fifo.c | 30 +- xen/common/gdbstub.c | 9 +- xen/common/grant_table.c | 29 +- xen/common/hypfs.c | 63 ++-- xen/common/irq.c | 6 +- xen/common/kernel.c | 6 +- xen/common/kexec.c | 18 +- xen/common/keyhandler.c | 47 +-- xen/common/livepatch.c | 15 +- xen/common/memory.c | 8 +- xen/common/multicall.c | 2 +- xen/common/page_alloc.c | 14 +- xen/common/perfc.c | 4 +- xen/common/radix-tree.c | 8 +- xen/common/random.c | 2 +- xen/common/rangeset.c | 2 +- xen/common/rcupdate.c | 8 +- xen/common/sched/arinc653.c | 20 +- xen/common/sched/compat.c | 2 +- xen/common/sched/core.c | 40 +-- xen/common/sched/cpupool.c | 35 +- xen/common/sched/credit.c | 59 ++-- xen/common/sched/credit2.c | 55 ++- xen/common/sched/null.c | 60 ++-- xen/common/sched/rt.c | 47 +-- xen/common/spinlock.c | 12 +- xen/common/stop_machine.c | 6 +- xen/common/sysctl.c | 2 +- xen/common/tasklet.c | 4 +- xen/common/timer.c | 6 +- xen/common/trace.c | 4 +- xen/common/unlzma.c | 2 +- xen/common/vm_event.c | 6 +- xen/common/xenoprof.c | 2 +- xen/common/xmalloc_tlsf.c | 4 +- xen/common/zstd/zstd_common.c | 4 +- xen/common/zstd/zstd_internal.h | 4 +- xen/drivers/acpi/apei/apei-base.c | 32 +- xen/drivers/acpi/apei/apei-internal.h | 20 +- xen/drivers/acpi/apei/erst.c | 57 ++- xen/drivers/acpi/apei/hest.c | 4 +- xen/drivers/acpi/numa.c | 10 +- xen/drivers/acpi/tables.c | 2 +- xen/drivers/char/console.c | 36 +- xen/drivers/char/ehci-dbgp.c | 28 +- xen/drivers/char/ns16550.c | 34 +- xen/drivers/cpufreq/cpufreq.c | 6 +- xen/drivers/cpufreq/cpufreq_misc_governors.c | 22 +- xen/drivers/cpufreq/cpufreq_ondemand.c | 10 +- xen/drivers/passthrough/amd/iommu.h | 45 +-- xen/drivers/passthrough/amd/iommu_acpi.c | 15 +- xen/drivers/passthrough/amd/iommu_guest.c | 12 +- xen/drivers/passthrough/amd/iommu_init.c | 49 +-- xen/drivers/passthrough/amd/iommu_intr.c | 20 +- xen/drivers/passthrough/amd/iommu_map.c | 22 +- xen/drivers/passthrough/amd/pci_amd_iommu.c | 32 +- xen/drivers/passthrough/iommu.c | 56 ++- xen/drivers/passthrough/pci.c | 18 +- xen/drivers/passthrough/vtd/dmar.c | 7 +- xen/drivers/passthrough/vtd/extern.h | 38 +- xen/drivers/passthrough/vtd/intremap.c | 14 +- xen/drivers/passthrough/vtd/iommu.c | 94 ++--- xen/drivers/passthrough/vtd/qinval.c | 28 +- xen/drivers/passthrough/vtd/quirks.c | 2 +- xen/drivers/passthrough/vtd/utils.c | 2 +- xen/drivers/passthrough/vtd/x86/hvm.c | 4 +- xen/drivers/passthrough/x86/hvm.c | 14 +- xen/drivers/video/lfb.c | 4 +- xen/drivers/video/lfb.h | 4 +- xen/drivers/video/vesa.c | 6 +- xen/drivers/video/vga.c | 6 +- xen/drivers/vpci/header.c | 18 +- xen/drivers/vpci/msi.c | 42 +-- xen/drivers/vpci/msix.c | 20 +- xen/drivers/vpci/vpci.c | 16 +- xen/include/acpi/cpufreq/cpufreq.h | 1 - xen/include/xen/acpi.h | 2 +- xen/include/xen/compiler.h | 6 + xen/include/xen/domain.h | 2 +- xen/include/xen/hypercall.h | 69 ++-- xen/include/xen/hypfs.h | 49 ++- xen/include/xen/irq.h | 6 +- xen/include/xen/lib.h | 2 +- xen/include/xen/perfc.h | 4 +- xen/include/xen/sched.h | 2 +- xen/include/xen/sort.h | 55 ++- xen/include/xen/spinlock.h | 4 +- xen/include/xen/vpci.h | 8 +- xen/include/xsm/dummy.h | 211 +++++------ xen/lib/sort.c | 80 +---- xen/tools/check-endbr.sh | 85 +++++ xen/xsm/flask/avc.c | 2 +- xen/xsm/flask/flask_op.c | 8 +- xen/xsm/flask/hooks.c | 236 +++++++------ xen/xsm/flask/private.h | 9 + xen/xsm/flask/ss/avtab.c | 4 +- xen/xsm/flask/ss/conditional.c | 10 +- xen/xsm/flask/ss/conditional.h | 6 +- xen/xsm/flask/ss/policydb.c | 53 +-- xen/xsm/flask/ss/services.c | 6 +- xen/xsm/flask/ss/symtab.c | 5 +- xen/xsm/silo.c | 24 +- xen/xsm/xsm_core.c | 6 +- 322 files changed, 3316 insertions(+), 2739 deletions(-) create mode 100644 automation/build/debian/buster-gcc-ibt.dockerfile create mode 100644 xen/arch/x86/include/asm/endbr.h create mode 100755 xen/tools/check-endbr.sh create mode 100644 xen/xsm/flask/private.h
Quoted 4 lines · Jan Beulich
Quoted 1 line · Andrew Cooper
To avoid spamming everyone, I have only re-sent patches with changes in v3.
Could you enumerate which ones these are? Otherwise it's hard to tell whether everything you did send did arrive in the recipients' mailboxes.
Oops sorry. 1, 3, 5, 6, 8, 12, 26, 27, 29, 33, 46, 47, 59, 60, 64.
All that I'm expecting to see have appeared on the list.
~Andrew
PATCH v3 33/70 x86/emul: CFI hardening
In reply to Andrew CooperControl Flow Integrity schemes use toolchain and optionally hardware support to help protect against call/jump/return oriented programming attacks.
Use cf_check to annotate function pointer targets for the toolchain.
pv_emul_is_mem_write() is only used in a single file. Move it out of its header file, so it doesn't risk being duplicated in multiple translation units.
---
v2:
* Correct details in commit message.
v2:
* Reword again.
--- xen/arch/x86/hvm/emulate.c | 72 +++++++++++++++++----------------- xen/arch/x86/hvm/hvm.c | 8 ++-- xen/arch/x86/hvm/svm/svm.c | 4 +- xen/arch/x86/include/asm/hvm/emulate.h | 8 ++-- xen/arch/x86/include/asm/mm.h | 16 +++----- xen/arch/x86/mm.c | 4 +- xen/arch/x86/mm/shadow/hvm.c | 8 ++-- xen/arch/x86/pv/emul-gate-op.c | 9 +++-- xen/arch/x86/pv/emul-priv-op.c | 64 +++++++++++++++--------------- xen/arch/x86/pv/emulate.h | 7 ---- xen/arch/x86/pv/ro-page-fault.c | 31 +++++++++------ xen/arch/x86/x86_emulate.c | 21 +++++----- xen/arch/x86/x86_emulate/x86_emulate.c | 10 ++--- xen/arch/x86/x86_emulate/x86_emulate.h | 33 ++++++++-------- 14 files changed, 148 insertions(+), 147 deletions(-)
xen/arch/x86/hvm/emulate.c +36 -36
@@ -1272,7 +1272,7 @@ static int __hvmemul_read(return linear_read (addr, bytes, p_data, pfec, hvmemul_ctxt); } -static int hvmemul_read( +static int cf_check hvmemul_read( enum x86_segment seg, unsigned long offset, void *p_data,
@@ -1290,7 +1290,7 @@ static int hvmemul_read( container_of(ctxt, struct hvm_emulate_ctxt, ctxt)); } -int hvmemul_insn_fetch( +int cf_check hvmemul_insn_fetch( unsigned long offset, void *p_data, unsigned int bytes,
@@ -1336,7 +1336,7 @@ int hvmemul_insn_fetch(return X86EMUL_OKAY ; } -static int hvmemul_write( +static int cf_check hvmemul_write( enum x86_segment seg, unsigned long offset, void *p_data,
@@ -1384,7 +1384,7 @@ static int hvmemul_write(return X86EMUL_OKAY ; } -static int hvmemul_rmw( +static int cf_check hvmemul_rmw( enum x86_segment seg, unsigned long offset, unsigned int bytes,
@@ -1437,7 +1437,7 @@ static int hvmemul_rmw(return rc; } -static int hvmemul_blk( +static int cf_check hvmemul_blk( enum x86_segment seg, unsigned long offset, void *p_data,
@@ -1478,7 +1478,7 @@ static int hvmemul_blk(return rc; } -static int hvmemul_write_discard( +static int cf_check hvmemul_write_discard( enum x86_segment seg, unsigned long offset, void *p_data,
@@ -1489,7 +1489,7 @@ static int hvmemul_write_discard(return X86EMUL_OKAY ; } -static int hvmemul_rep_ins_discard( +static int cf_check hvmemul_rep_ins_discard( uint16_t src_port, enum x86_segment dst_seg, unsigned long dst_offset,
@@ -1500,7 +1500,7 @@ static int hvmemul_rep_ins_discard(return X86EMUL_OKAY ; } -static int hvmemul_rep_movs_discard( +static int cf_check hvmemul_rep_movs_discard( enum x86_segment src_seg, unsigned long src_offset, enum x86_segment dst_seg,
@@ -1512,7 +1512,7 @@ static int hvmemul_rep_movs_discard(return X86EMUL_OKAY ; } -static int hvmemul_rep_stos_discard( +static int cf_check hvmemul_rep_stos_discard( void *p_data, enum x86_segment seg, unsigned long offset,
@@ -1523,7 +1523,7 @@ static int hvmemul_rep_stos_discard(return X86EMUL_OKAY ; } -static int hvmemul_rep_outs_discard( +static int cf_check hvmemul_rep_outs_discard( enum x86_segment src_seg, unsigned long src_offset, uint16_t dst_port,
@@ -1534,7 +1534,7 @@ static int hvmemul_rep_outs_discard(return X86EMUL_OKAY ; } -static int hvmemul_cmpxchg_discard( +static int cf_check hvmemul_cmpxchg_discard( enum x86_segment seg, unsigned long offset, void *p_old,
@@ -1546,7 +1546,7 @@ static int hvmemul_cmpxchg_discard(return X86EMUL_OKAY ; } -static int hvmemul_read_io_discard( +static int cf_check hvmemul_read_io_discard( unsigned int port, unsigned int bytes, unsigned long *val,
@@ -1555,7 +1555,7 @@ static int hvmemul_read_io_discard(return X86EMUL_OKAY ; } -static int hvmemul_write_io_discard( +static int cf_check hvmemul_write_io_discard( unsigned int port, unsigned int bytes, unsigned long val,
@@ -1564,7 +1564,7 @@ static int hvmemul_write_io_discard(return X86EMUL_OKAY ; } -static int hvmemul_write_msr_discard ( +static int cf_check hvmemul_write_msr_discard(unsigned int reg,uint64_t val,struct x86_emulate_ctxt *ctxt)
@@ -1572,7 +1572,7 @@ static int hvmemul_write_msr_discard(return X86EMUL_OKAY ; } -static int hvmemul_cache_op_discard( +static int cf_check hvmemul_cache_op_discard( enum x86emul_cache_op op, enum x86_segment seg, unsigned long offset,
@@ -1581,7 +1581,7 @@ static int hvmemul_cache_op_discard(return X86EMUL_OKAY ; } -static int hvmemul_cmpxchg( +static int cf_check hvmemul_cmpxchg( enum x86_segment seg, unsigned long offset, void *p_old,
@@ -1675,7 +1675,7 @@ static int hvmemul_cmpxchg(return rc; } -static int hvmemul_validate ( +static int cf_check hvmemul_validate(const struct x86_emulate_state *state,struct x86_emulate_ctxt *ctxt) {
@@ -1688,7 +1688,7 @@ static int hvmemul_validate( ? X86EMUL_OKAY : X86EMUL_UNHANDLEABLE; } -static int hvmemul_rep_ins( +static int cf_check hvmemul_rep_ins( uint16_t src_port, enum x86_segment dst_seg, unsigned long dst_offset,
@@ -1766,7 +1766,7 @@ static int hvmemul_rep_outs_set_context(return rc; } -static int hvmemul_rep_outs( +static int cf_check hvmemul_rep_outs( enum x86_segment src_seg, unsigned long src_offset, uint16_t dst_port,
@@ -1807,7 +1807,7 @@ static int hvmemul_rep_outs( !!(ctxt->regs->eflags & X86_EFLAGS_DF), gpa); } -static int hvmemul_rep_movs( +static int cf_check hvmemul_rep_movs( enum x86_segment src_seg, unsigned long src_offset, enum x86_segment dst_seg,
@@ -1977,7 +1977,7 @@ static int hvmemul_rep_movs(return X86EMUL_UNHANDLEABLE ; } -static int hvmemul_rep_stos( +static int cf_check hvmemul_rep_stos( void *p_data, enum x86_segment seg, unsigned long offset,
@@ -2105,7 +2105,7 @@ static int hvmemul_rep_stos( } } -static int hvmemul_read_segment ( +static int cf_check hvmemul_read_segment(enum x86_segment seg,struct segment_register *reg,struct x86_emulate_ctxt *ctxt)
@@ -2122,7 +2122,7 @@ static int hvmemul_read_segment(return X86EMUL_OKAY ; } -static int hvmemul_write_segment ( +static int cf_check hvmemul_write_segment(enum x86_segment seg,const struct segment_register *reg,struct x86_emulate_ctxt *ctxt)
@@ -2141,7 +2141,7 @@ static int hvmemul_write_segment(return X86EMUL_OKAY ; } -static int hvmemul_read_io( +static int cf_check hvmemul_read_io( unsigned int port, unsigned int bytes, unsigned long *val,
@@ -2158,7 +2158,7 @@ static int hvmemul_read_io(return hvmemul_do_pio_buffer (port, bytes,IOREQ_READ , val); } -static int hvmemul_write_io( +static int cf_check hvmemul_write_io( unsigned int port, unsigned int bytes, unsigned long val,
@@ -2167,7 +2167,7 @@ static int hvmemul_write_io(return hvmemul_do_pio_buffer (port, bytes,IOREQ_WRITE , &val); } -static int hvmemul_read_cr ( +static int cf_check hvmemul_read_cr(unsigned int reg,unsigned long *val,struct x86_emulate_ctxt *ctxt)
@@ -2188,7 +2188,7 @@ static int hvmemul_read_cr(return X86EMUL_UNHANDLEABLE ; } -static int hvmemul_write_cr ( +static int cf_check hvmemul_write_cr(unsigned int reg,unsigned long val,struct x86_emulate_ctxt *ctxt)
@@ -2232,7 +2232,7 @@ static int hvmemul_write_cr(return rc; } -static int hvmemul_read_xcr ( +static int cf_check hvmemul_read_xcr(unsigned int reg,uint64_t *val,struct x86_emulate_ctxt *ctxt)
@@ -2245,7 +2245,7 @@ static int hvmemul_read_xcr(return rc; } -static int hvmemul_write_xcr ( +static int cf_check hvmemul_write_xcr(unsigned int reg,uint64_t val,struct x86_emulate_ctxt *ctxt)
@@ -2255,7 +2255,7 @@ static int hvmemul_write_xcr(return x86emul_write_xcr (reg, val, ctxt); } -static int hvmemul_read_msr ( +static int cf_check hvmemul_read_msr(unsigned int reg,uint64_t *val,struct x86_emulate_ctxt *ctxt)
@@ -2268,7 +2268,7 @@ static int hvmemul_read_msr(return rc; } -static int hvmemul_write_msr ( +static int cf_check hvmemul_write_msr(unsigned int reg,uint64_t val,struct x86_emulate_ctxt *ctxt)
@@ -2281,7 +2281,7 @@ static int hvmemul_write_msr(return rc; } -static int hvmemul_cache_op( +static int cf_check hvmemul_cache_op( enum x86emul_cache_op op, enum x86_segment seg, unsigned long offset,
@@ -2353,7 +2353,7 @@ static int hvmemul_cache_op(return X86EMUL_OKAY ; } -static int hvmemul_get_fpu ( +static int cf_check hvmemul_get_fpu(enum x86_emulate_fpu_type type,struct x86_emulate_ctxt *ctxt) {
@@ -2395,7 +2395,7 @@ static int hvmemul_get_fpu(return X86EMUL_OKAY ; } -static void hvmemul_put_fpu ( +static void cf_check hvmemul_put_fpu(struct x86_emulate_ctxt *ctxt,enum x86_emulate_fpu_type backout,const struct x86_emul_fpu_aux *aux)
@@ -2482,7 +2482,7 @@ static void hvmemul_put_fpu( } } -static int hvmemul_tlb_op( +static int cf_check hvmemul_tlb_op( enum x86emul_tlb_op op, unsigned long addr, unsigned long aux,
@@ -2539,7 +2539,7 @@ static int hvmemul_tlb_op(return rc; } -static int hvmemul_vmfunc ( +static int cf_check hvmemul_vmfunc(struct x86_emulate_ctxt *ctxt) {int rc;
xen/arch/x86/hvm/hvm.c +4 -4
@@ -3755,8 +3755,8 @@ void hvm_set_reg(struct vcpu *v, unsigned int reg, uint64_t val) } } -static bool is_sysdesc_access (const struct x86_emulate_state *state, -const struct x86_emulate_ctxt *ctxt) +static bool cf_check is_sysdesc_access( +const struct x86_emulate_state *state,const struct x86_emulate_ctxt *ctxt) {unsigned int ext;int mode =x86_insn_modrm (state,NULL , &ext);
@@ -3796,8 +3796,8 @@ int hvm_descriptor_access_intercept(uint64_t exit_info,return X86EMUL_OKAY ; } -static bool is_cross_vendor (const struct x86_emulate_state *state, -const struct x86_emulate_ctxt *ctxt) +static bool cf_check is_cross_vendor( +const struct x86_emulate_state *state,const struct x86_emulate_ctxt *ctxt) {switch ( ctxt->opcode ) {
xen/arch/x86/hvm/svm/svm.c +2 -2
@@ -2447,8 +2447,8 @@ static void svm_invlpg_intercept(unsigned long linear)paging_invlpg (current, linear); } -static bool is_invlpg (const struct x86_emulate_state *state, -const struct x86_emulate_ctxt *ctxt) +static bool cf_check is_invlpg( +const struct x86_emulate_state *state,const struct x86_emulate_ctxt *ctxt) {unsigned int ext;
xen/arch/x86/include/asm/hvm/emulate.h +4 -4
@@ -92,10 +92,10 @@ static inline bool handle_mmio(void)return hvm_emulate_one_insn (x86_insn_is_mem_access,"MMIO" ); } -int hvmemul_insn_fetch (unsigned long offset, -void *p_data, -unsigned int bytes, -struct x86_emulate_ctxt *ctxt); +int cf_check hvmemul_insn_fetch( +unsigned long offset,void *p_data,unsigned int bytes, +struct x86_emulate_ctxt *ctxt); + int hvmemul_do_pio_buffer(uint16_t port, unsigned int size, uint8_t dir,
xen/arch/x86/include/asm/mm.h +6 -10
@@ -538,16 +538,12 @@ struct mmio_ro_emulate_ctxt {unsigned int seg, bdf; }; -extern int mmio_ro_emulated_write (enum x86_segment seg, -unsigned long offset, -void *p_data, -unsigned int bytes, -struct x86_emulate_ctxt *ctxt); -extern int mmcfg_intercept_write (enum x86_segment seg, -unsigned long offset, -void *p_data, -unsigned int bytes, -struct x86_emulate_ctxt *ctxt); +int cf_check mmio_ro_emulated_write( +enum x86_segment seg,unsigned long offset,void *p_data, +unsigned int bytes,struct x86_emulate_ctxt *ctxt); +int cf_check mmcfg_intercept_write( +enum x86_segment seg,unsigned long offset,void *p_data, +unsigned int bytes,struct x86_emulate_ctxt *ctxt);int audit_adjust_pgtables (struct domain *d,int dir,int noisy);
xen/arch/x86/mm.c +2 -2
@@ -4852,7 +4852,7 @@ long arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return 0 ; } -int mmio_ro_emulated_write( +int cf_check mmio_ro_emulated_write( enum x86_segment seg, unsigned long offset, void *p_data,
@@ -4873,7 +4873,7 @@ int mmio_ro_emulated_write(return X86EMUL_OKAY ; } -int mmcfg_intercept_write( +int cf_check mmcfg_intercept_write( enum x86_segment seg, unsigned long offset, void *p_data,
xen/arch/x86/mm/shadow/hvm.c +4 -4
@@ -148,7 +148,7 @@ hvm_read(enum x86_segment seg,return X86EMUL_UNHANDLEABLE ; } -static int +static int cf_check hvm_emulate_read(enum x86_segment seg, unsigned long offset, void *p_data,
@@ -161,7 +161,7 @@ hvm_emulate_read(enum x86_segment seg, container_of(ctxt, struct sh_emulate_ctxt, ctxt)); } -static int +static int cf_check hvm_emulate_insn_fetch(unsigned long offset, void *p_data, unsigned int bytes,
@@ -181,7 +181,7 @@ hvm_emulate_insn_fetch(unsigned long offset,return X86EMUL_OKAY ; } -static int +static int cf_check hvm_emulate_write(enum x86_segment seg, unsigned long offset, void *p_data,
@@ -234,7 +234,7 @@ hvm_emulate_write(enum x86_segment seg,return X86EMUL_OKAY ; } -static int +static int cf_check hvm_emulate_cmpxchg(enum x86_segment seg, unsigned long offset, void *p_old,
xen/arch/x86/pv/emul-gate-op.c +5 -4
@@ -96,8 +96,9 @@ struct gate_op_ctxt {bool insn_fetch; }; -static int read_mem (enum x86_segment seg,unsigned long offset,void *p_data, -unsigned int bytes,struct x86_emulate_ctxt *ctxt) +static int cf_check read_mem( +enum x86_segment seg,unsigned long offset,void *p_data, +unsigned int bytes,struct x86_emulate_ctxt *ctxt) {const struct gate_op_ctxt *goc = container_of(ctxt, struct gate_op_ctxt, ctxt);
@@ -163,8 +164,8 @@ static int read_mem(enum x86_segment seg, unsigned long offset, void *p_data,return X86EMUL_OKAY ; } -static int fetch (unsigned long offset,void *p_data, -unsigned int bytes,struct x86_emulate_ctxt *ctxt) +static int cf_check fetch(unsigned long offset, void *p_data, +unsigned int bytes,struct x86_emulate_ctxt *ctxt) {return read_mem (x86_seg_cs, offset, p_data, bytes, ctxt); }
xen/arch/x86/pv/emul-priv-op.c +33 -31
136 lines not on this page · raw message
xen/arch/x86/pv/emulate.h +0 -7
@@ -12,13 +12,6 @@ int pv_emul_read_descriptor(unsigned int sel, const struct vcpu *v,void pv_emul_instruction_done (struct cpu_user_regs *regs,unsigned long rip); -static inline int pv_emul_is_mem_write (const struct x86_emulate_state *state, -struct x86_emulate_ctxt *ctxt) -{ -return x86_insn_is_mem_write (state, ctxt) ?X86EMUL_OKAY - :X86EMUL_UNHANDLEABLE ; -} -/* Return a pointer to the GDT/LDT descriptor referenced by sel. */ static inline const seg_desc_t *gdt_ldt_desc_ptr (unsigned int sel) {
xen/arch/x86/pv/ro-page-fault.c +19 -12
@@ -26,6 +26,13 @@#include "emulate.h" #include "mm.h" +static int cf_check pv_emul_is_mem_write( +const struct x86_emulate_state *state,struct x86_emulate_ctxt *ctxt) +{ +return x86_insn_is_mem_write (state, ctxt) ?X86EMUL_OKAY + :X86EMUL_UNHANDLEABLE ; +} +/********************* * Writable Pagetables */
@@ -35,9 +42,9 @@ struct ptwr_emulate_ctxt {l1_pgentry_t pte; }; -static int ptwr_emulated_read (enum x86_segment seg,unsigned long offset, -void *p_data,unsigned int bytes, -struct x86_emulate_ctxt *ctxt) +static int cf_check ptwr_emulated_read( +enum x86_segment seg,unsigned long offset,void *p_data, +unsigned int bytes,struct x86_emulate_ctxt *ctxt) {unsigned int rc = bytes;unsigned long addr = offset;
@@ -52,9 +59,9 @@ static int ptwr_emulated_read(enum x86_segment seg, unsigned long offset,return X86EMUL_OKAY ; } -static int ptwr_emulated_insn_fetch (unsigned long offset, -void *p_data,unsigned int bytes, -struct x86_emulate_ctxt *ctxt) +static int cf_check ptwr_emulated_insn_fetch( +unsigned long offset,void *p_data,unsigned int bytes, +struct x86_emulate_ctxt *ctxt) {unsigned int rc =copy_from_guest_pv (p_data, (void *)offset, bytes);
@@ -218,9 +225,9 @@ static int ptwr_emulated_update(unsigned long addr, intpte_t *p_old,return X86EMUL_OKAY ; } -static int ptwr_emulated_write (enum x86_segment seg,unsigned long offset, -void *p_data,unsigned int bytes, -struct x86_emulate_ctxt *ctxt) +static int cf_check ptwr_emulated_write( +enum x86_segment seg,unsigned long offset,void *p_data, +unsigned int bytes,struct x86_emulate_ctxt *ctxt) {intpte_t val =0 ;
@@ -236,9 +243,9 @@ static int ptwr_emulated_write(enum x86_segment seg, unsigned long offset,return ptwr_emulated_update (offset,NULL , val, bytes, ctxt); } -static int ptwr_emulated_cmpxchg (enum x86_segment seg,unsigned long offset, -void *p_old,void *p_new,unsigned int bytes, -bool lock,struct x86_emulate_ctxt *ctxt) +static int cf_check ptwr_emulated_cmpxchg( +enum x86_segment seg,unsigned long offset,void *p_old,void *p_new, +unsigned int bytes,bool lock,struct x86_emulate_ctxt *ctxt) {intpte_t old =0 , new =0 ;int rc;
xen/arch/x86/x86_emulate.c +11 -10
@@ -53,8 +53,8 @@#include "x86_emulate/x86_emulate.c" -int x86emul_read_xcr (unsigned int reg,uint64_t *val, -struct x86_emulate_ctxt *ctxt) +int cf_check x86emul_read_xcr( +unsigned int reg,uint64_t *val,struct x86_emulate_ctxt *ctxt) {switch ( reg ) {
@@ -77,8 +77,8 @@ int x86emul_read_xcr(unsigned int reg, uint64_t *val, }/* Note: May be called with ctxt=NULL. */ -int x86emul_write_xcr (unsigned int reg,uint64_t val, -struct x86_emulate_ctxt *ctxt) +int cf_check x86emul_write_xcr( +unsigned int reg,uint64_t val,struct x86_emulate_ctxt *ctxt) {switch ( reg ) {
@@ -100,8 +100,8 @@ int x86emul_write_xcr(unsigned int reg, uint64_t val,#ifdef CONFIG_PV /* Called with NULL ctxt in hypercall context. */ -int x86emul_read_dr (unsigned int reg,unsigned long *val, -struct x86_emulate_ctxt *ctxt) +int cf_check x86emul_read_dr( +unsigned int reg,unsigned long *val,struct x86_emulate_ctxt *ctxt) {struct vcpu *curr = current;
@@ -143,8 +143,8 @@ int x86emul_read_dr(unsigned int reg, unsigned long *val,return X86EMUL_OKAY ; } -int x86emul_write_dr (unsigned int reg,unsigned long val, -struct x86_emulate_ctxt *ctxt) +int cf_check x86emul_write_dr( +unsigned int reg,unsigned long val,struct x86_emulate_ctxt *ctxt) {struct vcpu *curr = current;
@@ -167,8 +167,9 @@ int x86emul_write_dr(unsigned int reg, unsigned long val, }#endif /* CONFIG_PV */ -int x86emul_cpuid (uint32_t leaf,uint32_t subleaf, -struct cpuid_leaf *res,struct x86_emulate_ctxt *ctxt) +int cf_check x86emul_cpuid( +uint32_t leaf,uint32_t subleaf,struct cpuid_leaf *res, +struct x86_emulate_ctxt *ctxt) {guest_cpuid (current, leaf, subleaf, res);
xen/arch/x86/x86_emulate/x86_emulate.c +5 -5
@@ -2524,7 +2524,7 @@ static void adjust_bnd(struct x86_emulate_ctxt *ctxt, done:; } -int x86emul_unhandleable_rw( +int cf_check x86emul_unhandleable_rw( enum x86_segment seg, unsigned long offset, void *p_data,
@@ -12320,7 +12320,7 @@ x86_insn_operand_ea(const struct x86_emulate_state *state,* memory operand (like POP), but it does not mean e.g. segment selector * loads, where the descriptor table access is considered an implicit one. */ -bool +bool cf_checkx86_insn_is_mem_access (const struct x86_emulate_state *state,const struct x86_emulate_ctxt *ctxt) {
@@ -12412,7 +12412,7 @@ x86_insn_is_mem_access(const struct x86_emulate_state *state,* loads, where the (possible) descriptor table write is considered an * implicit access. */ -bool +bool cf_checkx86_insn_is_mem_write (const struct x86_emulate_state *state,const struct x86_emulate_ctxt *ctxt) {
@@ -12584,7 +12584,7 @@ x86_insn_is_mem_write(const struct x86_emulate_state *state,return false; } -bool +bool cf_checkx86_insn_is_portio (const struct x86_emulate_state *state,const struct x86_emulate_ctxt *ctxt) {
@@ -12599,7 +12599,7 @@ x86_insn_is_portio(const struct x86_emulate_state *state,return false; } -bool +bool cf_checkx86_insn_is_cr_access (const struct x86_emulate_state *state,const struct x86_emulate_ctxt *ctxt) {
xen/arch/x86/x86_emulate/x86_emulate.h +17 -16
@@ -737,7 +737,7 @@ static inline unsigned long *decode_gpr(struct cpu_user_regs *regs, }/* Unhandleable read, write or instruction fetch */ -int +int cf_check x86emul_unhandleable_rw( enum x86_segment seg, unsigned long offset,
@@ -766,16 +766,16 @@ x86_insn_immediate(const struct x86_emulate_state *state,unsigned int x86_insn_length (const struct x86_emulate_state *state,const struct x86_emulate_ctxt *ctxt); -bool +bool cf_checkx86_insn_is_mem_access (const struct x86_emulate_state *state,const struct x86_emulate_ctxt *ctxt); -bool +bool cf_checkx86_insn_is_mem_write (const struct x86_emulate_state *state,const struct x86_emulate_ctxt *ctxt); -bool +bool cf_checkx86_insn_is_portio (const struct x86_emulate_state *state,const struct x86_emulate_ctxt *ctxt); -bool +bool cf_checkx86_insn_is_cr_access (const struct x86_emulate_state *state,const struct x86_emulate_ctxt *ctxt);
@@ -787,17 +787,18 @@ void x86_emulate_free_state(struct x86_emulate_state *state);#ifdef __XEN__ -int x86emul_read_xcr (unsigned int reg,uint64_t *val, -struct x86_emulate_ctxt *ctxt); -int x86emul_write_xcr (unsigned int reg,uint64_t val, -struct x86_emulate_ctxt *ctxt); - -int x86emul_read_dr (unsigned int reg,unsigned long *val, -struct x86_emulate_ctxt *ctxt); -int x86emul_write_dr (unsigned int reg,unsigned long val, -struct x86_emulate_ctxt *ctxt); -int x86emul_cpuid (uint32_t leaf,uint32_t subleaf, -struct cpuid_leaf *res,struct x86_emulate_ctxt *ctxt); +int cf_check x86emul_read_xcr( +unsigned int reg,uint64_t *val,struct x86_emulate_ctxt *ctxt); +int cf_check x86emul_write_xcr( +unsigned int reg,uint64_t val,struct x86_emulate_ctxt *ctxt); + +int cf_check x86emul_read_dr( +unsigned int reg,unsigned long *val,struct x86_emulate_ctxt *ctxt); +int cf_check x86emul_write_dr( +unsigned int reg,unsigned long val,struct x86_emulate_ctxt *ctxt); +int cf_check x86emul_cpuid( +uint32_t leaf,uint32_t subleaf,struct cpuid_leaf *res, +struct x86_emulate_ctxt *ctxt);#endif
Signature · 1 line
2.11.0
PATCH v3 46/70 x86/logdirty: CFI hardening
In reply to Andrew CooperControl Flow Integrity schemes use toolchain and optionally hardware support to help protect against call/jump/return oriented programming attacks.
Use cf_check to annotate function pointer targets for the toolchain.
---
v3:
* Fix !CONFIG_SHADOW build. Annotate targets in none.c
--- xen/arch/x86/mm/hap/hap.c | 6 +++--- xen/arch/x86/mm/shadow/common.c | 12 ++++++------ xen/arch/x86/mm/shadow/none.c | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-)
xen/arch/x86/mm/hap/hap.c +3 -3
@@ -180,7 +180,7 @@ int hap_track_dirty_vram(struct domain *d,* NB: Domain that having device assigned should not set log_global. Because * there is no way to track the memory updating from device. */ -static int hap_enable_log_dirty (struct domain *d,bool_t log_global) +static int cf_check hap_enable_log_dirty(struct domain *d, bool log_global) {struct p2m_domain *p2m =p2m_get_hostp2m (d);
@@ -211,7 +211,7 @@ static int hap_enable_log_dirty(struct domain *d, bool_t log_global)return 0 ; } -static int hap_disable_log_dirty (struct domain *d) +static int cf_check hap_disable_log_dirty(struct domain *d) {paging_lock (d); d->arch.paging.mode &= ~PG_log_dirty;
@@ -228,7 +228,7 @@ static int hap_disable_log_dirty(struct domain *d)return 0 ; } -static void hap_clean_dirty_bitmap (struct domain *d) +static void cf_check hap_clean_dirty_bitmap(struct domain *d) {/* * Switch to log-dirty mode, either by setting l1e entries of P2M table to
xen/arch/x86/mm/shadow/common.c +6 -6
@@ -40,9 +40,9 @@DEFINE_PER_CPU (uint32_t,trace_shadow_path_flags); -static int sh_enable_log_dirty (struct domain *,bool log_global); -static int sh_disable_log_dirty (struct domain *); -static void sh_clean_dirty_bitmap (struct domain *); +static int cf_check sh_enable_log_dirty(struct domain *, bool log_global); +static int cf_check sh_disable_log_dirty(struct domain *); +static void cf_check sh_clean_dirty_bitmap(struct domain *);/* Set up the shadow-specific parts of a domain struct at start of day. * Called for every domain from arch_domain_create() */
@@ -3016,7 +3016,7 @@ static int shadow_test_disable(struct domain *d)/* Shadow specific code which is called in paging_log_dirty_enable(). * Return 0 if no problem found. */ -static int sh_enable_log_dirty (struct domain *d,bool log_global) +static int cf_check sh_enable_log_dirty(struct domain *d, bool log_global) {int ret;
@@ -3044,7 +3044,7 @@ static int sh_enable_log_dirty(struct domain *d, bool log_global) }/* shadow specfic code which is called in paging_log_dirty_disable() */ -static int sh_disable_log_dirty (struct domain *d) +static int cf_check sh_disable_log_dirty(struct domain *d) {int ret;
@@ -3058,7 +3058,7 @@ static int sh_disable_log_dirty(struct domain *d)/* This function is called when we CLEAN log dirty bitmap. See * paging_log_dirty_op() for details. */ -static void sh_clean_dirty_bitmap (struct domain *d) +static void cf_check sh_clean_dirty_bitmap(struct domain *d) {paging_lock (d);/* Need to revoke write access to the domain's pages again.
xen/arch/x86/mm/shadow/none.c +3 -3
@@ -1,19 +1,19 @@#include <xen/mm.h> #include <asm/shadow.h> -static int _enable_log_dirty (struct domain *d,bool log_global) +static int cf_check _enable_log_dirty(struct domain *d, bool log_global) {ASSERT (is_pv_domain (d));return -EOPNOTSUPP ; } -static int _disable_log_dirty (struct domain *d) +static int cf_check _disable_log_dirty(struct domain *d) {ASSERT (is_pv_domain (d));return -EOPNOTSUPP ; } -static void _clean_dirty_bitmap (struct domain *d) +static void cf_check _clean_dirty_bitmap(struct domain *d) {ASSERT (is_pv_domain (d)); }
Signature · 1 line
2.11.0
PATCH v3 47/70 x86/shadow: CFI hardening
In reply to Andrew CooperControl Flow Integrity schemes use toolchain and optionally hardware support to help protect against call/jump/return oriented programming attacks.
Use cf_check to annotate function pointer targets for the toolchain.
---
v3:
* Fix !CONFIG_SHADOW build. Annotate targets in none.c
--- xen/arch/x86/mm/shadow/common.c | 11 +++--- xen/arch/x86/mm/shadow/hvm.c | 8 ++-- xen/arch/x86/mm/shadow/multi.c | 80 ++++++++++++++++++++-------------------- xen/arch/x86/mm/shadow/multi.h | 20 +++++----- xen/arch/x86/mm/shadow/none.c | 14 +++---- xen/arch/x86/mm/shadow/private.h | 12 +++--- xen/arch/x86/mm/shadow/pv.c | 4 +- 7 files changed, 74 insertions(+), 75 deletions(-)
xen/arch/x86/mm/shadow/common.c +6 -5
@@ -1215,7 +1215,7 @@ void shadow_free(struct domain *d, mfn_t smfn)* This action is irreversible: the p2m mapping only ever grows. * That's OK because the p2m table only exists for translated domains, * and those domains can't ever turn off shadow mode. */ -static struct page_info * +static struct page_info *cf_checkshadow_alloc_p2m_page (struct domain *d) {struct page_info *pg;
@@ -1251,7 +1251,7 @@ shadow_alloc_p2m_page(struct domain *d)return pg; } -static void +static void cf_checkshadow_free_p2m_page (struct domain *d,struct page_info *pg) {struct domain *owner =page_get_owner (pg);
@@ -2290,7 +2290,8 @@ void shadow_prepare_page_type_change(struct domain *d, struct page_info *page,/* Reset the up-pointers of every L3 shadow to 0. * This is called when l3 shadows stop being pinnable, to clear out all * the list-head bits so the up-pointer field is properly inititalised. */ -static int sh_clear_up_pointer (struct vcpu *v,mfn_t smfn,mfn_t unused) +static int cf_check sh_clear_up_pointer( +struct vcpu *v,mfn_t smfn,mfn_t unused) {mfn_to_page (smfn)->up =0 ;return 0 ;
@@ -2490,7 +2491,7 @@ static void sh_update_paging_modes(struct vcpu *v) v->arch.paging.mode->update_cr3 (v,0 , false); } -void shadow_update_paging_modes (struct vcpu *v) +void cf_check shadow_update_paging_modes(struct vcpu *v) {paging_lock (v->domain);sh_update_paging_modes (v);
@@ -3075,7 +3076,7 @@ static bool flush_vcpu(const struct vcpu *v, const unsigned long *vcpu_bitmap) }/* Flush TLB of selected vCPUs. NULL for all. */ -bool shadow_flush_tlb (const unsigned long *vcpu_bitmap) +bool cf_check shadow_flush_tlb(const unsigned long *vcpu_bitmap) { static DEFINE_PER_CPU(cpumask_t, flush_cpumask);cpumask_t *mask = &this_cpu (flush_cpumask);
xen/arch/x86/mm/shadow/hvm.c +4 -4
@@ -794,9 +794,9 @@ sh_remove_all_shadows_and_parents(struct domain *d, mfn_t gmfn)* It means extra emulated writes and slows down removal of mappings. */ } -static void sh_unshadow_for_p2m_change (struct domain *d,unsigned long gfn, -l1_pgentry_t old,l1_pgentry_t new, -unsigned int level) +static void cf_check sh_unshadow_for_p2m_change( +struct domain *d,unsigned long gfn,l1_pgentry_t old,l1_pgentry_t new, +unsigned int level) {mfn_t omfn =l1e_get_mfn (old);unsigned int oflags =l1e_get_flags (old);
@@ -879,7 +879,7 @@ static void sh_unshadow_for_p2m_change(struct domain *d, unsigned long gfn, }#if (SHADOW_OPTIMIZATIONS &SHOPT_FAST_FAULT_PATH ) -static void +static void cf_checksh_write_p2m_entry_post (struct p2m_domain *p2m,unsigned int oflags) {struct domain *d = p2m->domain;
xen/arch/x86/mm/shadow/multi.c +39 -41
252 lines not on this page · raw message
xen/arch/x86/mm/shadow/multi.h +10 -10
@@ -59,10 +59,10 @@ extern voidSHADOW_INTERNAL_NAME (sh_unhook_64b_mappings,GUEST_LEVELS ) (struct domain *d, mfn_t sl4mfn, int user_only); -extern int +int cf_checkSHADOW_INTERNAL_NAME (sh_rm_write_access_from_l1 ,GUEST_LEVELS ) (struct domain *d,mfn_t sl1mfn,mfn_t readonly_mfn); -extern int +int cf_checkSHADOW_INTERNAL_NAME (sh_rm_mappings_from_l1 ,GUEST_LEVELS ) (struct domain *d,mfn_t sl1mfn,mfn_t target_mfn);
@@ -70,30 +70,30 @@ extern voidSHADOW_INTERNAL_NAME (sh_clear_shadow_entry,GUEST_LEVELS ) (struct domain *d, void *ep, mfn_t smfn); -extern int +int cf_checkSHADOW_INTERNAL_NAME (sh_remove_l1_shadow ,GUEST_LEVELS ) (struct domain *d,mfn_t sl2mfn,mfn_t sl1mfn); -extern int +int cf_checkSHADOW_INTERNAL_NAME (sh_remove_l2_shadow ,GUEST_LEVELS ) (struct domain *d,mfn_t sl3mfn,mfn_t sl2mfn); -extern int +int cf_checkSHADOW_INTERNAL_NAME (sh_remove_l3_shadow ,GUEST_LEVELS ) (struct domain *d,mfn_t sl4mfn,mfn_t sl3mfn);#if SHADOW_AUDIT &SHADOW_AUDIT_ENTRIES -int +int cf_checkSHADOW_INTERNAL_NAME (sh_audit_l1_table ,GUEST_LEVELS ) (struct vcpu *v,mfn_t sl1mfn,mfn_t x); -int +int cf_checkSHADOW_INTERNAL_NAME (sh_audit_fl1_table ,GUEST_LEVELS ) (struct vcpu *v,mfn_t sl1mfn,mfn_t x); -int +int cf_checkSHADOW_INTERNAL_NAME (sh_audit_l2_table ,GUEST_LEVELS ) (struct vcpu *v,mfn_t sl2mfn,mfn_t x); -int +int cf_checkSHADOW_INTERNAL_NAME (sh_audit_l3_table ,GUEST_LEVELS ) (struct vcpu *v,mfn_t sl3mfn,mfn_t x); -int +int cf_checkSHADOW_INTERNAL_NAME (sh_audit_l4_table ,GUEST_LEVELS ) (struct vcpu *v,mfn_t sl4mfn,mfn_t x);#endif
xen/arch/x86/mm/shadow/none.c +7 -7
@@ -30,34 +30,34 @@ int shadow_domain_init(struct domain *d)return is_hvm_domain (d) ? -EOPNOTSUPP :0 ; } -static int _page_fault (struct vcpu *v,unsigned long va, -struct cpu_user_regs *regs) +static int cf_check _page_fault( +struct vcpu *v,unsigned long va,struct cpu_user_regs *regs) {ASSERT_UNREACHABLE ();return 0 ; } -static bool _invlpg (struct vcpu *v,unsigned long linear) +static bool cf_check _invlpg(struct vcpu *v, unsigned long linear) {ASSERT_UNREACHABLE ();return true; }#ifdef CONFIG_HVM -static unsigned long _gva_to_gfn (struct vcpu *v,struct p2m_domain *p2m, -unsigned long va,uint32_t *pfec) +static unsigned long cf_check _gva_to_gfn ( +struct vcpu *v,struct p2m_domain *p2m,unsigned long va,uint32_t *pfec) {ASSERT_UNREACHABLE ();return gfn_x (INVALID_GFN ); }#endif -static void _update_cr3 (struct vcpu *v,int do_locking,bool noflush) +static void cf_check _update_cr3(struct vcpu *v, int do_locking, bool noflush) {ASSERT_UNREACHABLE (); } -static void _update_paging_modes (struct vcpu *v) +static void cf_check _update_paging_modes(struct vcpu *v) {ASSERT_UNREACHABLE (); }
xen/arch/x86/mm/shadow/private.h +6 -6
@@ -420,15 +420,15 @@ static inline int sh_remove_write_access(struct domain *d, mfn_t readonly_mfn,#endif /* Functions that atomically write PV guest PT entries */ -void sh_write_guest_entry (struct vcpu *v,intpte_t *p,intpte_t new, -mfn_t gmfn); -intpte_t sh_cmpxchg_guest_entry (struct vcpu *v,intpte_t *p,intpte_t old, -intpte_t new,mfn_t gmfn); +void cf_check sh_write_guest_entry( +struct vcpu *v,intpte_t *p,intpte_t new,mfn_t gmfn); +intpte_t cf_check sh_cmpxchg_guest_entry( +struct vcpu *v,intpte_t *p,intpte_t old,intpte_t new,mfn_t gmfn);/* Update all the things that are derived from the guest's CR0/CR3/CR4. * Called to initialize paging structures if the paging mode * has changed, and when bringing up a VCPU for the first time. */ -void shadow_update_paging_modes (struct vcpu *v); +void cf_check shadow_update_paging_modes(struct vcpu *v);/* Unhook the non-Xen mappings in this top-level shadow mfn. * With user_only == 1, unhooks only the user-mode mappings. */
@@ -922,7 +922,7 @@ static inline int sh_check_page_has_no_refs(struct page_info *page) }/* Flush the TLB of the selected vCPUs. */ -bool shadow_flush_tlb (const unsigned long *vcpu_bitmap); +bool cf_check shadow_flush_tlb(const unsigned long *vcpu_bitmap);#endif /* _XEN_SHADOW_PRIVATE_H */
xen/arch/x86/mm/shadow/pv.c +2 -2
@@ -28,7 +28,7 @@* Write a new value into the guest pagetable, and update the shadows * appropriately. */ -void +void cf_checksh_write_guest_entry (struct vcpu *v,intpte_t *p,intpte_t new,mfn_t gmfn) {paging_lock (v->domain);
@@ -42,7 +42,7 @@ sh_write_guest_entry(struct vcpu *v, intpte_t *p, intpte_t new, mfn_t gmfn)* appropriately. Returns the previous entry found, which the caller is * expected to check to see if the cmpxchg was successful. */ -intpte_t +intpte_t cf_checksh_cmpxchg_guest_entry (struct vcpu *v,intpte_t *p,intpte_t old,intpte_t new,mfn_t gmfn) {
Signature · 1 line
2.11.0
PATCH v3 59/70 x86: Use control flow typechecking where possible
In reply to Andrew CooperNow all callees have been annotated, turn on typechecking to catch issues in the future.
This extension isn't in a released version of GCC yet, so provide a container to use with the extention included, and add it to CI. RANDCONFIG is necessary because some stubs for compiled-out subsystems are used as function pointer targets.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
v3:
* Provide container. Already pushed to Gitlab.
--- automation/build/debian/buster-gcc-ibt.dockerfile | 66 +++++++++++++++++++++++ automation/gitlab-ci/build.yaml | 6 +++ automation/scripts/containerize | 1 + xen/arch/x86/arch.mk | 1 + 4 files changed, 74 insertions(+) create mode 100644 automation/build/debian/buster-gcc-ibt.dockerfile
automation/build/debian/buster-gcc-ibt.dockerfile new file +66 -0
@@ -0,0 +1,66 @@ +FROM debian:buster-slim AS builder + +ENV DEBIAN_FRONTEND=noninteractive +ENV USER root + +RUN apt-get update && \ + apt-get --quiet --yes install \ + bison \ + build-essential \ + flex \ + libc6-dev-i386 \ + libgmp-dev \ + libisl-dev \ + libmpc-dev \ + libmpfr-dev \ + patch \ + wget + +RUN mkdir /build +WORKDIR /build + +RUN wget -q https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz -O - | tar xJ --strip=1 +RUN wget -q https://xenbits.xen.org/people/andrewcoop/gcc-11.2-Add-fcf-check-attribute-yes-no.patch -O - | patch -p1 +RUN ./configure \ + --prefix=/opt/gcc-11-ibt \ + --enable-languages=c \ + --disable-nls \ + --disable-threads \ + --disable-bootstrap \ + --disable-shared \ + --disable-libmudflap \ + --disable-libssp \ + --disable-libgomp \ + --disable-decimal-float \ + --disable-libquadmath \ + --disable-libatomic \ + --disable-libcc1 \ + --disable-libmpx +RUN make -j`nproc` && make -j`nproc` install + + +FROM debian:buster-slim +COPY --from=builder /opt/gcc-11-ibt /opt/gcc-11-ibt + +LABEL maintainer.name="The Xen Project" \ + maintainer.email="[email protected]" + +ENV DEBIAN_FRONTEND=noninteractive +ENV USER root +ENV PATH="/opt/gcc-11-ibt/bin:${PATH}" + +RUN mkdir /build +WORKDIR /build + +RUN apt-get update && \ + apt-get --quiet --yes install \ + bison \ + checkpolicy \ + flex \ + gawk \ + make \ + python3 \ + && \ + apt-get autoremove -y && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists* /tmp/* /var/tmp/*
automation/gitlab-ci/build.yaml +6 -0
@@ -294,6 +294,12 @@ debian-stretch-32-gcc-debug: variables: CONTAINER: debian:stretch-i386 +debian-buster-gcc-ibt: + extends: .gcc-x86-64-build + variables: + CONTAINER: debian:buster-gcc-ibt + RANDCONFIG: y + debian-unstable-clang: extends: .clang-x86-64-build variables:
automation/scripts/containerize +1 -0
@@ -33,6 +33,7 @@ case "_${CONTAINER}" in _focal) CONTAINER="${BASE}/ubuntu:focal" ;; _jessie) CONTAINER="${BASE}/debian:jessie" ;; _stretch|_) CONTAINER="${BASE}/debian:stretch" ;; + _buster-gcc-ibt) CONTAINER="${BASE}/debian:buster-gcc-ibt" ;; _unstable|_) CONTAINER="${BASE}/debian:unstable" ;; _trusty) CONTAINER="${BASE}/ubuntu:trusty" ;; _xenial) CONTAINER="${BASE}/ubuntu:xenial" ;;
xen/arch/x86/arch.mk +1 -0
@@ -54,6 +54,7 @@ endif ifdef CONFIG_XEN_IBT CFLAGS += -fcf-protection=branch -mmanual-endbr +$(call cc-option-add,CFLAGS,CC,-fcf-check-attribute=no) else $(call cc-option-add,CFLAGS,CC,-fcf-protection=none) endif
Signature · 1 line
2.11.0
Re: [PATCH v3 59/70] x86: Use control flow typechecking where possible
Quoted 9 lines · Andrew Cooper
Now all callees have been annotated, turn on typechecking to catch issues in the future.
This extension isn't in a released version of GCC yet, so provide a container to use with the extention included, and add it to CI. RANDCONFIG is necessary because some stubs for compiled-out subsystems are used as function pointer targets.
Signed-off-by Andrew Cooper <[email protected]>
I certainly see that we will want to have this extra level of safety. Hence feel free to add
But I'd like us to form a plan in case the change doesn't get committed relatively soon after gcc re-opens for general development after gcc12 was branched off. We don't want to get into the position of needing to maintain a gcc patch. Do you have any insight as to what is actually blocking the committing of that change, seeing that it has been around for a while?
Jan
Quoted 128 lines
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>v3:
* Provide container. Already pushed to Gitlab.--- automation/build/debian/buster-gcc-ibt.dockerfile | 66 +++++++++++++++++++++++ automation/gitlab-ci/build.yaml | 6 +++ automation/scripts/containerize | 1 + xen/arch/x86/arch.mk | 1 + 4 files changed, 74 insertions(+) create mode 100644 automation/build/debian/buster-gcc-ibt.dockerfileautomation/build/debian/buster-gcc-ibt.dockerfile new file +66
-0@@ -0,0 +1,66 @@ +FROM debian:buster-slim AS builder + +ENV DEBIAN_FRONTEND=noninteractive +ENV USER root + +RUN apt-get update && \ + apt-get --quiet --yes install \ + bison \ + build-essential \ + flex \ + libc6-dev-i386 \ + libgmp-dev \ + libisl-dev \ + libmpc-dev \ + libmpfr-dev \ + patch \ + wget + +RUN mkdir /build +WORKDIR /build + +RUN wget -q https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz -O - | tar xJ --strip=1 +RUN wget -q https://xenbits.xen.org/people/andrewcoop/gcc-11.2-Add-fcf-check-attribute-yes-no.patch -O - | patch -p1 +RUN ./configure \ + --prefix=/opt/gcc-11-ibt \ + --enable-languages=c \ + --disable-nls \ + --disable-threads \ + --disable-bootstrap \ + --disable-shared \ + --disable-libmudflap \ + --disable-libssp \ + --disable-libgomp \ + --disable-decimal-float \ + --disable-libquadmath \ + --disable-libatomic \ + --disable-libcc1 \ + --disable-libmpx +RUN make -j`nproc` && make -j`nproc` install + + +FROM debian:buster-slim +COPY --from=builder /opt/gcc-11-ibt /opt/gcc-11-ibt + +LABEL maintainer.name="The Xen Project" \ + maintainer.email="[email protected]" + +ENV DEBIAN_FRONTEND=noninteractive +ENV USER root +ENV PATH="/opt/gcc-11-ibt/bin:${PATH}" + +RUN mkdir /build +WORKDIR /build + +RUN apt-get update && \ + apt-get --quiet --yes install \ + bison \ + checkpolicy \ + flex \ + gawk \ + make \ + python3 \ + && \ + apt-get autoremove -y && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists* /tmp/* /var/tmp/*automation/gitlab-ci/build.yaml +6
-0@@ -294,6 +294,12 @@ debian-stretch-32-gcc-debug: variables: CONTAINER: debian:stretch-i386 +debian-buster-gcc-ibt: + extends: .gcc-x86-64-build + variables: + CONTAINER: debian:buster-gcc-ibt + RANDCONFIG: y + debian-unstable-clang: extends: .clang-x86-64-build variables:automation/scripts/containerize +1
-0@@ -33,6 +33,7 @@ case "_${CONTAINER}" in _focal) CONTAINER="${BASE}/ubuntu:focal" ;; _jessie) CONTAINER="${BASE}/debian:jessie" ;; _stretch|_) CONTAINER="${BASE}/debian:stretch" ;; + _buster-gcc-ibt) CONTAINER="${BASE}/debian:buster-gcc-ibt" ;; _unstable|_) CONTAINER="${BASE}/debian:unstable" ;; _trusty) CONTAINER="${BASE}/ubuntu:trusty" ;; _xenial) CONTAINER="${BASE}/ubuntu:xenial" ;;xen/arch/x86/arch.mk +1
-0@@ -54,6 +54,7 @@ endif ifdef CONFIG_XEN_IBT CFLAGS += -fcf-protection=branch -mmanual-endbr +$(call cc-option-add,CFLAGS,CC,-fcf-check-attribute=no) else $(call cc-option-add,CFLAGS,CC,-fcf-protection=none) endif
Re: [PATCH v3 59/70] x86: Use control flow typechecking where possible
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
Now all callees have been annotated, turn on typechecking to catch issues in the future.
This extension isn't in a released version of GCC yet, so provide a container to use with the extention included, and add it to CI. RANDCONFIG is necessary because some stubs for compiled-out subsystems are used as function pointer targets.
Quoted 4 lines
Quoted 1 line
Signed-off-by Andrew Cooper <[email protected]>I certainly see that we will want to have this extra level of safety. Hence feel free to add
Acked-by Jan Beulich <[email protected]>
Thanks.
Quoted 6 lines
But I'd like us to form a plan in case the change doesn't get committed relatively soon after gcc re-opens for general development after gcc12 was branched off. We don't want to get into the position of needing to maintain a gcc patch. Do you have any insight as to what is actually blocking the committing of that change, seeing that it has been around for a while?
I'll follow up and try to unblock.
~Andrew
PATCH v3 60/70 x86: Build check for embedded endbr64 instructions
In reply to Andrew CooperFrom: Marek Marczykowski-Górecki <[email protected]>
An interesting corner case occurs when the byte sequence making up endb64 ends up on a non-instruction boundary. Such embedded instructions mark legal indirect branch targets as far as the CPU is concerned, which aren't legal as far as the logic is concerned.
When CET-IBT is active, check for embedded byte sequences. Example failures look like:
check-endbr.sh xen-syms Fail: Found 2 embedded endbr64 instructions 0xffff82d040325677: test_endbr64 at /local/xen.git/xen/arch/x86/x86_64/entry.S:28 0xffff82d040352da6: init_done at /local/xen.git/xen/arch/x86/setup.c:675
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
v2:
* New
v3:
* Reposition to the end of the cf_check-ing, to retain bisectability
* Reword commit message to explain 'embedded'
* Use ${ADDR2LINE} if present in the environment
* Use objdump -w
* Explain the use of octal
* Check the EFI build too. Reposition to be last action, so all build artefacts remain in a failure case
* Check for grep support and warn if missing
* Replace strtonum() with int() to avoid gaining a gawk dependency
* Replace join with sort | uniq to avoid adding a coreutils dependency
--- README | 1 + xen/arch/x86/Makefile | 6 ++++ xen/tools/check-endbr.sh | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100755 xen/tools/check-endbr.sh
README +1 -0
@@ -68,6 +68,7 @@ provided by your OS distributor: In addition to the above there are a number of optional build prerequisites. Omitting these will cause the related features to be disabled at compile time: + * Binary-search capable grep (if building Xen with CET support) * Development install of Ocaml (e.g. ocaml-nox and ocaml-findlib). Required to build ocaml components which includes the alternative ocaml xenstored.
xen/arch/x86/Makefile +6 -0
@@ -142,6 +142,9 @@ $(TARGET)-syms: $(BASEDIR)/prelink.o $(obj)/xen.lds | $(BASEDIR)/tools/symbols --all-symbols --xensyms --sysv --sort \ >$(@D)/$(@F).map rm -f $(@D)/.$(@F).[0-9]* $(@D)/..$(@F).[0-9]* +ifeq ($(CONFIG_XEN_IBT),y) + $(SHELL) $(BASEDIR)/tools/check-endbr.sh $@ +endif $(obj)/note.o: $(TARGET)-syms $(OBJCOPY) -O binary --only-section=.note.gnu.build-id $< [email protected]
@@ -212,6 +215,9 @@ endif $(NM) -pa --format=sysv $(@D)/$(@F) \ | $(BASEDIR)/tools/symbols --all-symbols --xensyms --sysv --sort >$(@D)/$(@F).map rm -f $(@D)/.$(@F).[0-9]* $(@D)/..$(@F).[0-9]* +ifeq ($(CONFIG_XEN_IBT),y) + $(SHELL) $(BASEDIR)/tools/check-endbr.sh $@ +endif else $(TARGET).efi: FORCE rm -f $@
xen/tools/check-endbr.sh new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
2.11.0
Re: [PATCH v3 60/70] x86: Build check for embedded endbr64 instructions
Quoted 3 lines · Andrew Cooper
From: Marek Marczykowski-Górecki <[email protected]>
An interesting corner case occurs when the byte sequence making up endb64 ends
Nit: For grep-ability it would be nice to spell this "endbr64".
Quoted 3 lines
up on a non-instruction boundary. Such embedded instructions mark legal indirect branch targets as far as the CPU is concerned, which aren't legal as far as the logic is concerned.
Thinking about it: Wouldn't it be yet slightly more reassuring to also look for ENDBR32?
Quoted 9 lines
When CET-IBT is active, check for embedded byte sequences. Example failures look like:
check-endbr.shxen-syms Fail: Found 2 embedded endbr64 instructions0xffff82d040325677:test_endbr64at /local/xen.git/xen/arch/x86/x86_64/entry.S:280xffff82d040352da6:init_doneat /local/xen.git/xen/arch/x86/setup.c:675Signed-off-by Marek Marczykowski-Górecki <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
README provided by your OS distributor: · line 71
Quoted 7 lines
README +1
-0@@ -68,6 +68,7 @@ provided by your OS distributor: In addition to the above there are a number of optional build prerequisites. Omitting these will cause the related features to be disabled at compile time: + * Binary-search capable grep (if building Xen with CET support)
Nit: With this (maybe this was the case already earlier though) s/will/may/ in the previous sentence?
Quoted 4 lines
xen/tools/check-endbr.sh new file +1
-0@@ -0,0 +1,85 @@ +#!/bin/sh
xen/tools/check-endbr.sh line 11
Quoted 10 lines
xen/tools/check-endbr.sh new file +10
-0+# +# Usage ./$0 xen-syms +# +set -e + +# Prettyprint parameters a little for message +MSG_PFX="${0##*/} ${1##*/}" + +OBJCOPY="${OBJCOPY:-objcopy} -j .text $1" +OBJDUMP="${OBJDUMP:-objdump} -j .text $1"
While embedding the arguments here shortens the lines where these are used, the appearance especially of $OBJCOPY with a single file name argument ...
Quoted 40 lines
xen/tools/check-endbr.sh new file +40
-0+ADDR2LINE="${ADDR2LINE:-addr2line}" + +D=$(mktemp -d) +trap "rm -rf $D" EXIT + +TEXT_BIN=$D/xen-syms.text +VALID=$D/valid-addrs +ALL=$D/all-addrs +BAD=$D/bad-addrs + +# Check that grep can do binary searches. Some, e.g. busybox, can't. Leave a +# warning but don't fail the build. +echo "X" | grep -aob "X" -q 2>/dev/null || + { echo "$MSG_PFX Warning: grep can't do binary searches" >&2; exit 0; } + +# +# First, look for all the valid endbr64 instructions. +# A worst-case disassembly, viewed through cat -A, may look like: +# +# ffff82d040337bd4 <endbr64>:$ +# ffff82d040337bd4:^If3 0f 1e fa ^Iendbr64 $ +# ffff82d040337bd8:^Ieb fe ^Ijmp ffff82d040337bd8 <endbr64+0x4>$ +# ffff82d040337bda:^Ib8 f3 0f 1e fa ^Imov $0xfa1e0ff3,%eax$ +# +# Want to grab the address of endbr64 instructions only, ignoring function +# names/jump labels/etc, so look for 'endbr64' preceeded by a tab and with any +# number of trailing spaces before the end of the line. +# +${OBJDUMP} -d -w | grep ' endbr64 *$' | cut -f 1 -d ':' > $VALID & + +# +# Second, look for any endbr64 byte sequence +# This has a couple of complications: +# +# 1) Grep binary search isn't VMA aware. Copy .text out as binary, causing +# the grep offset to be from the start of .text. +# +# 2) dash's printf doesn't understand hex escapes, hence the use of octal. +# +# 3) AWK can't add 64bit integers, because internally all numbers are doubles.
xen/tools/check-endbr.sh line 61
Quoted 10 lines
xen/tools/check-endbr.sh new file +10
-0+# When the upper bits are set, the exponents worth of precision is lost in +# the lower bits, rounding integers to the nearest 4k. +# +# Instead, use the fact that Xen's .text is within a 1G aligned region, and +# split the VMA in half so AWK's numeric addition is only working on 32 bit +# numbers, which don't lose precision. +# +eval $(${OBJDUMP} -h | awk '$2 == ".text" {printf "vma_hi=%s\nvma_lo=%s\n", substr($4, 1, 8), substr($4, 9, 16)}') + +${OBJCOPY} -O binary $TEXT_BIN
..., like here, is then somewhat misleading considering that the tool can take one or two filenames as arguments.
Jan
Re: [PATCH v3 60/70] x86: Build check for embedded endbr64 instructions
Quoted 6 lines · Jan Beulich
Quoted 3 lines · Andrew Cooper
up on a non-instruction boundary. Such embedded instructions mark legal indirect branch targets as far as the CPU is concerned, which aren't legal as far as the logic is concerned.
Thinking about it: Wouldn't it be yet slightly more reassuring to also look for ENDBR32?
I considered that, but it's awkward to do and doubles the length of this already ~0.7s (x2 for efi because this step isn't performed in parallel) delay to the build.
We do not have __HYPERVISOR_CS32, so ENDBR32 will yield #CP[endbr] if encountered.
If an attacker has managed to edit the GDT to insert a compatibility code segment, and hijacked a far transfer to use it, then the absence of ENDBR32's in the binary isn't going to be an impediment.
Quoted 11 lines
Quoted 10 lines
When CET-IBT is active, check for embedded byte sequences. Example failures look like:
check-endbr.shxen-syms Fail: Found 2 embedded endbr64 instructions0xffff82d040325677:test_endbr64at /local/xen.git/xen/arch/x86/x86_64/entry.S:280xffff82d040352da6:init_doneat /local/xen.git/xen/arch/x86/setup.c:675Signed-off-by Marek Marczykowski-Górecki <[email protected]>Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Jan Beulich <[email protected]>
Thanks.
Quoted 10 lines
README provided by your OS distributor: · line 71
Quoted 8 lines
README +1
-0@@ -68,6 +68,7 @@ provided by your OS distributor: In addition to the above there are a number of optional build prerequisites. Omitting these will cause the related features to be disabled at compile time: + * Binary-search capable grep (if building Xen with CET support)Nit: With this (maybe this was the case already earlier though) s/will/may/ in the previous sentence?
I'm planning a separate overhaul to README because bits of it are quite wrong, including lots of this section. This was the lead bad addition I could come up with that didn't involve a major rewrite.
Quoted 62 lines
Quoted 4 lines
xen/tools/check-endbr.sh new file +1
-0@@ -0,0 +1,85 @@ +#!/bin/shxen/tools/check-endbr.sh line 11
Quoted 10 lines
xen/tools/check-endbr.sh new file +10
-0+# +# Usage ./$0 xen-syms +# +set -e + +# Prettyprint parameters a little for message +MSG_PFX="${0##*/} ${1##*/}" + +OBJCOPY="${OBJCOPY:-objcopy} -j .text $1" +OBJDUMP="${OBJDUMP:-objdump} -j .text $1"While embedding the arguments here shortens the lines where these are used, the appearance especially of $OBJCOPY with a single file name argument ...
Quoted 44 lines
xen/tools/check-endbr.sh new file +44
-0+ADDR2LINE="${ADDR2LINE:-addr2line}" + +D=$(mktemp -d) +trap "rm -rf $D" EXIT + +TEXT_BIN=$D/xen-syms.text +VALID=$D/valid-addrs +ALL=$D/all-addrs +BAD=$D/bad-addrs + +# Check that grep can do binary searches. Some, e.g. busybox, can't. Leave a +# warning but don't fail the build. +echo "X" | grep -aob "X" -q 2>/dev/null || + { echo "$MSG_PFX Warning: grep can't do binary searches" >&2; exit 0; } + +# +# First, look for all the valid endbr64 instructions. +# A worst-case disassembly, viewed through cat -A, may look like: +# +# ffff82d040337bd4 <endbr64>:$ +# ffff82d040337bd4:^If3 0f 1e fa ^Iendbr64 $ +# ffff82d040337bd8:^Ieb fe ^Ijmp ffff82d040337bd8 <endbr64+0x4>$ +# ffff82d040337bda:^Ib8 f3 0f 1e fa ^Imov $0xfa1e0ff3,%eax$ +# +# Want to grab the address of endbr64 instructions only, ignoring function +# names/jump labels/etc, so look for 'endbr64' preceeded by a tab and with any +# number of trailing spaces before the end of the line. +# +${OBJDUMP} -d -w | grep ' endbr64 *$' | cut -f 1 -d ':' > $VALID & + +# +# Second, look for any endbr64 byte sequence +# This has a couple of complications: +# +# 1) Grep binary search isn't VMA aware. Copy .text out as binary, causing +# the grep offset to be from the start of .text. +# +# 2) dash's printf doesn't understand hex escapes, hence the use of octal. +# +# 3) AWK can't add 64bit integers, because internally all numbers are doubles. +# When the upper bits are set, the exponents worth of precision is lost in +# the lower bits, rounding integers to the nearest 4k. +# +# Instead, use the fact that Xen's .text is within a 1G aligned region, and
Quoted 8 lines
xen/tools/check-endbr.sh line 61
Quoted 6 lines
xen/tools/check-endbr.sh new file +6
-0+# split the VMA in half so AWK's numeric addition is only working on 32 bit +# numbers, which don't lose precision. +# +eval $(${OBJDUMP} -h | awk '$2 == ".text" {printf "vma_hi=%s\nvma_lo=%s\n", substr($4, 1, 8), substr($4, 9, 16)}') + +${OBJCOPY} -O binary $TEXT_BIN..., like here, is then somewhat misleading considering that the tool can take one or two filenames as arguments.
I can re-expand them if you'd prefer. This would be the delta:
xen/tools/check-endbr.sh +0 -0
@@ -7,8 +7,8 @@ set -e
# Prettyprint parameters a little for message MSG_PFX="${0##*/} ${1##*/}"
-OBJCOPY="${OBJCOPY:-objcopy} -j .text $1" -OBJDUMP="${OBJDUMP:-objdump} -j .text $1" +OBJCOPY="${OBJCOPY:-objcopy}" +OBJDUMP="${OBJDUMP:-objdump}" ADDR2LINE="${ADDR2LINE:-addr2line}"
D=$(mktemp -d)
@@ -37,7 +37,7 @@ echo "X" | grep -aob "X" -q 2>/dev/null ||
# names/jump labels/etc, so look for 'endbr64' preceeded by a tab and
with any
# number of trailing spaces before the end of the line.
#
-${OBJDUMP} -d -w | grep ' endbr64 *$' | cut -f 1 -d ':' > $VALID &
+${OBJDUMP} -j .text $1 -d -w | grep ' endbr64 *$' | cut -f 1 -d ':' >
$VALID &
#
# Second, look for any endbr64 byte sequence
@@ -56,9 +56,10 @@ ${OBJDUMP} -d -w | grep ' endbr64 *$' | cut -f 1
-d ':' > $VALID &
# split the VMA in half so AWK's numeric addition is only working on
32 bit
# numbers, which don't lose precision.
#
-eval $(${OBJDUMP} -h | awk '$2 == ".text" {printf
"vma_hi=%s\nvma_lo=%s\n", substr($4, 1, 8), substr($4, 9, 16)}')
+eval $(${OBJDUMP} -j .text $1 -h |
+ awk '$2 == ".text" {printf "vma_hi=%s\nvma_lo=%s\n", substr($4, 1,
8), substr($4, 9, 16)}')
-${OBJCOPY} -O binary $TEXT_BIN
+${OBJCOPY} -j .text $1 -O binary $TEXT_BIN
grep -aob "$(printf '\363\17\36\372')" $TEXT_BIN |
awk -F':' '{printf "%s%x\n", "'$vma_hi'", int(0x'$vma_lo') + $1}' >
$ALL
~Andrew
Re: [PATCH v3 60/70] x86: Build check for embedded endbr64 instructions
Quoted 11 lines · Andrew Cooper
Quoted 6 lines · Jan Beulich
Quoted 3 lines · Andrew Cooper
up on a non-instruction boundary. Such embedded instructions mark legal indirect branch targets as far as the CPU is concerned, which aren't legal as far as the logic is concerned.
Thinking about it: Wouldn't it be yet slightly more reassuring to also look for ENDBR32?
I considered that, but it's awkward to do and doubles the length of this already ~0.7s (x2 for efi because this step isn't performed in parallel) delay to the build.
(Side note: In general the two linking steps can occur in parallel. An exception is when the note.o need to be extracted from xen-syms for use by xen.efi. But that should happen only with old binutils.)
Quoted 6 lines
We do not have
__HYPERVISOR_CS32, so ENDBR32 will yield #CP[endbr] if encountered.If an attacker has managed to edit the GDT to insert a compatibility code segment, and hijacked a far transfer to use it, then the absence of ENDBR32's in the binary isn't going to be an impediment.
True.
Quoted 71 lines
Quoted 62 lines
Quoted 4 lines
xen/tools/check-endbr.sh new file +1
-0@@ -0,0 +1,85 @@ +#!/bin/shxen/tools/check-endbr.sh line 11
Quoted 10 lines
xen/tools/check-endbr.sh new file +10
-0+# +# Usage ./$0 xen-syms +# +set -e + +# Prettyprint parameters a little for message +MSG_PFX="${0##*/} ${1##*/}" + +OBJCOPY="${OBJCOPY:-objcopy} -j .text $1" +OBJDUMP="${OBJDUMP:-objdump} -j .text $1"While embedding the arguments here shortens the lines where these are used, the appearance especially of $OBJCOPY with a single file name argument ...
Quoted 44 lines
xen/tools/check-endbr.sh new file +44
-0+ADDR2LINE="${ADDR2LINE:-addr2line}" + +D=$(mktemp -d) +trap "rm -rf $D" EXIT + +TEXT_BIN=$D/xen-syms.text +VALID=$D/valid-addrs +ALL=$D/all-addrs +BAD=$D/bad-addrs + +# Check that grep can do binary searches. Some, e.g. busybox, can't. Leave a +# warning but don't fail the build. +echo "X" | grep -aob "X" -q 2>/dev/null || + { echo "$MSG_PFX Warning: grep can't do binary searches" >&2; exit 0; } + +# +# First, look for all the valid endbr64 instructions. +# A worst-case disassembly, viewed through cat -A, may look like: +# +# ffff82d040337bd4 <endbr64>:$ +# ffff82d040337bd4:^If3 0f 1e fa ^Iendbr64 $ +# ffff82d040337bd8:^Ieb fe ^Ijmp ffff82d040337bd8 <endbr64+0x4>$ +# ffff82d040337bda:^Ib8 f3 0f 1e fa ^Imov $0xfa1e0ff3,%eax$ +# +# Want to grab the address of endbr64 instructions only, ignoring function +# names/jump labels/etc, so look for 'endbr64' preceeded by a tab and with any +# number of trailing spaces before the end of the line. +# +${OBJDUMP} -d -w | grep ' endbr64 *$' | cut -f 1 -d ':' > $VALID & + +# +# Second, look for any endbr64 byte sequence +# This has a couple of complications: +# +# 1) Grep binary search isn't VMA aware. Copy .text out as binary, causing +# the grep offset to be from the start of .text. +# +# 2) dash's printf doesn't understand hex escapes, hence the use of octal. +# +# 3) AWK can't add 64bit integers, because internally all numbers are doubles. +# When the upper bits are set, the exponents worth of precision is lost in +# the lower bits, rounding integers to the nearest 4k. +# +# Instead, use the fact that Xen's .text is within a 1G aligned region, andQuoted 8 lines
xen/tools/check-endbr.sh line 61
Quoted 6 lines
xen/tools/check-endbr.sh new file +6
-0+# split the VMA in half so AWK's numeric addition is only working on 32 bit +# numbers, which don't lose precision. +# +eval $(${OBJDUMP} -h | awk '$2 == ".text" {printf "vma_hi=%s\nvma_lo=%s\n", substr($4, 1, 8), substr($4, 9, 16)}') + +${OBJCOPY} -O binary $TEXT_BIN..., like here, is then somewhat misleading considering that the tool can take one or two filenames as arguments.
Quoted 1 line
I can re-expand them if you'd prefer. This would be the delta:
I'd actually be happy to keep "-j .text" where you had it, and merely move the file arguments to the actual invocation lines. But the way you have it with the incremental diff is of course even less "unexpected".
Jan
Quoted 46 lines
xen/tools/check-endbr.sh +0
-0@@ -7,8 +7,8 @@ set -e # Prettyprint parameters a little for messageMSG_PFX="${0##*/} ${1##*/}"
xen/tools/check-endbr.sh +2
-2-OBJCOPY="${OBJCOPY:-objcopy} -j .text $1" -OBJDUMP="${OBJDUMP:-objdump} -j .text $1" +OBJCOPY="${OBJCOPY:-objcopy}" +OBJDUMP="${OBJDUMP:-objdump}"ADDR2LINE="${ADDR2LINE:-addr2line}"
D=$(mktemp -d)xen/tools/check-endbr.sh +0
-0@@ -37,7 +37,7 @@ echo "X" | grep -aob "X" -q 2>/dev/null || # names/jump labels/etc, so look for 'endbr64' preceeded by a tab andwith any
# number of trailing spaces before the end of the line. # -${OBJDUMP} -d -w | grep ' endbr64 *$' | cut -f 1 -d ':' > $VALID & +${OBJDUMP} -j .text $1 -d -w | grep ' endbr64 *$' | cut -f 1 -d ':' > $VALID & # # Second, look for any endbr64 byte sequencexen/tools/check-endbr.sh +0
-1@@ -56,9 +56,10 @@ ${OBJDUMP} -d -w | grep ' endbr64 *$' | cut -f 1 -d ':' > $VALID & # split the VMA in half so AWK's numeric addition is only working on32 bit
# numbers, which don't lose precision.
#
-eval $(${OBJDUMP} -h | awk '$2 == ".text" {printf "vma_hi=%s\nvma_lo=%s\n",substr($4, 1, 8),substr($4, 9, 16)}') +eval $(${OBJDUMP} -j .text $1 -h |
+ awk '$2 == ".text" {printf "vma_hi=%s\nvma_lo=%s\n",substr($4, 1, 8),substr($4, 9, 16)}')
-${OBJCOPY} -O binary $TEXT_BIN
+${OBJCOPY} -j .text $1 -O binary $TEXT_BIN
grep -aob "$(printf '\363\17\36\372')" $TEXT_BIN |
awk -F':' '{printf "%s%x\n", "'$vma_hi'",int(0x'$vma_lo')+ $1}' > $ALL~Andrew
PATCH v3 64/70 x86: Introduce helpers/checks for endbr64 instructions
In reply to Andrew Cooper... to prevent the optimiser creating unsafe code. See the code comment for full details.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
v3:
* Introduce ENDBR64_LEN
v2:
* Fix include to let the header be standalone
* Add earlyclobber to asm
v1.1:
* New
--- xen/arch/x86/include/asm/endbr.h | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 xen/arch/x86/include/asm/endbr.h
xen/arch/x86/include/asm/endbr.h new file +55 -0
@@ -0,0 +1,55 @@ +/****************************************************************************** +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2021-2022 Citrix Systems Ltd. +*/ +#ifndef XEN_ASM_ENDBR_H +#define XEN_ASM_ENDBR_H + +#include <xen/types.h> + +#define ENDBR64_LEN 4 + +/* +* In some cases we need to inspect/insert endbr64 instructions. +* +* The naive way, mem{cmp,cpy}(ptr, "\xf3\x0f\x1e\xfa", 4), optimises unsafely +* by placing 0xfa1e0ff3 in an imm32 operand, and marks a legal indirect +* branch target as far as the CPU is concerned. +* +* gen_endbr64() is written deliberately to avoid the problematic operand, and +* marked __const__ as it is safe for the optimiser to hoist/merge/etc. +*/ +static inline uint32_t __attribute_const__ gen_endbr64(void) +{ +uint32_t res; + + asm ("mov $~0xfa1e0ff3, %[res]\n\t" +"not %[res]\n\t" + : [res]"=&r" (res) ); + +return res; +} + +static inline bool is_endbr64 (const void *ptr) +{ +return *(const uint32_t *)ptr ==gen_endbr64 (); +} + +static inline void place_endbr64 (void *ptr) +{ + *(uint32_t *)ptr =gen_endbr64 (); +} + +#endif /* XEN_ASM_ENDBR_H */
Signature · 1 line
2.11.0