|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH 59.5/65] x86: Introduce helpers/checks for endbr64 instructions
On Fri, Nov 26, 2021 at 04:33:40PM +0000, Andrew Cooper wrote:
> ... to prevent the optimiser creating unsafe code. See the code comment for
> full details.
>
> Also add a build time check for endbr64 embedded in imm32 operands, which
> catches the obvious cases where the optimiser has done an unsafe thing.
>
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> ---
> CC: Jan Beulich <JBeulich@xxxxxxxx>
> CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
> CC: Wei Liu <wl@xxxxxxx>
> ---
> xen/arch/x86/Makefile | 4 ++++
> xen/include/asm-x86/endbr.h | 55
> +++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 59 insertions(+)
> create mode 100644 xen/include/asm-x86/endbr.h
>
> diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
> index 69b6cfaded25..64a5c0d20018 100644
> --- a/xen/arch/x86/Makefile
> +++ b/xen/arch/x86/Makefile
> @@ -190,6 +190,10 @@ $(TARGET)-syms: prelink.o xen.lds
> $(MAKE) -f $(BASEDIR)/Rules.mk efi-y= $(@D)/.$(@F).1.o
> $(LD) $(XEN_LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \
> $(@D)/.$(@F).1.o -o $@
> +ifeq ($(CONFIG_XEN_IBT),y)
> + $(OBJDUMP) -d $@ | grep 0xfa1e0ff3 >/dev/null && \
> + { echo "Found embedded endbr64 instructions" >&2; false; } || :
> +endif
Some more robust check can be done this way (warning, PoC quality bash):
objcopy -j .text xen-syms xen-syms.text
offset=$(objdump -h xen-syms -j .text | tail -2|head -1|awk '{printf
"%x\n", (strtonum("0x" $4) - strtonum("0x" $6))}')
objdump --adjust-vma=-0x$offset -d xen-syms.text|grep endbr | cut -f 1 -d
':' | tr -d ' ' > valid-addrs
grep -aob $'\xf3\x0f\x1e\xfa' xen-syms.text|cut -f 1 -d :|xargs printf
'%x\n' > all-addrs
join -v 2 <(sort valid-addrs) <(sort all-addrs) | awk '{ printf "%x\n",
0x'$offset' + strtonum("0x" $1)}' | addr2line -e xen-syms
Currently it finds just one match:
xen/arch/x86/alternative.c:145
--
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
Attachment:
signature.asc
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |