x86/altcall: Optimise away endbr64 instruction where possible
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 4 Nov 2021 19:36:23 +0000 (19:36 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 23 Feb 2022 15:33:43 +0000 (15:33 +0000)
commit37ed5da851b867ae7133720dba3cf96e83bef2e1
tree724480b11a9e8ae2e5465ad32c95f2c50aa1cb27
parent12e3410e071e284398e49d125e7d9cec076d00e5
x86/altcall: Optimise away endbr64 instruction where possible

With altcall, we convert indirect branches into direct ones.  With that
complete, none of the potential targets need an endbr64 instruction.

Furthermore, removing the endbr64 instructions is a security defence-in-depth
improvement, because it limits the options available to an attacker who has
managed to hijack a function pointer.

Introduce new .init.{ro,}data.cf_clobber sections.  Have _apply_alternatives()
walk over this, looking for any pointers into .text, and clobber an endbr64
instruction if found.  This is some minor structure (ab)use but it works
alarmingly well.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/alternative.c
xen/arch/x86/xen.lds.S
xen/include/xen/init.h