From: Petr Mladek <pmladek@suse.com>
To: Yafang Shao <laoar.shao@gmail.com>
Cc: jpoimboe@kernel.org, jikos@kernel.org, mbenes@suse.cz,
joe.lawrence@redhat.com, mcgrof@kernel.org,
live-patching@vger.kernel.org, linux-modules@vger.kernel.org
Subject: Re: [PATCH v2 1/2] module: Add a new helper delete_module()
Date: Mon, 6 May 2024 13:58:45 +0200 [thread overview]
Message-ID: <ZjjF9cf0nU3ORFha@pathway.suse.cz> (raw)
In-Reply-To: <20240407035730.20282-2-laoar.shao@gmail.com>
On Sun 2024-04-07 11:57:29, Yafang Shao wrote:
> Introduce a new helper function, delete_module(), designed to delete kernel
> modules from locations outside of the `kernel/module` directory.
>
> No functional change.
>
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -695,12 +695,74 @@ EXPORT_SYMBOL(module_refcount);
> /* This exists whether we can unload or not */
> static void free_module(struct module *mod);
>
> +static void __delete_module(struct module *mod)
> +{
> + char buf[MODULE_FLAGS_BUF_SIZE];
> +
> + WARN_ON_ONCE(mod->state != MODULE_STATE_GOING);
> +
> + /* Final destruction now no one is using it. */
> + if (mod->exit != NULL)
> + mod->exit();
> + blocking_notifier_call_chain(&module_notify_list,
> + MODULE_STATE_GOING, mod);
> + klp_module_going(mod);
> + ftrace_release_mod(mod);
> +
> + async_synchronize_full();
> +
> + /* Store the name and taints of the last unloaded module for diagnostic purposes */
> + strscpy(last_unloaded_module.name, mod->name, sizeof(last_unloaded_module.name));
> + strscpy(last_unloaded_module.taints, module_flags(mod, buf, false),
> + sizeof(last_unloaded_module.taints));
> +
> + free_module(mod);
> + /* someone could wait for the module in add_unformed_module() */
> + wake_up_all(&module_wq);
> +}
> +
> +int delete_module(struct module *mod)
> +{
> + int ret;
> +
> + mutex_lock(&module_mutex);
> + if (!list_empty(&mod->source_list)) {
> + /* Other modules depend on us: get rid of them first. */
> + ret = -EWOULDBLOCK;
> + goto out;
> + }
This is cut&paste from SYSCALL_DEFINE2(delete_module...
> +
> + /* Doing init or already dying? */
> + if (mod->state != MODULE_STATE_LIVE) {
> + ret = -EBUSY;
> + goto out;
> + }
Same here. You only removed the debug message. Why?
> +
> + /* If it has an init func, it must have an exit func to unload */
> + if (mod->init && !mod->exit) {
> + ret = -EBUSY;
> + goto out;
> + }
Same code, just without the "forced" handling.
> +
> + if (try_release_module_ref(mod) != 0) {
> + ret = -EWOULDBLOCK;
> + goto out;
> + }
This is the same as try_stop_module() without the "forced" handling.
> + mod->state = MODULE_STATE_GOING;
> + mutex_unlock(&module_mutex);
> + __delete_module(mod);
> + return 0;
I am sure that we could better refactor the code to remove
the code duplication.
> +
> +out:
> + mutex_unlock(&module_mutex);
> + return ret;
> +}
> +
> SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
> unsigned int, flags)
> {
> struct module *mod;
> char name[MODULE_NAME_LEN];
> - char buf[MODULE_FLAGS_BUF_SIZE];
> int ret, forced = 0;
>
> if (!capable(CAP_SYS_MODULE) || modules_disabled)
Otherwise, it looks good to me.
Best Regards,
Petr
next prev parent reply other threads:[~2024-05-06 11:58 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-07 3:57 [PATCH v2 0/2] livepatch, module: Delete the associated module of disabled livepatch Yafang Shao
2024-04-07 3:57 ` [PATCH v2 1/2] module: Add a new helper delete_module() Yafang Shao
2024-04-24 12:09 ` Yafang Shao
2024-05-04 16:53 ` Greg KH
2024-05-04 22:26 ` Josh Poimboeuf
2024-05-04 21:36 ` Luis Chamberlain
2024-05-06 11:58 ` Petr Mladek [this message]
2024-04-07 3:57 ` [PATCH v2 2/2] livepatch: Delete the associated module of disabled livepatch Yafang Shao
2024-05-03 21:14 ` Josh Poimboeuf
2024-05-06 11:32 ` Petr Mladek
2024-05-07 2:35 ` Josh Poimboeuf
2024-05-07 14:03 ` Yafang Shao
2024-05-08 5:16 ` Josh Poimboeuf
2024-05-08 6:01 ` Yafang Shao
2024-05-08 7:03 ` Josh Poimboeuf
2024-05-09 2:17 ` Yafang Shao
2024-05-09 5:20 ` Josh Poimboeuf
2024-05-09 5:53 ` Yafang Shao
2024-05-09 10:16 ` Petr Mladek
2024-05-09 11:57 ` Yafang Shao
2024-05-09 10:51 ` Petr Mladek
2024-05-06 12:20 ` Petr Mladek
2024-05-02 13:30 ` [PATCH v2 0/2] livepatch, module: " Joe Lawrence
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=ZjjF9cf0nU3ORFha@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=laoar.shao@gmail.com \
--cc=linux-modules@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=mcgrof@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.