BPF List
 help / color / mirror / Atom feed
* objtool/klp: ___bpf_prog_run jumptable is correlated to the original, fix never runs
@ 2026-11-28  6:51 Seke Kazuru
  2026-11-30 20:51 ` Joe Lawrence
  0 siblings, 1 reply; 2+ messages in thread
From: Seke Kazuru @ 2026-11-28  6:51 UTC (permalink / raw)
  To: live-patching
  Cc: jpoimboe, mbenes, pmladek@suse.com, joe.lawrence@redhat.com,
	song@kernel.org, peterz, bpf

Hello,

A livepatch module built by klp-build for a fix to ___bpf_prog_run()
loads, reports "patching complete", and lists ___bpf_prog_run as
patched, but the fixed instruction handlers never run. The replaced
function dispatches through vmlinux's copy of its static jumptable,
whose entries point into the original function body.

Setup: Linux 6.19, x86_64, gcc 13, a config without BPF JIT (so every
program runs in the interpreter), klp-build from the same tree:

  ./scripts/livepatch/klp-build -T --no-replace -o lp.ko fix.patch

The fix is c77b30bd1dcb ("bpf: Fix undefined behavior in interpreter
sdiv/smod for INT_MIN"), which changes the signed DIV and MOD handlers
inside ___bpf_prog_run(). Those handlers are reached only through the
computed-goto table:

  static const void * const jumptable[256] = { ... &&label ... };

klp diff refers every static local of a changed function to the
original kernel's copy unless is_uncorrelated_static_local() exempts its
name. "jumptable" is not on that list (6.19, and still not in
7.4-rc4). The module's ___bpf_prog_run therefore carries a relocation
to .klp.sym.vmlinux.jumptable.12 (R_X86_64_32S at +0x40), and every
dispatch lands in the original handlers.

Test, under KVM: a small helper module runs a three-instruction
program through the interpreter (r0 = S32_MIN; r0 s/= 2 as ALU32 DIV K
with off 1; exit) and prints r0. Unfixed code returns 0x40000000,
fixed code 0xc0000000.

  boot 1, klp-build module as built:
    before load:              0x40000000 (6 of 6 runs)
    after load, enabled=1, transition=0, "patching complete",
    /sys/kernel/livepatch/<mod>/vmlinux/___bpf_prog_run,1 present:
                              0x40000000 (6 of 6 runs)

  boot 2, same command and same fix, with "jumptable." added to the
  list in is_uncorrelated_static_local():
    before load:              0x40000000 (6 of 6)
    after load:               0xc0000000 (6 of 6)

The build prints no warning, and every kernel signal reports success.
Any klp-build fix to ___bpf_prog_run has this effect on kernels that run
the interpreter, that is without CONFIG_BPF_JIT_ALWAYS_ON when the JIT
is off or unavailable.

Two possible fixes:

1. Add "jumptable" to is_uncorrelated_static_local(). This is the change
   tested in boot 2. It covers this function only.

2. More generally, do not correlate a static local whose relocations
   point into the changed function's own text (label addresses). Such a
   table describes the code, not shared state, so it has to follow the
   new function. This would also cover any other computed-goto table.

I can send the helper module, the program, the kernel config and the
two klp-build logs. I am glad to test a patch on the same setup.

This came up in a study of live-patch module fidelity. Of 70 klp-build
modules built from real stable fixes on 6.19, this is the only one in
which a changed function's new code does not run.

Thank you for your time.

Regards,
Seke Kazuru
Independent researcher

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-30 20:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28  6:51 objtool/klp: ___bpf_prog_run jumptable is correlated to the original, fix never runs Seke Kazuru
2026-11-30 20:51 ` Joe Lawrence

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox