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 09/10] modpost: add symbol import protection flag to kflagstab
Date: Mon, 13 Oct 2025 15:39:17 +0000	[thread overview]
Message-ID: <20251013153918.2206045-10-sidnayyar@google.com> (raw)
In-Reply-To: <20251013153918.2206045-1-sidnayyar@google.com>

When the unused exports whitelist is provided, the symbol protection bit
is set for symbols not present in the unused exports whitelist.

The flag will be used in the following commit to prevent unsigned
modules from the using symbols other than those explicitly declared by
the such modules ahead of time.

Signed-off-by: Siddharth Nayyar <sidnayyar@google.com>
Reviewed-by: Petr Pavlu <petr.pavlu@suse.com>
---
 include/linux/module_symbol.h |  1 +
 scripts/mod/modpost.c         | 13 +++++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/include/linux/module_symbol.h b/include/linux/module_symbol.h
index 574609aced99..1d0414da4c7c 100644
--- a/include/linux/module_symbol.h
+++ b/include/linux/module_symbol.h
@@ -5,6 +5,7 @@
 /* Kernel symbol flags bitset. */
 enum ksym_flags {
 	KSYM_FLAG_GPL_ONLY	= 1 << 0,
+	KSYM_FLAG_PROTECTED	= 1 << 1,
 };
 
 /* This ignores the intensely annoying "mapping symbols" found in ELF files. */
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 8936db84779b..8d360bab50d6 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -61,6 +61,9 @@ static bool extra_warn;
 bool target_is_big_endian;
 bool host_is_big_endian;
 
+/* Are symbols protected against being used by unsigned modules? */
+static bool default_symbol_protected_status;
+
 /*
  * Cut off the warnings when there are too many. This typically occurs when
  * vmlinux is missing. ('make modules' without building vmlinux.)
@@ -225,6 +228,7 @@ struct symbol {
 	bool is_func;
 	bool is_gpl_only;	/* exported by EXPORT_SYMBOL_GPL */
 	bool used;		/* there exists a user of this symbol */
+	bool protected;		/* this symbol cannot be used by unsigned modules */
 	char name[];
 };
 
@@ -246,7 +250,8 @@ static struct symbol *alloc_symbol(const char *name)
 
 static uint8_t get_symbol_flags(const struct symbol *sym)
 {
-	return sym->is_gpl_only ? KSYM_FLAG_GPL_ONLY : 0;
+	return (sym->is_gpl_only ? KSYM_FLAG_GPL_ONLY : 0) |
+		(sym->protected ? KSYM_FLAG_PROTECTED : 0);
 }
 
 /* For the hash of exported symbols */
@@ -370,6 +375,7 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod,
 	s->namespace = xstrdup(namespace);
 	list_add_tail(&s->list, &mod->exported_symbols);
 	hash_add_symbol(s);
+	s->protected = default_symbol_protected_status;
 
 	return s;
 }
@@ -1785,8 +1791,10 @@ static void handle_white_list_exports(const char *white_list)
 	while ((name = strsep(&p, "\n"))) {
 		struct symbol *sym = find_symbol(name);
 
-		if (sym)
+		if (sym) {
 			sym->used = true;
+			sym->protected = false;
+		}
 	}
 
 	free(buf);
@@ -2294,6 +2302,7 @@ int main(int argc, char **argv)
 			break;
 		case 'u':
 			unused_exports_white_list = optarg;
+			default_symbol_protected_status = true;
 			break;
 		case 'W':
 			extra_warn = true;
-- 
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 ` Siddharth Nayyar [this message]
2025-10-13 15:39 ` [PATCH v2 10/10] module loader: enforce symbol import protection Siddharth Nayyar
2025-10-14  7:34   ` 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-10-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