public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: Siddharth Nayyar <sidnayyar@google.com>
To: petr.pavlu@suse.com
Cc: arnd@arndb.de, linux-arch@vger.kernel.org,
	linux-kbuild@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-modules@vger.kernel.org,  mcgrof@kernel.org,
	nathan@kernel.org, nicolas.schier@linux.dev,
	 samitolvanen@google.com, sidnayyar@google.com,
	maennich@google.com,  gprocida@google.com
Subject: [PATCH v2 10/10] module loader: enforce symbol import protection
Date: Mon, 13 Oct 2025 15:39:18 +0000	[thread overview]
Message-ID: <20251013153918.2206045-11-sidnayyar@google.com> (raw)
In-Reply-To: <20251013153918.2206045-1-sidnayyar@google.com>

The module loader will reject unsigned modules from loading if such a
module attempts to import a symbol which has the import protection bit
set in the kflagstab entry for the symbol.

Signed-off-by: Siddharth Nayyar <sidnayyar@google.com>
Reviewed-by: Petr Pavlu <petr.pavlu@suse.com>
---
 kernel/module/internal.h |  1 +
 kernel/module/main.c     | 10 +++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/kernel/module/internal.h b/kernel/module/internal.h
index 061161cc79d9..98faaf8900aa 100644
--- a/kernel/module/internal.h
+++ b/kernel/module/internal.h
@@ -108,6 +108,7 @@ struct find_symbol_arg {
 	const u32 *crc;
 	const struct kernel_symbol *sym;
 	enum mod_license license;
+	bool is_protected;
 };
 
 /* modules using other modules */
diff --git a/kernel/module/main.c b/kernel/module/main.c
index f5f9872dc070..c27df62a68f5 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -380,6 +380,7 @@ static bool find_exported_symbol_in_section(const struct symsearch *syms,
 	fsa->crc = symversion(syms->crcs, sym - syms->start);
 	fsa->sym = sym;
 	fsa->license = (sym_flags & KSYM_FLAG_GPL_ONLY) ? GPL_ONLY : NOT_GPL_ONLY;
+	fsa->is_protected = sym_flags & KSYM_FLAG_PROTECTED;
 
 	return true;
 }
@@ -1267,6 +1268,13 @@ static const struct kernel_symbol *resolve_symbol(struct module *mod,
 		goto getname;
 	}
 
+	if (fsa.is_protected && !mod->sig_ok) {
+		pr_warn("%s: Cannot use protected symbol %s\n",
+			mod->name, name);
+		fsa.sym = ERR_PTR(-EACCES);
+		goto getname;
+	}
+
 	err = ref_module(mod, fsa.owner);
 	if (err) {
 		fsa.sym = ERR_PTR(err);
@@ -1550,7 +1558,7 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
 				break;
 
 			ret = PTR_ERR(ksym) ?: -ENOENT;
-			pr_warn("%s: Unknown symbol %s (err %d)\n",
+			pr_warn("%s: Unresolved symbol %s (err %d)\n",
 				mod->name, name, ret);
 			break;
 
-- 
2.51.0.740.g6adb054d12-goog


  parent reply	other threads:[~2025-10-13 15:39 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-13 15:39 [PATCH v2 00/10] scalable symbol flags with __kflagstab Siddharth Nayyar
2025-10-13 15:39 ` [PATCH v2 01/10] define kernel symbol flags Siddharth Nayyar
2025-10-13 15:39 ` [PATCH v2 02/10] linker: add kflagstab section to vmlinux and modules Siddharth Nayyar
2025-10-13 15:39 ` [PATCH v2 03/10] modpost: create entries for kflagstab Siddharth Nayyar
2025-10-13 15:39 ` [PATCH v2 04/10] module loader: use kflagstab instead of *_gpl sections Siddharth Nayyar
2025-10-13 15:39 ` [PATCH v2 05/10] modpost: put all exported symbols in ksymtab section Siddharth Nayyar
2025-10-13 15:39 ` [PATCH v2 06/10] module loader: remove references of *_gpl sections Siddharth Nayyar
2025-10-13 15:39 ` [PATCH v2 07/10] linker: remove *_gpl sections from vmlinux and modules Siddharth Nayyar
2025-10-13 15:39 ` [PATCH v2 08/10] remove references to *_gpl sections in documentation Siddharth Nayyar
2025-10-13 15:39 ` [PATCH v2 09/10] modpost: add symbol import protection flag to kflagstab Siddharth Nayyar
2025-10-13 15:39 ` Siddharth Nayyar [this message]
2025-10-14  7:34   ` [PATCH v2 10/10] module loader: enforce symbol import protection kernel test robot
2025-10-20 23:00     ` Siddharth Nayyar
2025-10-23  2:36   ` kernel test robot
2025-10-23  9:58   ` kernel test robot
2025-10-13 19:02 ` [PATCH v2 00/10] scalable symbol flags with __kflagstab Jonathan Corbet
2025-10-20 22:43   ` Siddharth Nayyar
2025-10-21  8:35     ` Petr Pavlu

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=20251013153918.2206045-11-sidnayyar@google.com \
    --to=sidnayyar@google.com \
    --cc=arnd@arndb.de \
    --cc=gprocida@google.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=maennich@google.com \
    --cc=mcgrof@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nicolas.schier@linux.dev \
    --cc=petr.pavlu@suse.com \
    --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