Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1126607ybl; Thu, 12 Dec 2019 10:02:37 -0800 (PST) X-Google-Smtp-Source: APXvYqwyTRuYrWOJCaiK58n2F1UhQ8mzSmv3vmWmpAcVzy4oEwhny5U9k9johxmSwqtXLxzdLNxW X-Received: by 2002:aca:43c1:: with SMTP id q184mr5459655oia.116.1576173757672; Thu, 12 Dec 2019 10:02:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576173757; cv=none; d=google.com; s=arc-20160816; b=wN9UdYMPssFmPzCldABp6JhZpIzrKKmyjz4QTPQk+kebYL+/WLjNQ/CZ4bq316b8JV CRjIs8TAOmGKilHHCBgy4q+K4tm7cSm2sXtgJKrx/XP4e7/RpHIf2Diyc/Uy3hR8Xfmz xWXdFPAf6R/+BoHQVHI19XI8r6EghB8fYwy+hO7uzEsX9f9qGJ6M2JZ2LMtyDi7F3TOU r4oOXuybXWnbmT4wU5bdtVRhKnjRku94J+UdJxuN/M0OzQ/tjBdsZddyV2dSGwxVMkE8 CAnBEOMMmCbNbuttgZC6Q2VQjYRhr1iDftPlF0wIPew36tpYs9vkFSHhhzM5R1E1/Rle N58w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=atIQIs7dUB80addC2OXNtRGB9vn8GNEImvyJYL7Xn7U=; b=LsGkEIKcM7Bpk9VzJqEVqocXwIDOC9lpQWCITUSc5fSWTq6QljjG9CSFCp0XLDxOEt yf5CVBjF5iiP0JtJ2Tm3Oe3e2/Rwg10rLosIb+ZF94N9vGkRtrZ+x7WSyukOPvtVbUke 1LNDwRJVLvv+nF2UKuPud+kPqOfBjP3aR127bcDgIE02sJE9d+SRMlxstF56J0jldeF/ 38yvaxKy8gJZL4kgACv/4e5M3e35d0sdWoH0OBIkj6Ml24e5qfdmmhhVINewvUvekaV7 d7oBBqKZ0Jv+oYPUVDXgoHSLxxAK4kHNSDnTWLXh77SSfbAvqxCQX0bFpArOlhpxBkCT 4YRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f25si3417307otp.25.2019.12.12.10.02.23; Thu, 12 Dec 2019 10:02:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730333AbfLLSAd (ORCPT + 99 others); Thu, 12 Dec 2019 13:00:33 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:43079 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730310AbfLLSA2 (ORCPT ); Thu, 12 Dec 2019 13:00:28 -0500 Received: by mail-qk1-f194.google.com with SMTP id t129so2329485qke.10 for ; Thu, 12 Dec 2019 10:00:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=atIQIs7dUB80addC2OXNtRGB9vn8GNEImvyJYL7Xn7U=; b=oJjNvcjmMFzhW6eH8FRzAxpSimDJAgQMMY7zgPtn1H1Gmm6amAz9E8rwZfdLf2Q3MH tZGHj2KgYfzy298SvlFNEvzRWxSTawsJX5ZEaeLf0Ya+ggxbYgNGciPBagDk82JmT7wp KAQ9bs5Pmx3KQg8WFQ01mKxwcAnoKd0cRnQ5L+Q+R7rYSA9NN/h50mIOyAhYYtc1LWZM jgmRpdbCv9gs3oRAXsCrgVlC4OCKcZiguHgT/Nz863oiFEw03L1kE79bxQ/pPpiSbrz8 L01fcD43tFDBflES6a5Mo5JFws0GN98YMa0rjy8P2bxAZRobM0NeKnhk6NDe1yrhY/z/ H55g== X-Gm-Message-State: APjAAAWKEcCInuST1YouLmPT9nvqyrREJvn+r93YdDdXQ6LocWFhPycZ E9kTfivHwokSthoFt0jrLbJNWpWc X-Received: by 2002:a05:620a:15af:: with SMTP id f15mr9385035qkk.225.1576173627338; Thu, 12 Dec 2019 10:00:27 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id j7sm1946037qkd.46.2019.12.12.10.00.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2019 10:00:26 -0800 (PST) From: Arvind Sankar To: Andrew Morton , Linus Torvalds 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 Message-Id: <20191212180023.24339-4-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191212180023.24339-1-nivedita@alum.mit.edu> References: <20191123214039.139275-1-nivedita@alum.mit.edu> <20191212180023.24339-1-nivedita@alum.mit.edu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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