linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arvind Sankar <nivedita@alum.mit.edu>
To: Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH v2 3/3] init/main.c: fix quoted value handling in unknown_bootoption
Date: Thu, 12 Dec 2019 13:00:23 -0500	[thread overview]
Message-ID: <20191212180023.24339-4-nivedita@alum.mit.edu> (raw)
In-Reply-To: <20191212180023.24339-1-nivedita@alum.mit.edu>

Commit a99cd1125189 ("init: fix bug where environment vars can't be
passed via boot args") introduced two minor bugs in unknown_bootoption
by factoring out the quoted value handling into a separate function.

When value is quoted, repair_env_string will move the value up 1 byte to
strip the quotes, so val in unknown_bootoption no longer points to the
actual location of the value.

The result is that an argument of the form param=".value" is mistakenly
treated as a potential module parameter and is not placed in init's
environment, and an argument of the form param="value" can result in a
duplicate environment variable: eg TERM="vt100" on the command line will
result in both TERM=linux and TERM=vt100 being placed into init's
environment.

Fix this by recording the length of the param before calling
repair_env_string instead of relying on val.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
---
 init/main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/init/main.c b/init/main.c
index a1febc3de582..efece9fe988e 100644
--- a/init/main.c
+++ b/init/main.c
@@ -255,7 +255,6 @@ static void __init repair_env_string(char *param, char *val)
 		else if (val == param+strlen(param)+2) {
 			val[-2] = '=';
 			memmove(val-1, val, strlen(val)+1);
-			val--;
 		} else
 			BUG();
 	}
@@ -290,6 +289,8 @@ static int __init set_init_arg(char *param, char *val,
 static int __init unknown_bootoption(char *param, char *val,
 				     const char *unused, void *arg)
 {
+	size_t len = strlen(param);
+
 	repair_env_string(param, val);
 
 	/* Handle obsolete-style parameters */
@@ -297,7 +298,7 @@ static int __init unknown_bootoption(char *param, char *val,
 		return 0;
 
 	/* Unused module parameter. */
-	if (strchr(param, '.') && (!val || strchr(param, '.') < val))
+	if (strnchr(param, len, '.'))
 		return 0;
 
 	if (panic_later)
@@ -311,7 +312,7 @@ static int __init unknown_bootoption(char *param, char *val,
 				panic_later = "env";
 				panic_param = param;
 			}
-			if (!strncmp(param, envp_init[i], val - param))
+			if (!strncmp(param, envp_init[i], len+1))
 				break;
 		}
 		envp_init[i] = param;
-- 
2.23.0


      parent reply	other threads:[~2019-12-12 18:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-23 21:08 [PATCH 0/3] init/main.c: minor cleanup/bugfix of envvar handling Arvind Sankar
2019-11-23 21:08 ` [PATCH 1/3] init/main.c: log arguments and environment passed to init Arvind Sankar
2019-11-23 21:08 ` [PATCH 2/3] init/main.c: remove unnecessary repair_env_string in do_initcall_level Arvind Sankar
2019-11-23 21:08 ` [PATCH 3/3] init/main.c: fix quoted value handling in unknown_bootoption Arvind Sankar
2019-11-23 21:20 ` [PATCH 0/3] init/main.c: minor cleanup/bugfix of envvar handling Randy Dunlap
2019-11-23 21:26   ` Arvind Sankar
2019-11-23 21:40 ` [PATCH RESEND " Arvind Sankar
2019-11-23 21:40   ` [PATCH RESEND 1/3] init/main.c: log arguments and environment passed to init Arvind Sankar
2019-11-23 21:40   ` [PATCH RESEND 2/3] init/main.c: remove unnecessary repair_env_string in do_initcall_level Arvind Sankar
2019-11-23 21:40   ` [PATCH RESEND 3/3] init/main.c: fix quoted value handling in unknown_bootoption Arvind Sankar
2019-11-27 19:25   ` [PATCH RESEND 0/3] init/main.c: minor cleanup/bugfix of envvar handling Arvind Sankar
2019-12-12 18:00   ` [PATCH v2 " Arvind Sankar
2019-12-12 18:00     ` [PATCH v2 1/3] init/main.c: log arguments and environment passed to init Arvind Sankar
2019-12-12 18:00     ` [PATCH v2 2/3] init/main.c: remove unnecessary repair_env_string in do_initcall_level Arvind Sankar
2019-12-12 18:00     ` Arvind Sankar [this message]

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=20191212180023.24339-4-nivedita@alum.mit.edu \
    --to=nivedita@alum.mit.edu \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).