From: Luis Chamberlain <mcgrof@kernel.org>
To: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org,
pmladek@suse.com, david@redhat.com, petr.pavlu@suse.com,
prarit@redhat.com
Cc: christophe.leroy@csgroup.eu, song@kernel.org, mcgrof@kernel.org,
torvalds@linux-foundation.org
Subject: [RFC 12/12] module: use aliases to find module on find_module_all()
Date: Fri, 10 Mar 2023 21:17:12 -0800 [thread overview]
Message-ID: <20230311051712.4095040-13-mcgrof@kernel.org> (raw)
In-Reply-To: <20230311051712.4095040-1-mcgrof@kernel.org>
Modules can have a series of aliases, but we don't currently use
them to check if a module is already loaded. Part of this is because
load_module() will stick to checking for already loaded modules using
the actual module name, not an alias. Its however desriable to also
check for aliases on find_module_all() for existing callers and future
callers. The curent gain to using aliases on find_module_all() will
simply be to be able to support unloading modules using the alias using
the delete_module() syscall.
You can debug this with dynamic debug:
GRUB_CMDLINE_LINUX_DEFAULT="dyndbg=\"func module_process_aliases +p; func module_name_match +p; \" "
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
kernel/module/aliases.c | 17 +++++++++++++++++
kernel/module/internal.h | 5 +++++
kernel/module/main.c | 24 +++++++++++++++++++++++-
3 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/kernel/module/aliases.c b/kernel/module/aliases.c
index 2f30c9d4c765..69518bc5169a 100644
--- a/kernel/module/aliases.c
+++ b/kernel/module/aliases.c
@@ -90,3 +90,20 @@ int module_process_aliases(struct module *mod, struct load_info *info)
return -ENOMEM;
}
+
+bool module_name_match_aliases(struct module *mod, const char *name, size_t len)
+{
+ unsigned int i;
+ const char *alias;
+
+ for (i=0; i < mod->num_aliases; i++) {
+ alias = mod->aliases[i];
+ if (strlen(alias) == len && !memcmp(alias, name, len)) {
+ pr_debug("module %s alias matched: alias[%u] = %s\n",
+ mod->name, i, alias);
+ return true;
+ }
+ }
+
+ return false;
+}
diff --git a/kernel/module/internal.h b/kernel/module/internal.h
index 40bb80ed21e2..78aaad74f4ca 100644
--- a/kernel/module/internal.h
+++ b/kernel/module/internal.h
@@ -306,6 +306,7 @@ static inline int same_magic(const char *amagic, const char *bmagic, bool has_cr
#ifdef CONFIG_MODULE_KERNEL_ALIAS
void free_mod_aliases(struct module *mod);
int module_process_aliases(struct module *mod, struct load_info *info);
+bool module_name_match_aliases(struct module *mod, const char *name, size_t len);
#else
static void free_mod_aliases(struct module *mod)
{
@@ -314,4 +315,8 @@ static int module_process_aliases(struct module *mod, struct load_info *info)
{
return 0;
}
+static bool module_name_match_aliases(struct module *mod, const char *name, size_t len)
+{
+ return false;
+}
#endif /* CONFIG_MODULE_KERNEL_ALIAS */
diff --git a/kernel/module/main.c b/kernel/module/main.c
index bc9202b60d55..cf044329da3c 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -338,6 +338,28 @@ bool find_symbol(struct find_symbol_arg *fsa)
return false;
}
+static bool module_name_match(struct module *mod, const char *name, size_t len)
+{
+ unsigned int i;
+ const char *alias;
+
+ if (strlen(mod->name) == len && !memcmp(mod->name, name, len))
+ return true;
+
+ return module_name_match_aliases(mod, name, len);
+
+ for (i=0; i < mod->num_aliases; i++) {
+ alias = mod->aliases[i];
+ if (strlen(alias) == len && !memcmp(alias, name, len)) {
+ pr_debug("module %s alias matched: alias[%u] = %s\n",
+ mod->name, i, alias);
+ return true;
+ }
+ }
+
+ return false;
+}
+
/*
* Search for module by name: must hold module_mutex (or preempt disabled
* for read-only access).
@@ -353,7 +375,7 @@ struct module *find_module_all(const char *name, size_t len,
lockdep_is_held(&module_mutex)) {
if (!even_unformed && mod->state == MODULE_STATE_UNFORMED)
continue;
- if (strlen(mod->name) == len && !memcmp(mod->name, name, len))
+ if (module_name_match(mod, name, len))
return mod;
}
return NULL;
--
2.39.1
next prev parent reply other threads:[~2023-03-11 5:17 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-11 5:17 [RFC 00/12] module: avoid userspace pressure on unwanted allocations Luis Chamberlain
2023-03-11 5:17 ` [RFC 01/12] module: use goto errors on check_modinfo() and layout_and_allocate() Luis Chamberlain
2023-03-11 5:17 ` [RFC 02/12] module: move get_modinfo() helpers all above Luis Chamberlain
2023-03-11 5:17 ` [RFC 03/12] module: rename next_string() to module_next_tag_pair() Luis Chamberlain
2023-03-11 5:17 ` [RFC 04/12] module: add a for_each_modinfo_entry() Luis Chamberlain
2023-03-11 5:17 ` [RFC 05/12] module: add debugging alias parsing support Luis Chamberlain
2023-03-11 5:17 ` [RFC 06/12] module: move early sanity checks into a helper Luis Chamberlain
2023-03-11 5:17 ` [RFC 07/12] module: move check_modinfo() early to early_mod_check() Luis Chamberlain
2023-03-11 5:17 ` [RFC 08/12] module: move finished_loading() Luis Chamberlain
2023-03-11 5:17 ` [RFC 09/12] module: extract patient module check into helper Luis Chamberlain
2023-03-11 5:17 ` [RFC 10/12] module: avoid allocation if module is already present and ready Luis Chamberlain
2023-03-11 5:17 ` [RFC 11/12] module: use list_add_tail_rcu() when adding module Luis Chamberlain
2023-03-11 5:17 ` Luis Chamberlain [this message]
2023-03-15 14:43 ` [RFC 12/12] module: use aliases to find module on find_module_all() Petr Pavlu
2023-03-15 16:12 ` Luis Chamberlain
2023-03-15 12:24 ` [RFC 00/12] module: avoid userspace pressure on unwanted allocations David Hildenbrand
2023-03-15 16:10 ` Luis Chamberlain
2023-03-15 16:41 ` David Hildenbrand
2023-03-16 23:55 ` Luis Chamberlain
2023-03-16 23:56 ` Luis Chamberlain
2023-03-18 0:11 ` Luis Chamberlain
2023-03-20 9:38 ` David Hildenbrand
2023-03-20 19:40 ` David Hildenbrand
2023-03-20 21:09 ` Luis Chamberlain
2023-03-20 21:15 ` David Hildenbrand
2023-03-20 21:23 ` Luis Chamberlain
2023-03-20 21:27 ` Luis Chamberlain
2023-03-21 19:32 ` David Hildenbrand
2023-03-24 9:27 ` David Hildenbrand
2023-03-24 17:54 ` Luis Chamberlain
2023-03-24 19:11 ` Linus Torvalds
2023-03-24 19:59 ` Luis Chamberlain
2023-03-24 20:28 ` Linus Torvalds
2023-03-24 21:14 ` Luis Chamberlain
2023-03-24 23:27 ` Luis Chamberlain
2023-03-24 23:41 ` Linus Torvalds
2023-03-28 3:44 ` David Hildenbrand
2023-03-28 6:16 ` Luis Chamberlain
2023-03-28 21:02 ` David Hildenbrand
2023-03-29 5:31 ` Luis Chamberlain
2023-03-30 4:42 ` David Hildenbrand
2023-03-21 15:11 ` David Hildenbrand
2023-03-21 16:52 ` Luis Chamberlain
2023-03-21 17:01 ` David Hildenbrand
2023-03-20 9:37 ` David Hildenbrand
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=20230311051712.4095040-13-mcgrof@kernel.org \
--to=mcgrof@kernel.org \
--cc=christophe.leroy@csgroup.eu \
--cc=david@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=petr.pavlu@suse.com \
--cc=pmladek@suse.com \
--cc=prarit@redhat.com \
--cc=song@kernel.org \
--cc=torvalds@linux-foundation.org \
/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;
as well as URLs for NNTP newsgroup(s).