[PATCH v3 6/9] module: switch to execmem API for remapping as RW and restoring ROX
Petr Pavlu
petr.pavlu at suse.com
Tue Jan 28 02:31:36 PST 2025
On 1/28/25 11:00, Mike Rapoport wrote:
> On Mon, Jan 27, 2025 at 01:50:31PM +0100, Petr Pavlu wrote:
>> On 1/26/25 08:47, Mike Rapoport wrote:
>>> From: "Mike Rapoport (Microsoft)" <rppt at kernel.org>
>>>
>>> Instead of using writable copy for module text sections, temporarily remap
>>> the memory allocated from execmem's ROX cache as writable and restore its
>>> ROX permissions after the module is formed.
>>>
>>> This will allow removing nasty games with writable copy in alternatives
>>> patching on x86.
>>>
>>> Signed-off-by: Mike Rapoport (Microsoft) <rppt at kernel.org>
>>
>> [...]
>>
>>> +static void module_memory_restore_rox(struct module *mod)
>>> +{
>>> + for_class_mod_mem_type(type, text) {
>>> + struct module_memory *mem = &mod->mem[type];
>>> +
>>> + if (mem->is_rox)
>>> + execmem_restore_rox(mem->base, mem->size);
>>> + }
>>> +}
>>> +
>>
>> Can the execmem_restore_rox() call here fail? I realize that there isn't
>> much that the module loader can do if that happens, but should it be
>> perhaps logged as a warning?
>
> It won't fail at this point. set_memory APIs may fail if they need to split
> a large page and could not allocate a new page table, but here all the
> splits were already done at module_memory_alloc() time.
Ok, thanks for the explanation.
Acked-by: Petr Pavlu <petr.pavlu at suse.com>
-- Petr
More information about the linux-um
mailing list