Skip to content

Conversation

@sumanthkorikkar
Copy link
Contributor

kpatch_check_relocations() validates relocation targets using sec->data->d_size, which doesnt reflect entire section size.

Sections such as __bug_table may be represented by multiple records. In this case, data->d_size is lesser than the logical section size, leading to false out-of-range relocation errors.

ERROR: kernel/fork.o: kpatch_check_relocations:
.text.kernel_clone+0x2f6: out-of-range relocation __bug_table+0x1b2
sec_off: 432 sec_size: 48

The correct size of the section is sec->sh.sh_size, total size of __bug_table (480 bytes, corresponding to 30 struct bug_entry records).

Fix this by using sec->sh.sh_size instead of sec->data->d_size when verifying relocation bounds.

Additionally, ensure that newly rebuilt .kpatch.strings sections update sh.sh_size after the string table is finalized. Without this update, kpatch may fail with:

ERROR: kernel/fork.o: kpatch_check_relocations:
.kpatch.funcs+0x28: out-of-range relocation .kpatch.strings+0x8
sec_off: 8 sec_size: 0

kpatch_check_relocations() validates relocation targets using
sec->data->d_size, which doesnt reflect entire section size.

Sections such as __bug_table may be represented by multiple records. In
this case, data->d_size is lesser than the logical section size, leading
to false out-of-range relocation errors.

ERROR: kernel/fork.o: kpatch_check_relocations:
.text.kernel_clone+0x2f6: out-of-range relocation __bug_table+0x1b2
sec_off: 432 sec_size: 48

The correct size of the section is sec->sh.sh_size, total size of
__bug_table (480 bytes, corresponding to 30 struct bug_entry records).

Fix this by using sec->sh.sh_size instead of sec->data->d_size when
verifying relocation bounds.

Additionally, ensure that newly rebuilt .kpatch.strings sections update
sh.sh_size after the string table is finalized. Without this update,
kpatch may fail with:

ERROR: kernel/fork.o: kpatch_check_relocations:
.kpatch.funcs+0x28: out-of-range relocation .kpatch.strings+0x8
sec_off: 8 sec_size: 0

Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant