Linux-Modules Archive on lore.kernel.org
 help / Atom feed
* [PATCH 1/2] libkmod-config: replace 0/1 with bool
@ 2017-02-16 17:28 Lucas De Marchi
  2017-02-16 17:28 ` [PATCH 2/2] libkmod-config: fix parsing quoted kernel cmdline on params Lucas De Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Lucas De Marchi @ 2017-02-16 17:28 UTC (permalink / raw)
  To: linux-modules; +Cc: James Minor, julia.cartwright, zach.brown, ken.sharp

---
 libkmod/libkmod-config.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c
index 0596025..18f300a 100644
--- a/libkmod/libkmod-config.c
+++ b/libkmod/libkmod-config.c
@@ -496,8 +496,8 @@ 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;
+	char *p, *modname,  *param = NULL, *value = NULL;
+	bool is_quoted = false, is_module = true;
 
 	fd = open("/proc/cmdline", O_RDONLY|O_CLOEXEC);
 	if (fd < 0) {
@@ -528,7 +528,7 @@ static int kmod_config_parse_kcmdline(struct kmod_config *config)
 				kcmdline_parse_result(config, modname, param, value);
 			param = value = NULL;
 			modname = p + 1;
-			is_module = 1;
+			is_module = true;
 			break;
 		case '.':
 			if (param == NULL) {
@@ -540,7 +540,7 @@ static int kmod_config_parse_kcmdline(struct kmod_config *config)
 			if (param != NULL)
 				value = p + 1;
 			else
-				is_module = 0;
+				is_module = false;
 			break;
 		}
 	}
-- 
2.9.3


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

* [PATCH 2/2] libkmod-config: fix parsing quoted kernel cmdline on params
  2017-02-16 17:28 [PATCH 1/2] libkmod-config: replace 0/1 with bool Lucas De Marchi
@ 2017-02-16 17:28 ` Lucas De Marchi
  2017-02-23 22:14   ` Lucas De Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Lucas De Marchi @ 2017-02-16 17:28 UTC (permalink / raw)
  To: linux-modules; +Cc: James Minor, julia.cartwright, zach.brown, ken.sharp

We can only accept quoted values, not module names or parameter names.
---
 libkmod/libkmod-config.c                                   | 14 ++++++++++++++
 .../test-modprobe/module-param-kcmdline5/proc/cmdline      |  2 +-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c
index 18f300a..aaac0a1 100644
--- a/libkmod/libkmod-config.c
+++ b/libkmod/libkmod-config.c
@@ -517,10 +517,24 @@ 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;
+
+			if (is_quoted) {
+				/* don't consider a module until closing quotes */
+				is_module = false;
+			} else if (param != NULL && value != NULL) {
+				/*
+				 * If we are indeed expecting a value and
+				 * closing quotes, then this can be considered
+				 * a valid option for a module
+				 */
+				is_module = true;
+			}
+
 			continue;
 		}
 		if (is_quoted)
 			continue;
+
 		switch (*p) {
 		case ' ':
 			*p = '\0';
diff --git a/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline5/proc/cmdline b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline5/proc/cmdline
index 0c796b3..84e0168 100644
--- a/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline5/proc/cmdline
+++ b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline5/proc/cmdline
@@ -1 +1 @@
-psmouse.foo psmouse.bar=1 psmouse.foobar="test 1" " notamodule" "noteamodule2 " notamodule3 " quiet rw
+psmouse.foo psmouse.bar=1 psmouse.foobar="test 1" psmouse."invalid option" " notamodule" "noteamodule2 " notamodule3 quiet rw
-- 
2.9.3


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

* Re: [PATCH 2/2] libkmod-config: fix parsing quoted kernel cmdline on params
  2017-02-16 17:28 ` [PATCH 2/2] libkmod-config: fix parsing quoted kernel cmdline on params Lucas De Marchi
@ 2017-02-23 22:14   ` Lucas De Marchi
  0 siblings, 0 replies; 3+ messages in thread
From: Lucas De Marchi @ 2017-02-23 22:14 UTC (permalink / raw)
  To: Lucas De Marchi
  Cc: linux-modules, James Minor, julia.cartwright, zach.brown, ken.sharp

On Thu, Feb 16, 2017 at 9:28 AM, Lucas De Marchi
<lucas.demarchi@intel.com> wrote:
> We can only accept quoted values, not module names or parameter names.
> ---
>  libkmod/libkmod-config.c                                   | 14 ++++++++++++++
>  .../test-modprobe/module-param-kcmdline5/proc/cmdline      |  2 +-
>  2 files changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c
> index 18f300a..aaac0a1 100644
> --- a/libkmod/libkmod-config.c
> +++ b/libkmod/libkmod-config.c
> @@ -517,10 +517,24 @@ 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;
> +
> +                       if (is_quoted) {
> +                               /* don't consider a module until closing quotes */
> +                               is_module = false;
> +                       } else if (param != NULL && value != NULL) {
> +                               /*
> +                                * If we are indeed expecting a value and
> +                                * closing quotes, then this can be considered
> +                                * a valid option for a module
> +                                */
> +                               is_module = true;
> +                       }
> +
>                         continue;
>                 }
>                 if (is_quoted)
>                         continue;
> +
>                 switch (*p) {
>                 case ' ':
>                         *p = '\0';
> diff --git a/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline5/proc/cmdline b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline5/proc/cmdline
> index 0c796b3..84e0168 100644
> --- a/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline5/proc/cmdline
> +++ b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline5/proc/cmdline
> @@ -1 +1 @@
> -psmouse.foo psmouse.bar=1 psmouse.foobar="test 1" " notamodule" "noteamodule2 " notamodule3 " quiet rw
> +psmouse.foo psmouse.bar=1 psmouse.foobar="test 1" psmouse."invalid option" " notamodule" "noteamodule2 " notamodule3 quiet rw
> --

Both patches applied.

Lucas De Marchi

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-16 17:28 [PATCH 1/2] libkmod-config: replace 0/1 with bool Lucas De Marchi
2017-02-16 17:28 ` [PATCH 2/2] libkmod-config: fix parsing quoted kernel cmdline on params Lucas De Marchi
2017-02-23 22:14   ` 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