]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
objtool/klp: Fix position-dependent checksums for non-relocated jumps/calls
authorJosh Poimboeuf <jpoimboe@kernel.org>
Fri, 3 Apr 2026 18:57:02 +0000 (11:57 -0700)
committerJosh Poimboeuf <jpoimboe@kernel.org>
Tue, 5 May 2026 04:16:06 +0000 (21:16 -0700)
commitcca84cb12908f1cfcecaef80a7692017e2d6a945
treea64d268c6df137ea25d408c153f1d2be7755eb06
parent3ee67629b2b7fbe270f6c21d9a95219bbd214630
objtool/klp: Fix position-dependent checksums for non-relocated jumps/calls

When computing klp checksums, instructions with non-relocated jump/call
destination offsets are problematic because the offset values can change
when surrounding code has moved, causing the function to be incorrectly
marked as changed.

Specifically, that includes jumps from alternatives to the end of the
alternative, which from objtool's perspective are jumps to the end of
the alternative instruction block in the original function.

Note that 'jump_dest' jumps don't include sibling calls (those use
call_dest), nor do they include jumps to/from .cold sub functions (those
are cross-section and need a reloc).

Fix it by hashing the opcode bytes (excluding the immediate operand)
along with a position-independent representation of the destination.
For calls, use the function name, and for jumps, use the destination's
offset within its function.

[Note the "9 bit hole" comment was wrong: it has been 8 bits since
commit 70589843b36f ("objtool: Add option to trace function validation")
added the 'trace' field.  Adding the 4-bit 'immediate_len' field now
leaves a 4-bit hole.]

Fixes: 0d83da43b1e1 ("objtool/klp: Add --checksum option to generate per-function checksums")
Acked-by: Song Liu <song@kernel.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
tools/objtool/arch/x86/decode.c
tools/objtool/include/objtool/arch.h
tools/objtool/include/objtool/check.h
tools/objtool/klp-checksum.c