freenode
Kernel & Low-Level

Kernel module loader left arch code open to bad relocation indexes

Malformed modules could crash ARM, ARM64, LoongArch, PA-RISC, and RISC-V before common validation ran.

A proposed Linux kernel fix closes a gap in module loading that let crafted ELF modules crash several architectures by pointing relocation sections at out-of-range targets.

The common loader already skips relocation work when a section’s target index falls outside the section table. On ARM, ARM64, LoongArch, PA-RISC, and RISC-V, architecture setup runs earlier and still trusts that index. The result is an out-of-bounds section-header read on most of those platforms, or an out-of-bounds access into a heap array on PA-RISC. Karl Mehltretter reproduced page-fault oopses under QEMU on ARM, ARM64, LoongArch, and RISC-V, and a Data TLB miss on PA-RISC.

The patch validates relocation target indexes during ELF section-header checks and rejects the module with ENOEXEC before any architecture code can use a bad index. Mehltretter found the ARM case with a Frama-C static analysis harness and confirmed the other arches with before-and-after load tests; fixed kernels refused the same malformed modules while still accepting good ones. The change is aimed at stable kernels as well, tying back to older module PLT and large-module work on those platforms.

Without the early check, loading an untrusted or corrupted module on the affected architectures could panic the machine rather than fail cleanly.