From 79f45d1b0afd2ff0c3235be7cc32f934453e7acb Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf Date: Wed, 11 May 2022 14:34:44 -0700 Subject: [PATCH] create-diff-object: fix kpatch_replace_sections_syms() for non-text It doesn't make sense to disassemble a data section. That just happened to work by accident. PC-relative offsets only need adjusting when associated with an instruction. Signed-off-by: Josh Poimboeuf --- kpatch-build/create-diff-object.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c index afe1bf6..03c3321 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c @@ -1575,17 +1575,18 @@ static void kpatch_replace_sections_syms(struct kpatch_elf *kelf) add_off = 0; break; case X86_64: - if (rela->type == R_X86_64_PC32 || - rela->type == R_X86_64_PLT32) { + if (!is_text_section(relasec->base) || + rela->type == R_X86_64_64 || + rela->type == R_X86_64_32S) + add_off = 0; + else if (rela->type == R_X86_64_PC32 || + rela->type == R_X86_64_PLT32) { struct insn insn; rela_insn(relasec, rela, &insn); add_off = (unsigned int)((long)insn.next_byte - (long)relasec->base->data->d_buf - rela->offset); - } else if (rela->type == R_X86_64_64 || - rela->type == R_X86_64_32S) - add_off = 0; - else + } else continue; break; default: