Linux-Modules Archive on lore.kernel.org
 help / Atom feed
* [RFC v1] libkmod: Fix handling of quotes in kernel command line
@ 2017-01-20 23:15 James Minor
  2017-01-23 20:05 ` Lucas De Marchi
  0 siblings, 1 reply; 2+ messages in thread
From: James Minor @ 2017-01-20 23:15 UTC (permalink / raw)
  To: linux-modules; +Cc: julia.cartwright, zach.brown, ken.sharp, James Minor

If a module parameter on the command line contains quotes, any
spaces inside those quotes should be included as part of the
parameter.

Signed-off-by: James Minor <james.minor@ni.com>
---
 libkmod/libkmod-config.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c
index 19f56a7..0596025 100644
--- a/libkmod/libkmod-config.c
+++ b/libkmod/libkmod-config.c
@@ -497,6 +497,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, is_module = 1;
+	bool is_quoted = false;
 
 	fd = open("/proc/cmdline", O_RDONLY|O_CLOEXEC);
 	if (fd < 0) {
@@ -514,6 +515,12 @@ static int kmod_config_parse_kcmdline(struct kmod_config *config)
 	}
 
 	for (p = buf, modname = buf; *p != '\0' && *p != '\n'; p++) {
+		if (*p == '"') {
+			is_quoted = !is_quoted;
+			continue;
+		}
+		if (is_quoted)
+			continue;
 		switch (*p) {
 		case ' ':
 			*p = '\0';
-- 
1.9.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [RFC v1] libkmod: Fix handling of quotes in kernel command line
  2017-01-20 23:15 [RFC v1] libkmod: Fix handling of quotes in kernel command line James Minor
@ 2017-01-23 20:05 ` Lucas De Marchi
  0 siblings, 0 replies; 2+ messages in thread
From: Lucas De Marchi @ 2017-01-23 20:05 UTC (permalink / raw)
  To: James Minor; +Cc: linux-modules, julia.cartwright, zach.brown, ken.sharp

On Fri, Jan 20, 2017 at 3:15 PM, James Minor <james.minor@ni.com> wrote:
>
> If a module parameter on the command line contains quotes, any
> spaces inside those quotes should be included as part of the
> parameter.
>
> Signed-off-by: James Minor <james.minor@ni.com>
> ---
>  libkmod/libkmod-config.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c
> index 19f56a7..0596025 100644
> --- a/libkmod/libkmod-config.c
> +++ b/libkmod/libkmod-config.c
> @@ -497,6 +497,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, is_module = 1;
> +       bool is_quoted = false;
>
>         fd = open("/proc/cmdline", O_RDONLY|O_CLOEXEC);
>         if (fd < 0) {
> @@ -514,6 +515,12 @@ static int kmod_config_parse_kcmdline(struct kmod_config *config)
>         }
>
>         for (p = buf, modname = buf; *p != '\0' && *p != '\n'; p++) {
> +               if (*p == '"') {
> +                       is_quoted = !is_quoted;
> +                       continue;
> +               }
> +               if (is_quoted)
> +                       continue;

Thanks for fixing this bug. However this would parse spaces in the
module name, which is not allowed by kernel. I think we should
maintain the "quoted" state across loop iterations and forbid it on
param names.

We also have a testsuite in which we add tests for this kind of stuff.
I added a test there:
https://git.kernel.org/cgit/utils/kernel/kmod/kmod.git/commit/?id=ded0bebca80ac1f20caa488efb412aa72ea8a7fd

thanks
Lucas De Marchi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-20 23:15 [RFC v1] libkmod: Fix handling of quotes in kernel command line James Minor
2017-01-23 20:05 ` Lucas De Marchi

Linux-Modules Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-modules/0 linux-modules/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-modules linux-modules/ https://lore.kernel.org/linux-modules \
		linux-modules@vger.kernel.org linux-modules@archiver.kernel.org
	public-inbox-index linux-modules


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-modules


AGPL code for this site: git clone https://public-inbox.org/ public-inbox