Re: [PATCH] module: Clarify purpose and description of elf_validity_cache_copy()
From: Aaron Tomlin
Date: Sat Nov 21 2026 - 14:07:23 EST
On Thu, Nov 19, 2026 at 05:25:27PM +0100, Petr Pavlu wrote:
> With the advent of LLM agents, a number of recent patches and bug reports
> for the module loader focus on its validation of module ELF metadata.
> However, many of them are misguided.
>
> Loading a module is a privileged operation. The ELF metadata can normally
> be trusted, just as the module code itself is expected to be correct. The
> checks in elf_validity_cache_copy() are intended to catch accidental
> corruption and basic violations of the ELF format, rather than to provide
> exhaustive validation. The only requirement is that enough of the ELF data
> is validated for the module loader to safely reach the blacklist check
> without crashing on a corrupted module file. This allows a broken module to
> be blacklisted and prevented from loading.
>
> Clarify the purpose of elf_validity_cache_copy() and otherwise clean up its
> description. Hopefully, LLM agents will take this into account and the
> number of validation-related reports will decrease.
>
> Signed-off-by: Petr Pavlu <petr.pavlu@xxxxxxxx>
> ---
> kernel/module/main.c | 37 +++++++++++++++++++++++--------------
> 1 file changed, 23 insertions(+), 14 deletions(-)
>
> diff --git a/kernel/module/main.c b/kernel/module/main.c
> index 34e0204ea37c..0c204f07ca68 100644
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -2421,24 +2421,33 @@ static int elf_validity_cache_strtab(struct load_info *info)
> }
>
> /*
> - * Check userspace passed ELF module against our expectations, and cache
> - * useful variables for further processing as we go.
> + * Check the ELF module passed in from userspace against our expectations, and
> + * cache useful variables for further processing as we go.
> *
> - * This does basic validity checks against section offsets and sizes, the
> - * section name string table, and the indices used for it (sh_name).
> + * Loading a module is a privileged operation. The ELF metadata can normally be
> + * trusted, just as the module code itself is expected to be correct. These
> + * checks are intended to catch accidental corruption and basic violations of
> + * the ELF format, rather than to provide exhaustive validation. The only
> + * requirement is that enough of the ELF data is validated for the module loader
> + * to safely reach the blacklist check without crashing on a corrupted module
> + * file. This allows a broken module to be blacklisted and prevented from
> + * loading.
> *
> - * As a last step, since we're already checking the ELF sections we cache
> - * useful variables which will be used later for our convenience:
> + * The checks cover the ELF header, section offsets and sizes, section-name and
> + * symbol string tables, offsets into those tables, and selected
> + * section-specific constraints.
> *
> - * o pointers to section headers
> - * o cache the modinfo symbol section
> - * o cache the string symbol section
> - * o cache the module section
> + * While validating, cache the following for later use:
> *
> - * As a last step we set info->mod to the temporary copy of the module in
> - * info->hdr. The final one will be allocated in move_module(). Any
> - * modifications we make to our copy of the module will be carried over
> - * to the final minted module.
> + * * pointers to the section headers and section-name string table
> + * * indices of relevant sections, including .modinfo, the symbol table, the
> + * symbol string table, the module section, and version sections
> + * * a pointer to the symbol string table
> + *
> + * Finally, set info->mod to point to the temporary module struct within
> + * info->hdr. The final copy of the module struct will be allocated in
> + * move_module(). Any modifications to the temporary copy will be carried over
> + * to the final one.
> */
> static int elf_validity_cache_copy(struct load_info *info, int flags)
> {
>
> ---
> base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
> change-id: 20261119-module-elf-validation-a5a0e28e6dcb
Thank you.
Reviewed-by: Aaron Tomlin <atomlin@xxxxxxxxxxx>
--
Aaron Tomlin