2020-01-17 14:54:28

by Jessica Yu

[permalink] [raw]
Subject: [PATCH] module: avoid setting info->name early in case we can fall back to info->mod->name

In setup_load_info(), info->name (which contains the name of the module,
mostly used for early logging purposes before the module gets set up)
gets unconditionally assigned if .modinfo is missing despite the fact
that there is an if (!info->name) check near the end of the function.
Avoid assigning a placeholder string to info->name if .modinfo doesn't
exist, so that we can fall back to info->mod->name later on.

Fixes: 5fdc7db6448a ("module: setup load info before module_sig_check()")
Signed-off-by: Jessica Yu <[email protected]>
---
kernel/module.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index 2b5f9c4748bc..f2379e54fae8 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -3059,9 +3059,7 @@ static int setup_load_info(struct load_info *info, int flags)

/* Try to find a name early so we can log errors with a module name */
info->index.info = find_sec(info, ".modinfo");
- if (!info->index.info)
- info->name = "(missing .modinfo section)";
- else
+ if (info->index.info)
info->name = get_modinfo(info, "name");

/* Find internal symbols and strings. */
@@ -3076,14 +3074,15 @@ static int setup_load_info(struct load_info *info, int flags)
}

if (info->index.sym == 0) {
- pr_warn("%s: module has no symbols (stripped?)\n", info->name);
+ pr_warn("%s: module has no symbols (stripped?)\n",
+ info->name ?: "(missing .modinfo section or name field)");
return -ENOEXEC;
}

info->index.mod = find_sec(info, ".gnu.linkonce.this_module");
if (!info->index.mod) {
pr_warn("%s: No module found in object\n",
- info->name ?: "(missing .modinfo name field)");
+ info->name ?: "(missing .modinfo section or name field)");
return -ENOEXEC;
}
/* This is temporary: point mod into copy of data. */
--
2.16.4


2020-01-20 15:58:36

by Miroslav Benes

[permalink] [raw]
Subject: Re: [PATCH] module: avoid setting info->name early in case we can fall back to info->mod->name

On Fri, 17 Jan 2020, Jessica Yu wrote:

> In setup_load_info(), info->name (which contains the name of the module,
> mostly used for early logging purposes before the module gets set up)
> gets unconditionally assigned if .modinfo is missing despite the fact
> that there is an if (!info->name) check near the end of the function.
> Avoid assigning a placeholder string to info->name if .modinfo doesn't
> exist, so that we can fall back to info->mod->name later on.
>
> Fixes: 5fdc7db6448a ("module: setup load info before module_sig_check()")
> Signed-off-by: Jessica Yu <[email protected]>

Reviewed-by: Miroslav Benes <[email protected]>

M

2020-01-21 08:50:27

by Jessica Yu

[permalink] [raw]
Subject: Re: [PATCH] module: avoid setting info->name early in case we can fall back to info->mod->name

+++ Miroslav Benes [20/01/20 16:57 +0100]:
>On Fri, 17 Jan 2020, Jessica Yu wrote:
>
>> In setup_load_info(), info->name (which contains the name of the module,
>> mostly used for early logging purposes before the module gets set up)
>> gets unconditionally assigned if .modinfo is missing despite the fact
>> that there is an if (!info->name) check near the end of the function.
>> Avoid assigning a placeholder string to info->name if .modinfo doesn't
>> exist, so that we can fall back to info->mod->name later on.
>>
>> Fixes: 5fdc7db6448a ("module: setup load info before module_sig_check()")
>> Signed-off-by: Jessica Yu <[email protected]>
>
>Reviewed-by: Miroslav Benes <[email protected]>

Applied, thanks!

Jessica