Skip to content

Commit

Permalink
kpatch-build: strengthen conditions for changed sections
Browse files Browse the repository at this point in the history
If two sections want to be the same, they need to satisfy
two conditions:

1) the result of memcmp is zero, which means they
the have 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 <lizongwu@huawei.com>
Signed-off-by: Longjun Luo <luolongjuna@gmail.com>
  • Loading branch information
anatasluo committed Sep 23, 2022
1 parent 850a998 commit ae6dd80
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kpatch-build/create-diff-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit ae6dd80

Please sign in to comment.