Re: [PATCH] arm64/module: Support for patching modules during runtime

From: Will Deacon
Date: Mon Aug 11 2025 - 08:05:20 EST


On Mon, Aug 11, 2025 at 09:01:43AM +0100, Marc Zyngier wrote:
> On Mon, 11 Aug 2025 08:37:32 +0100,
> fanqincui <fanqincui@xxxxxxx> wrote:
> >
> > Hi will,
> > Yes, you are right. The alternative callback function lives inside the module.
> > This callback function is actually similar to kvm_update_va_mask in KVM;
> >
> > The module's callback function calculates some values based on
> > the current CPU features and then performs the replacement.
> >
> > The .text.alternative_cb section is actually marked as SHF_EXECINSTR | SHF_ALLOC
> > during compilation, so intersections() includes this section and sets it as executable later.
>
> I'm worried there is a chicken-and-egg problem here. What if the
> callback itself requires patching via some other alternative? Is there
> a guarantee that this always performed in the correct order?

Maybe we should just reject loading modules that have alternative
callbacks that don't reside in the kernel text? I _think_ that should
cover all the in-tree users, although I didn't get a reply to my
question asking which module triggered this bug report.

Will