From: Petr Pavlu <petr.pavlu@suse.com>
To: Luis Chamberlain <mcgrof@kernel.org>
Cc: christophe.leroy@csgroup.eu, song@kernel.org,
linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org,
pmladek@suse.com, david@redhat.com, prarit@redhat.com
Subject: Re: [PATCH 04/12] module: move early sanity checks into a helper
Date: Fri, 24 Mar 2023 14:02:06 +0100 [thread overview]
Message-ID: <71176c99-cacb-9a7a-0b4a-9e2c5cb1c3b5@suse.com> (raw)
In-Reply-To: <20230319212746.1783033-5-mcgrof@kernel.org>
On 3/19/23 22:27, Luis Chamberlain wrote:
> Move early sanity checkers for the module into a helper.
> This let's us make it clear when we are working with the
> local copy of the module prior to allocation.
>
> This produces no functional changes, it just makes subsequent
> changes easier to read.
>
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> ---
> kernel/module/main.c | 43 ++++++++++++++++++++++++++-----------------
> 1 file changed, 26 insertions(+), 17 deletions(-)
>
> diff --git a/kernel/module/main.c b/kernel/module/main.c
> index 427284ab31f1..933cef72ae13 100644
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -2668,6 +2668,31 @@ static int unknown_module_param_cb(char *param, char *val, const char *modname,
> return 0;
> }
>
> +/* Module within temporary copy, this doesn't do any allocation */
> +static int early_mod_check(struct load_info *info, int flags)
> +{
> + int err;
> +
> + /*
> + * Now that we know we have the correct module name, check
> + * if it's blacklisted.
> + */
> + if (blacklisted(info->name)) {
> + pr_err("Module %s is blacklisted\n", info->name);
> + return -EPERM;
> + }
> +
> + err = rewrite_section_headers(info, flags);
> + if (err)
> + return err;
> +
> + /* Check module struct version now, before we try to use module. */
> + if (!check_modstruct_version(info, info->mod))
> + return ENOEXEC;
The error value when check_modstruct_version() fails is changed in this patch
from -ENOEXEC to ENOEXEC and updated back again in the next patch. It would be
good to avoid introducing this temporary problem and keep the value throughout
as -ENOEXEC.
> +
> + return 0;
> +}
> +
> /*
> * Allocate and load the module: note that size of section 0 is always
> * zero, and we rely on this for optional sections.
> @@ -2711,26 +2736,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
> if (err)
> goto free_copy;
>
> - /*
> - * Now that we know we have the correct module name, check
> - * if it's blacklisted.
> - */
> - if (blacklisted(info->name)) {
> - err = -EPERM;
> - pr_err("Module %s is blacklisted\n", info->name);
> - goto free_copy;
> - }
> -
> - err = rewrite_section_headers(info, flags);
> + err = early_mod_check(info, flags);
> if (err)
> goto free_copy;
>
> - /* Check module struct version now, before we try to use module. */
> - if (!check_modstruct_version(info, info->mod)) {
> - err = -ENOEXEC;
Original value here.
> - goto free_copy;
> - }
> -
> /* Figure out module layout, and allocate all the memory. */
> mod = layout_and_allocate(info, flags);
> if (IS_ERR(mod)) {
Thanks,
Petr
next prev parent reply other threads:[~2023-03-24 13:02 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-19 21:27 [PATCH 00/12] module: cleanup and call taints after is inserted Luis Chamberlain
2023-03-19 21:27 ` [PATCH 01/12] module: move get_modinfo() helpers all above Luis Chamberlain
2023-03-19 21:27 ` [PATCH 02/12] module: rename next_string() to module_next_tag_pair() Luis Chamberlain
2023-03-19 21:27 ` [PATCH 03/12] module: add a for_each_modinfo_entry() Luis Chamberlain
2023-03-19 21:27 ` [PATCH 04/12] module: move early sanity checks into a helper Luis Chamberlain
2023-03-24 13:02 ` Petr Pavlu [this message]
2023-03-24 18:33 ` Luis Chamberlain
2023-03-19 21:27 ` [PATCH 05/12] module: move check_modinfo() early to early_mod_check() Luis Chamberlain
2023-03-19 21:27 ` [PATCH 06/12] module: rename set_license() to module_license_taint_check() Luis Chamberlain
2023-03-19 21:27 ` [PATCH 07/12] module: split taint work out of check_modinfo_livepatch() Luis Chamberlain
2023-03-19 21:27 ` [PATCH 08/12] module: split taint adding with info checking Luis Chamberlain
2023-03-19 21:27 ` [PATCH 09/12] module: move tainting until after a module hits our linked list Luis Chamberlain
2023-03-19 21:27 ` [PATCH 10/12] module: move signature taint to module_augment_kernel_taints() Luis Chamberlain
2023-03-19 21:27 ` [PATCH 11/12] module: converge taint work together Luis Chamberlain
2023-03-19 21:27 ` [PATCH 12/12] module: rename check_module_license_and_versions() to check_export_symbol_versions() Luis Chamberlain
2023-03-22 23:42 ` [PATCH 00/12] module: cleanup and call taints after is inserted Luis Chamberlain
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=71176c99-cacb-9a7a-0b4a-9e2c5cb1c3b5@suse.com \
--to=petr.pavlu@suse.com \
--cc=christophe.leroy@csgroup.eu \
--cc=david@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=pmladek@suse.com \
--cc=prarit@redhat.com \
--cc=song@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 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®