History

objtool/klp: Fix symbol resolution for duplicate data symbols

find_sympos() calculates a sympos used by livepatch to disambiguate duplicately-named symbols. For function symbols, there's a hack which counts .text.unlikely symbols before other .text symbols, matching the linker script's section ordering. Not only is the hack fragile, data symbols can have the same problem. So for example, adding a reference to pwq_cache in ep_unregister_pollwait() can trigger a corrupt sympos and a relocation to the wrong pwq_cache symbol in the livepatch module, resulting in a crash or undefined behavior. Remove the existing hack in favor of a fully deterministic solution, using the new .klp.symid table to derive the symbol-to-id mapping from the original vmlinux.o and the id-to-address mapping from the corresponding vmlinux, which can then be used to determine the exact sympos associated with the original vmlinux. Modules don't need any special treatment: the .ko has the same section/symbol ordering as the original whole-archive symbol table.

Josh Poimboeuf committed 3 months ago

Commit 15fa2031 parent 029223d5 files · +427 −62Browse files

Showing the changes to scripts (1 of 5 files). Show all

Unified · Split

scripts/livepatch/klp-build+4−0
@@ -611,6 +611,8 @@ copy_orig_objects() { · 610 unmodified lines
611 done611 done
612 xtrace_restore612 xtrace_restore
613 613
614 cp -f "$PWD/vmlinux" "$ORIG_DIR" || die "missing vmlinux"
615
614 mv -f "$TMP_DIR/build.log" "$ORIG_DIR"616 mv -f "$TMP_DIR/build.log" "$ORIG_DIR"
615 touch "$TIMESTAMP"617 touch "$TIMESTAMP"
616 touch "$ORIG_DIR/.complete"618 touch "$ORIG_DIR/.complete"
@@ -681,6 +683,8 @@ generate_checksums() { · 64 unmodified lines
681 "$OBJTOOL" klp checksum "$dest"683 "$OBJTOOL" klp checksum "$dest"
682 done684 done
683 685
686 [[ -f "$src_dir/vmlinux" ]] && cp -f "$src_dir/vmlinux" "$dest_dir"
687
684 touch "$dest_dir/.complete"688 touch "$dest_dir/.complete"
685}689}
686 690