create-diff-object: Fix out of range relocation verification check #1493
+2
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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