History

klp-build: Fix checksum comparison for changed offsets

The klp-build -f/--show-first-changed feature uses diff to compare checksum log lines between original and patched objects. However, diff compares entire lines, including the offset field. When a function is at a different section offset, the offset field differs even though the instruction checksum is identical, causing the wrong instruction to be printed. Only compare the checksum field when looking for the first changed instruction. Also print both the original and patched offsets when they differ.

Josh Poimboeuf committed 7 months ago

Commit ba77fe51 parent cc39ccc1 file · +23 −7Browse files

Showing the changes to scripts/livepatch (1 of 1 file). Show all

Unified · Split

scripts/livepatch/klp-build+23−7
@@ -727,13 +727,29 @@ diff_checksums() { · 726 unmodified lines
727727 )
728728
729729 for func in ${funcs[$file]}; do
730− diff <( grep0 -E "^DEBUG: .*checksum: $func " "$orig_log" | sed "s|$ORIG_DIR/||") \
731− <( grep0 -E "^DEBUG: .*checksum: $func " "$patched_log" | sed "s|$PATCHED_DIR/||") \
732− | gawk '/^< DEBUG: / {
733− gsub(/:/, "")
734− printf "%s: %s: %s\n", $3, $5, $6
735− exit
736− }' || true
730+ local -a orig patched
731+ paste <(grep0 -E "^DEBUG: .*checksum: $func " "$orig_log") \
732+ <(grep0 -E "^DEBUG: .*checksum: $func " "$patched_log") |
733+ while IFS= read -r line; do
734+ read -ra orig <<< "${line%%$'\t'*}"
735+ read -ra patched <<< "${line#*$'\t'}"
736+
737+ if [[ ${#patched[@]} -eq 0 ]]; then
738+ printf "%s: %s: %s (removed)\n" "${orig[1]%:}" "${orig[3]}" "${orig[-2]}"
739+ break
740+ elif [[ ${#orig[@]} -eq 0 ]]; then
741+ printf "%s: %s: %s (added)\n" "${patched[1]%:}" "${patched[3]}" "${patched[-2]}"
742+ break
743+ fi
744+
745+ [[ "${orig[-1]}" == "${patched[-1]}" ]] && continue
746+
747+ printf "%s: %s: %s" "${orig[1]%:}" "${orig[3]}" "${orig[-2]}"
748+ [[ "${orig[-2]}" != "${patched[-2]}" ]] && \
749+ printf " (patched: %s)" "${patched[-2]}"
750+ printf "\n"
751+ break
752+ done || true
737753 done
738754 done
739755 }