From: Petr Pavlu <petr.pavlu@suse.com>
To: Luis Chamberlain <mcgrof@kernel.org>,
Petr Pavlu <petr.pavlu@suse.com>,
Daniel Gomez <da.gomez@kernel.org>,
Sami Tolvanen <samitolvanen@google.com>
Cc: Aaron Tomlin <atomlin@atomlin.com>,
linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] module: Clarify purpose and description of elf_validity_cache_copy()
Date: Thu, 19 Nov 2026 17:25:27 +0100 [thread overview]
Message-ID: <20261119-module-elf-validation-v1-1-69a74a84552c@suse.com> (raw)
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@suse.com>
---
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
reply other threads:[~2026-11-19 16:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119-module-elf-validation-v1-1-69a74a84552c@suse.com \
--to=petr.pavlu@suse.com \
--cc=atomlin@atomlin.com \
--cc=da.gomez@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=samitolvanen@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®