xen/x86: Livepatch: support patching CET-enhanced functions
authorBjoern Doebel <doebel@amazon.de>
Thu, 10 Mar 2022 07:35:36 +0000 (07:35 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 17 Mar 2022 20:34:06 +0000 (20:34 +0000)
commit6974c75180f1aad44e5428eabf2396b2b50fb0e4
tree7ee4afd558be4c3f068ed75ba2f278be86e83731
parent37786b23b027ab83051175cb8ce9ac86cacfc58e
xen/x86: Livepatch: support patching CET-enhanced functions

Xen enabled CET for supporting architectures. The control flow aspect of
CET require functions that can be called indirectly (i.e., via function
pointers) to start with an ENDBR64 instruction. Otherwise a control flow
exception is raised.

This expectation breaks livepatching flows because we patch functions by
overwriting their first 5 bytes with a JMP + <offset>, thus breaking the
ENDBR64. We fix this by checking the start of a patched function for
being ENDBR64. In the positive case we move the livepatch JMP to start
behind the ENDBR64 instruction.

To avoid having to guess the ENDBR64 offset again on patch reversal
(which might race with other mechanisms adding/removing ENDBR
dynamically), use the livepatch metadata to store the computed offset
along with the saved bytes of the overwritten function.

Signed-off-by: Bjoern Doebel <doebel@amazon.de>
Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Tested-by: Jiamei Xie <jiamei.xie@arm.com>
xen/arch/x86/livepatch.c
xen/include/public/sysctl.h