Skip to content

Commit d46fea9

Browse files
committed
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 <[email protected]> Signed-off-by: Longjun Luo <[email protected]>
1 parent 80fc15a commit d46fea9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kpatch-build/create-diff-object.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ static void kpatch_compare_correlated_section(struct section *sec)
579579
}
580580

581581
if (sec1->sh.sh_size != sec2->sh.sh_size ||
582-
sec1->data->d_size != sec2->data->d_size) {
582+
sec1->data->d_size != sec2->data->d_size ||
583+
(sec1->rela && !sec2->rela) ||
584+
(sec2->rela && !sec1->rela)) {
583585
sec->status = CHANGED;
584586
goto out;
585587
}

0 commit comments

Comments
 (0)