Re: [PATCH v2 36/58] objtool/klp: Add test for position-independent checksums
From: Song Liu <song@kernel.org>
Date: 2026-09-14 21:42:55
Also in:
sashiko-reviews
On Sun, Sep 13, 2026 at 11:46 PM [off-list ref] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The test script incorrectly assumes that if target() moves relative to the section start, its relative displacement to callee() must have changed. This allows the test to falsely pass if the compiler shifts both functions by the same amount. -- commit 3328da26fa650b64515b357106fb0c92f158e5b7 Author: Song Liu [off-list ref] objtool/klp: Add test for position-independent checksums A function that only moves has not changed, and its checksum must not move with it. This commit adds a test to verify position-independent checksums for non-relocated jumps/calls.quoted
diff --git a/tools/objtool/tests/generic/test-checksum-position.sh b/tools/objtool/tests/generic/test-checksum-position.sh new file mode 100755 index 0000000000000..459a718d75e7e --- /dev/null +++ b/tools/objtool/tests/generic/test-checksum-position.sh[ ... ]quoted
+orig_off="$(in_symbols orig.o | awk '$8 == "target" { print $2 }')" +new_off="$( in_symbols patched.o | awk '$8 == "target" { print $2 }')" +[ -n "$orig_off" ] && [ -n "$new_off" ] || + fail "target symbol not found in both objects" +[ "$orig_off" != "$new_off" ] || + probe_skip "compiler did not move target() between builds"[Severity: Medium] Does this check guarantee the relative displacement between target() and callee() actually changed? Since the test is built with -O2 (which enables -ftoplevel-reorder) and -fno-function-sections, the compiler could group globals and statics, emitting padding() before both target() and callee(). In this case, target() and callee() would both shift by the exact size of padding(). The script checks if target() moved relative to the section start: [ "$orig_off" != "$new_off" ] This would evaluate to true since target() did move, allowing the test to proceed. However, because the relative displacement between target() and callee() is unchanged, the encoded call displacement bytes within target() will be identical in both builds. The checksum will trivially match without exercising objtool's displacement-masking logic.
This is a real issue. I'm trying to fix this by enforcing some alignment for patched version. Thanks, Song