[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v3 6/9] livepatch: Add parsing for the symbol+0x<offset>/<len>
in case we want to patch at specific offsets inside a function. (for example if we want to do NOP patching). We also assume that the 'len' is only the size of an isns that would be for a call opcode (so 5 bytes on x86, and 4 on ARM 32/64). Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx> --- Cc: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx> Cc: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx> Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx> Cc: Julien Grall <julien.grall@xxxxxxx> Cc: Jan Beulich <jbeulich@xxxxxxxx> Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> v3: First submission --- docs/misc/livepatch.markdown | 2 +- xen/arch/arm/livepatch.c | 8 ++++++++ xen/arch/x86/livepatch.c | 5 +++++ xen/common/livepatch.c | 43 +++++++++++++++++++++++++++++++++++++++++-- xen/include/xen/livepatch.h | 1 + 5 files changed, 56 insertions(+), 3 deletions(-) diff --git a/docs/misc/livepatch.markdown b/docs/misc/livepatch.markdown index 89c1050..f1a5147 100644 --- a/docs/misc/livepatch.markdown +++ b/docs/misc/livepatch.markdown @@ -312,7 +312,7 @@ The size of the structure is 64 bytes on 64-bit hypervisors. It will be * `name` is the symbol name of the old function. Only used if `old_addr` is zero, otherwise will be used during dynamic linking (when hypervisor loads - the payload). + the payload). The format can be _symbol_ or _symbol+0x<offset>/<len>_. * `old_addr` is the address of the function to be patched and is filled in at payload generation time if hypervisor function address is known. If unknown, diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c index aba1320..3093554 100644 --- a/xen/arch/arm/livepatch.c +++ b/xen/arch/arm/livepatch.c @@ -7,6 +7,14 @@ #include <xen/livepatch_elf.h> #include <xen/livepatch.h> +/* On ARM32,64 instructions are always 4 bytes long. */ +#define PATCH_INSN_SIZE 4 + +int arch_verify_insn_length(unsigned long len) +{ + return len != PATCH_INSN_SIZE; +} + void arch_livepatch_quiesce(void) { } diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c index 1023fab..df64b00 100644 --- a/xen/arch/x86/livepatch.c +++ b/xen/arch/x86/livepatch.c @@ -27,6 +27,11 @@ void arch_livepatch_revive(void) write_cr0(read_cr0() | X86_CR0_WP); } +int arch_verify_insn_length(unsigned long len) +{ + return len != PATCH_INSN_SIZE; +} + int arch_livepatch_verify_func(const struct livepatch_func *func) { /* No NOP patching yet. */ diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index cbfeac1..e752949 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -234,14 +234,46 @@ static const char *livepatch_symbols_lookup(unsigned long addr, static int lookup_symbol(struct livepatch_func *f, struct livepatch_elf *elf) { + const char *s; + char *plus = NULL, *slash = NULL; + unsigned long offset = 0; + if ( f->old_addr ) return 0; + s = f->name; + /* +<offset>/<len> */ + plus = strchr(f->name, '+'); + if ( plus ) + { + slash = strchr(plus, '/'); + + if ( slash ) + { + const char *endp = NULL; + unsigned int len; + + offset = simple_strtoul(plus+1, &endp, 16); + + if ( endp != slash ) + return -EINVAL; + + len = simple_strtoul(slash+1, NULL, 16); + + if ( arch_verify_insn_length(len) ) + return -EINVAL; + + /* So that symbol lookup works. */ + *plus = '\0'; + s = f->name; + } + } + /* Lookup function's old address if not already resolved. */ - f->old_addr = (void *)symbols_lookup_by_name(f->name); + f->old_addr = (void *)symbols_lookup_by_name(s); if ( !f->old_addr ) { - f->old_addr = (void *)livepatch_symbols_lookup_by_name(f->name); + f->old_addr = (void *)livepatch_symbols_lookup_by_name(s); if ( !f->old_addr ) { dprintk(XENLOG_ERR, LIVEPATCH "%s: Could not resolve old address of %s\n", @@ -249,6 +281,13 @@ static int lookup_symbol(struct livepatch_func *f, struct livepatch_elf *elf) return -ENOENT; } } + + if ( plus && slash ) + { + *plus = '+'; + f->old_addr += offset; + } + dprintk(XENLOG_DEBUG, LIVEPATCH "%s: Resolved old address %s => %p\n", elf->name, f->name, f->old_addr); diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h index 02f4572..2e64686 100644 --- a/xen/include/xen/livepatch.h +++ b/xen/include/xen/livepatch.h @@ -44,6 +44,7 @@ unsigned long livepatch_symbols_lookup_by_name(const char *symname); bool_t is_patch(const void *addr); /* Arch hooks. */ +int arch_verify_insn_length(unsigned long len); int arch_livepatch_verify_elf(const struct livepatch_elf *elf); int arch_livepatch_perform_rel(struct livepatch_elf *elf, const struct livepatch_elf_sec *base, -- 2.4.11 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |