diff options
author | Lucas De Marchi <lucas.demarchi@intel.com> | 2021-02-12 01:45:22 -0800 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@intel.com> | 2021-02-15 11:53:43 -0800 |
commit | d3a1fe67b64cad103ff4f93dfd9f2cf19cab09ba (patch) | |
tree | f9145f603b88ab905ae143e34751828f8cca686d /libkmod | |
parent | 01ed9af61e239b40514edf527ac87c79377266ac (diff) | |
download | kmod-d3a1fe67b64cad103ff4f93dfd9f2cf19cab09ba.tar.gz kmod-d3a1fe67b64cad103ff4f93dfd9f2cf19cab09ba.tar.bz2 kmod-d3a1fe67b64cad103ff4f93dfd9f2cf19cab09ba.zip |
libkmod-config: re-quote option from kernel cmdline
It was reported that grub mangles the kernel cmdline. It turns
acpi_cpufreq.dyndbg="file drivers/cpufreq/acpi-cpufreq.c +mpf"
into
"acpi_cpufreq.dyndbg=file drivers/cpufreq/acpi-cpufreq.c +mpf"
However, even though we could blame grub for doing that, the kernel
happily accepts and re-quotes it when the module is built-in.
So, it's better if kmod also understands it this way and does the same.
Here we basically add additional code to un-mangle it, moving the quote
in way that is acceptable to pass through init_module(). Note that the
interface [f]init_module() gives us mandates the quote to be part of the
value: the module name is not passed and the options are separated by
space.
Reported-by: Jiri Slaby <jirislaby@kernel.org>
Tested-by: Jessica Yu <jeyu@kernel.org>
Link: https://bugzilla.suse.com/show_bug.cgi?id=1181111#c10
Diffstat (limited to 'libkmod')
-rw-r--r-- | libkmod/libkmod-config.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c index d3cd10d..2873f06 100644 --- a/libkmod/libkmod-config.c +++ b/libkmod/libkmod-config.c @@ -498,7 +498,7 @@ static int kmod_config_parse_kcmdline(struct kmod_config *config) { char buf[KCMD_LINE_SIZE]; int fd, err; - char *p, *modname, *param = NULL, *value = NULL; + char *p, *p_quote_start, *modname, *param = NULL, *value = NULL; bool is_quoted = false, iter = true; enum state { STATE_IGNORE, @@ -524,10 +524,23 @@ static int kmod_config_parse_kcmdline(struct kmod_config *config) } state = STATE_MODNAME; + p_quote_start = NULL; for (p = buf, modname = buf; iter; p++) { switch (*p) { case '"': is_quoted = !is_quoted; + + /* + * only allow starting quote as first char when looking + * for a modname: anything else is considered ill-formed + */ + if (is_quoted && state == STATE_MODNAME && p == modname) { + p_quote_start = p; + modname = p + 1; + } else if (state != STATE_VALUE) { + state = STATE_IGNORE; + } + break; case '\0': case '\n': @@ -550,6 +563,7 @@ static int kmod_config_parse_kcmdline(struct kmod_config *config) */ modname = p + 1; state = STATE_MODNAME; + p_quote_start = NULL; } break; case '.': @@ -576,10 +590,30 @@ static int kmod_config_parse_kcmdline(struct kmod_config *config) } if (state == STATE_COMPLETE) { + /* + * We may need to re-quote to unmangle what the + * bootloader passed. Example: grub passes the option as + * "parport.dyndbg=file drivers/parport/ieee1284_ops.c +mpf" + * instead of + * parport.dyndbg="file drivers/parport/ieee1284_ops.c +mpf" + */ + if (p_quote_start && p_quote_start < modname) { + /* + * p_quote_start + * | + * |modname param value + * || | | + * vv v v + * "parport\0dyndbg=file drivers/parport/ieee1284_ops.c +mpf" */ + memmove(p_quote_start, modname, value - modname); + value--; modname--; param--; + *value = '"'; + } kcmdline_parse_result(config, modname, param, value); /* start over on next iteration */ modname = p + 1; state = STATE_MODNAME; + p_quote_start = NULL; } } |