livepatch: account for patch offset when applying NOP patch
PATCH 1/1 livepatch: account for patch offset when applying NOP patch
While not triggered by the trivial xen_nop in-tree patch on staging/master, that patch exposes a problem on the stable trees, where all functions have ENDBR inserted. When NOP-ing out a range, we need to account for this. Handle this right in livepatch_insn_len().
---
Only build tested, as I don't have a live patching environment available.
For Arm this assumes that the patch_offset field starts out as zero; I think we can make such an assumption, yet otoh on x86 explicit initialization was added by the cited commit.
xen/include/xen/livepatch.h +1 -1
@@ -90,7 +90,7 @@ static inlineunsigned int livepatch_insn_len (const struct livepatch_func *func) {if ( !func->new_addr ) -return func->new_size; +return func->new_size - func->patch_offset;return ARCH_PATCH_INSN_SIZE ; }
Quoted 17 lines · Jan Beulich
While not triggered by the trivial
xen_nopin-tree patch on staging/master, that patch exposes a problem on the stable trees, where all functions have ENDBR inserted. When NOP-ing out a range, we need to account for this. Handle this right inlivepatch_insn_len().Fixes 6974c75180f1 ("xen/x86: Livepatch: support patching CET-enhanced functions")Signed-off-by Jan Beulich <[email protected]>---
Only build tested, as I don't have a live patching environment available.For Arm this assumes that the
patch_offsetfield starts out as zero; I think we can make such an assumption, yet otoh on x86 explicit initialization was added by the cited commit.
xen/include/xen/livepatch.h static inline · line 96
Quoted 8 lines
xen/include/xen/livepatch.h +1
-1@@ -90,7 +90,7 @@ static inlineunsigned int livepatch_insn_len (const struct livepatch_func *func) {if ( !func->new_addr ) -return func->new_size; +return func->new_size - func->patch_offset;return ARCH_PATCH_INSN_SIZE ; }
Don't you also need to move the call to livepatch_insn_len() in arch_livepatch_apply() after func->patch_offset has been adjusted to account for ENDBR presence?
Thanks, Roger.
Quoted 24 lines · Roger Pau Monné
Quoted 23 lines · Jan Beulich
While not triggered by the trivial
xen_nopin-tree patch on staging/master, that patch exposes a problem on the stable trees, where all functions have ENDBR inserted. When NOP-ing out a range, we need to account for this. Handle this right inlivepatch_insn_len().Fixes 6974c75180f1 ("xen/x86: Livepatch: support patching CET-enhanced functions")Signed-off-by Jan Beulich <[email protected]>---
Only build tested, as I don't have a live patching environment available.For Arm this assumes that the
patch_offsetfield starts out as zero; I think we can make such an assumption, yet otoh on x86 explicit initialization was added by the cited commit.xen/include/xen/livepatch.h +1
-1@@ -90,7 +90,7 @@ static inlineunsigned int livepatch_insn_len (const struct livepatch_func *func) {if ( !func->new_addr ) -return func->new_size; +return func->new_size - func->patch_offset;
Quoted 6 lines
xen/include/xen/livepatch.h static inline · line 96
Quoted 2 lines
xen/include/xen/livepatch.h +0
-0return ARCH_PATCH_INSN_SIZE ; }Don't you also need to move the call to
livepatch_insn_len()inarch_livepatch_apply()afterfunc->patch_offsethas been adjusted to account for ENDBR presence?
Oh, yes, I definitely need to.
Jan
Quoted 25 lines · Jan Beulich
Quoted 24 lines · Roger Pau Monné
Quoted 23 lines · Jan Beulich
While not triggered by the trivial
xen_nopin-tree patch on staging/master, that patch exposes a problem on the stable trees, where all functions have ENDBR inserted. When NOP-ing out a range, we need to account for this. Handle this right inlivepatch_insn_len().Fixes 6974c75180f1 ("xen/x86: Livepatch: support patching CET-enhanced functions")Signed-off-by Jan Beulich <[email protected]>---
Only build tested, as I don't have a live patching environment available.For Arm this assumes that the
patch_offsetfield starts out as zero; I think we can make such an assumption, yet otoh on x86 explicit initialization was added by the cited commit.xen/include/xen/livepatch.h +1
-1@@ -90,7 +90,7 @@ static inlineunsigned int livepatch_insn_len (const struct livepatch_func *func) {if ( !func->new_addr ) -return func->new_size; +return func->new_size - func->patch_offset;
Quoted 8 lines
Quoted 6 lines
xen/include/xen/livepatch.h static inline · line 96
Quoted 2 lines
xen/include/xen/livepatch.h +0
-0return ARCH_PATCH_INSN_SIZE ; }Don't you also need to move the call to
livepatch_insn_len()inarch_livepatch_apply()afterfunc->patch_offsethas been adjusted to account for ENDBR presence?Oh, yes, I definitely need to.
Actually - not quite. I need to call the function a 2nd time. And this then also points out that is_endbr64() and is_endbr64_poison() may overrun the range pointed to by old_ptr (which I'll take care of at the same time).
Jan