From d46fea98ef11d6ae701850acaec2d3bcda0972c0 Mon Sep 17 00:00:00 2001 From: Longjun Luo Date: Fri, 23 Sep 2022 18:16:20 +0800 Subject: [PATCH] kpatch-build: strengthen conditions for changed sections If two sections want to be the same, they need to satisfy two conditions: 1) the result of memcmp is zero, which means they have the same content. 2) they have the same relocation entries. In one specific situation, two sections have the same content. But one section has relocation entries while the other one has no relocation entries. For example, in X86, consider the following code: original code ``` __noreturn noinline int kpatch_func(void) { while(1) {}; } ``` patched code ``` __noreturn notrace noinline int kpatch_func(void) { asm(".byte 0xe8, 0x00, 0x00, 0x00, 0x00"); while(1){}; } ``` Since the original code has a fentry call, these two functions have the same compile result. But obviously, they are different functions. Currently, kpatch would not find their differences since the patched code has no relocation entries. For the situation that one section has relocation entries while the other one doesn't have, it should be set to be changed directly. Cooperated-by: Zongwu Li Signed-off-by: Longjun Luo --- kpatch-build/create-diff-object.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c index f43154b6d..360441111 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c @@ -579,7 +579,9 @@ static void kpatch_compare_correlated_section(struct section *sec) } if (sec1->sh.sh_size != sec2->sh.sh_size || - sec1->data->d_size != sec2->data->d_size) { + sec1->data->d_size != sec2->data->d_size || + (sec1->rela && !sec2->rela) || + (sec2->rela && !sec1->rela)) { sec->status = CHANGED; goto out; }