Re: [PATCH v3] arm64: module: Use text-poke for late PLT/veneer emission
From: Catalin Marinas
Date: Wed Nov 25 2026 - 07:39:07 EST
On Tue, 17 Nov 2026 19:35:35 +0800, Rui Qi wrote:
> module_emit_plt_entry() and module_emit_veneer_for_adrp() write PLT
> entries into the .plt section by direct assignment. Once a module is
> fully formed its .plt is read-only/executable, so a late (livepatch)
> relocation that falls back to PLT emission -- an out-of-range
> R_AARCH64_CALL26/JUMP26, or an ADRP under CONFIG_ARM64_ERRATUM_843419
> -- triggers a synchronous Data Abort and panics.
>
> [...]
Applied to arm64 (for-next/fixes), thanks!
[1/1] arm64: module: Use text-poke for late PLT/veneer emission
https://git.kernel.org/arm64/c/a7e632493acf
I folded in a small fix which addresses Sashiko's comment: the bounds
check before the write must allow i == plt_max_entries since .plt has
plt_max_entries + 1 slots (the last one is where a duplicate of the
final entry is built before being discarded). I restored the
plt_num_entries check after the duplicate test as well.
I moved the module_write_place() prototype to asm/module.h, next
to the other PLT emitters. I concluded it's a better fit than
text-patching.h. My concern on v2 was the macro but now it's an
out-of-line function. I also dropped the const from the val argument,
which removes the (void *) cast when calling aarch64_insn_copy(). All
callers pass non-const locals anyway. It would be a good cleanup in the
future but that should also add const to aarch64_insn_copy().
Please check that I got these right.
Sashiko had some comments on v2 which we concluded are existing
problems, just exposed because we no longer take a fault. If you have
time for a livepatch reload follow-up (probably not cc stable), there
are two separate problems when the target module is unloaded and loaded
again:
- The livepatch module's .plt slots are reserved once but used again on
every klp_module_coming(), so a reload eventually hits the WARN and
the target module is rejected. This is safe but we need some slot
rewinding or a clear_relocate_add().
- With the A53 erratum 843419 workaround, if the first application
replaced an ADRP with a B to a veneer, reloc_insn_adrp() reads the
B back on reload as if it were an ADRP. It either encodes the ADR
immediate into the B or decodes Rd from the branch offset. This
corrupts the livepatch code silently on the first reload (unrelated to
how many slots are left). Not sure yet how to fix this, maybe the
original instruction needs restoring on unload (or saving).
Thanks.
--
Catalin