Commit b0f93df
committed
create-diff-object: Remove undefined function symbols
When building shadow-pid.patch on a debug kernel, it generates
__bug_table, which contains an array of struct bug_entries.
.rela__bug_table contains references to bug address, line number and
column.
create-diff-object identifies that .text.kernel_clone has changed and it
includes .rela.text.kernel_clone rela section. Then later, it includes
all symbols (in kpatch_include_symbols()) associated with it, which ends
up including __bug_table and its rela section .rela__bug_table. Then,
all the function symbols associated with .rela__bug_table is included
irrespective of whether it's section is included or not.
This leads to the following modpost errors:
kernel/fork.o: changed function: kernel_clone
kernel/exit.o: changed function: do_exit
fs/proc/array.o: changed function: proc_pid_status
make -C /root/linux M=/root/.kpatch/tmp/patch CFLAGS_MODULE=''
make[1]: Entering directory '/root/linux'
make[2]: Entering directory '/root/.kpatch/tmp/patch'
LDS kpatch.lds
CC [M] patch-hook.o
LD [M] test-shadow-newpid.o
MODPOST Module.symvers
WARNING: modpost: missing MODULE_DESCRIPTION() in test-shadow-newpid.o
ERROR: modpost: "replace_mm_exe_file" [test-shadow-newpid.ko] undefined!
ERROR: modpost: "put_task_stack" [test-shadow-newpid.ko] undefined!
ERROR: modpost: "release_task" [test-shadow-newpid.ko] undefined!
ERROR: modpost: "set_mm_exe_file" [test-shadow-newpid.ko] undefined!
Examining the /root/.kpatch/patch/ directory reveals, these symbols are
never referenced in any relas.
readelf -Ws output.o |
grep -E 'put_task_stack|replace_mm_exe_file|release_task|set_mm_exe_file'
27: 0000000000000000 0 SECTION LOCAL DEFAULT 36 .rodata.release_task.str1.2
45: 0000000000000000 0 SECTION LOCAL DEFAULT 55 .rodata.set_mm_exe_file.str1.2
47: 0000000000000000 0 SECTION LOCAL DEFAULT 57 .rodata.replace_mm_exe_file.str1.2
234: 0000000000000000 0 FUNC GLOBAL DEFAULT UND replace_mm_exe_file
254: 0000000000000000 0 FUNC GLOBAL DEFAULT UND put_task_stack
263: 0000000000000000 0 FUNC GLOBAL DEFAULT UND release_task
269: 0000000000000000 0 FUNC GLOBAL DEFAULT UND set_mm_exe_file
readelf -Wr output.o |
grep -E 'put_task_stack|replace_mm_exe_file|release_task|set_mm_exe_file'
<EMPTY>
Hence, exclude these unreferenced symbols to avoid modpost errors.
Fix:
* Identify all function symbols present in __bug_table and track their
symbol indices.
* Exclude .rela__bug_table and .rela__mcount_loc, and for all other
relocation sections, check whether any of these symbol indices are
actually referenced.
* If a symbol index is never referenced in any relevant relocation
section and the symbol’s section is not included in the patch, exclude
the symbol from being added.
Note: Skipped need_klp_reloc()/kpatch_create_intermediate_sections()
check for .rela__bug_table section.
Reason: The function symbols that were not referenced by any sections
other than .rela__bug_table were being initialized with include = 0 (via
rela->sym->include = 0). As a result, kpatch_migrate_included_elements()
did not migrate these function symbols into kelf_out. However, later in
kpatch_create_intermediate_sections(), when parsing the .rela__bug_table
relasec and evaluating each symbol in need_klp_reloc(), the
code ended up using the previous rela->sym reference (which had already
been torn down). Since that symbol had its include field set to 0, the
dereference led to a segmentation fault. To prevent this, the
.rela__bug_table section is excluded from consideration in
kpatch_migrate_included_elements(). Additionally, if a function is
modified, the assumption is that, it will be referenced by other
relasec.
Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>1 parent 7552b46 commit b0f93df
1 file changed
Lines changed: 66 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2462 | 2462 | | |
2463 | 2463 | | |
2464 | 2464 | | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
| 2475 | + | |
| 2476 | + | |
| 2477 | + | |
| 2478 | + | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
| 2482 | + | |
| 2483 | + | |
| 2484 | + | |
| 2485 | + | |
| 2486 | + | |
| 2487 | + | |
| 2488 | + | |
| 2489 | + | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
| 2493 | + | |
| 2494 | + | |
| 2495 | + | |
| 2496 | + | |
| 2497 | + | |
| 2498 | + | |
| 2499 | + | |
| 2500 | + | |
| 2501 | + | |
| 2502 | + | |
| 2503 | + | |
| 2504 | + | |
| 2505 | + | |
| 2506 | + | |
| 2507 | + | |
| 2508 | + | |
| 2509 | + | |
| 2510 | + | |
| 2511 | + | |
| 2512 | + | |
| 2513 | + | |
| 2514 | + | |
| 2515 | + | |
| 2516 | + | |
| 2517 | + | |
| 2518 | + | |
| 2519 | + | |
| 2520 | + | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
2465 | 2528 | | |
2466 | 2529 | | |
2467 | 2530 | | |
| |||
3684 | 3747 | | |
3685 | 3748 | | |
3686 | 3749 | | |
3687 | | - | |
| 3750 | + | |
| 3751 | + | |
3688 | 3752 | | |
3689 | 3753 | | |
3690 | | - | |
3691 | 3754 | | |
3692 | 3755 | | |
3693 | 3756 | | |
| |||
4499 | 4562 | | |
4500 | 4563 | | |
4501 | 4564 | | |
| 4565 | + | |
4502 | 4566 | | |
4503 | 4567 | | |
4504 | 4568 | | |
| |||
0 commit comments