Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1029414ybc; Sat, 23 Nov 2019 13:43:26 -0800 (PST) X-Google-Smtp-Source: APXvYqxLP9bEBIQxinkKnxM0qKTZ66QJtL4nyO1MqysuHkIDEL1Cel1dYPTY3UcPYFezBPaIvSMc X-Received: by 2002:aa7:ca4a:: with SMTP id j10mr9081204edt.54.1574545406746; Sat, 23 Nov 2019 13:43:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574545406; cv=none; d=google.com; s=arc-20160816; b=t+6Ql0vOP2WzEhZ/zLS4fBIgNC+YUlKQbWzhxKkoIQNLZQz/h0BVtYZt8gD4/C4lwv b/TfLLKQ9xLfFPV2LX6Xt+LhFbajNCvdUnU2U/lHG2LqpGAObbHyd5D9Z4AkYRCVWD2E 7/o1pFgT1b61ArJ3TRSWRXH4HzPf4390zZ+eOWFAAqXaXAPQigzAJquSR3W3jHcE9j4c ajOrRvd7J39PPMGy0c1VxelbJDkSA6IVDbf+EvAbowkq11PcwKEaCPT/WJSetaGk8dZM x2ydrndK8pyGq3bdzPHj0aeaCodiWr3OmrnfAHmXLPMfekwryG+ZVnQowWyClSXHgrMM lE0A== 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=rYFSQLQUePhEzpBCVJ4C9SU6P0f+WttzJ5CloUXrqVU=; b=GqAAZHnu5M7W3h7RAmvOv5vmcjehTpGTIv/Lk8G+aqkKrRwnxlTKe2K1p0+tV7vvFO y+45v5h9NLPdXOQVDG2f263IYJRc+Pp0O51WRjBHaLseIEjJSHJIjALrfHt+jYowtZoA cZxU4jv6ze9PkdB/n60vvUU8xYYeEL6ZW134vXGTCeqLCSG8FphdQKs4Gq6V6FMJW+6J upAWqBNJM3NgzY0U6zqtV/NHb5h/Rumq+gtvEiIMFmnzPa2rv+ud8jPF0BSX6E+bFv6K Xdyw9KR1JR5B9X269BxVbYuggx2j43tTIB+87nKFCFe6FMAP/+RaBOxAL5UoYSRR7q2t 3+DQ== 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 rn10si1479106ejb.325.2019.11.23.13.43.02; Sat, 23 Nov 2019 13:43:26 -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 S1726962AbfKWVkq (ORCPT + 99 others); Sat, 23 Nov 2019 16:40:46 -0500 Received: from mail-qk1-f196.google.com ([209.85.222.196]:36413 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726803AbfKWVkq (ORCPT ); Sat, 23 Nov 2019 16:40:46 -0500 Received: by mail-qk1-f196.google.com with SMTP id d13so9472040qko.3 for ; Sat, 23 Nov 2019 13:40:44 -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=rYFSQLQUePhEzpBCVJ4C9SU6P0f+WttzJ5CloUXrqVU=; b=XLHIuHjnWkQQNopbp97l2GmpYDfz23g/qyuuFpd81ELOwGJ4zeH+PtW1uwveUSre0t AwfDfWZa/x0BCJ6jDg7GICxqb9cbWmnxBHuOdmRlKzjetpNzVLAROz90o4qmUwuN+RaD +8PfEGHgDRfJk+L91Pv2FhxOtoGkCMBNgik0O0qexdwJfhnflxN76a0tOb6A3Rqfv+vd KGqeYljktCt4L9pd2+SfvqepwPndhZ9D3pJeOkjfzonFsMJcWRZA8KiP0w1kAtdyk2iW F99dqSoUNF931Na7kUKwMIT2MjYGM3Uv6Br61+bGtCBTI9I39SS44zM09OelmqaFU9Hm Vmdg== X-Gm-Message-State: APjAAAVF2B9pVM1fcuGZ2kmf2mtKtcbt2B4nuIfHK3IG+odEMCgU+WBT JjRUxLpScb6Zk9abgCxpEsOxA07lrBk= X-Received: by 2002:a05:620a:149b:: with SMTP id w27mr4084950qkj.387.1574545243445; Sat, 23 Nov 2019 13:40:43 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id v189sm933208qkc.37.2019.11.23.13.40.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Nov 2019 13:40:42 -0800 (PST) From: Arvind Sankar To: Andrew Morton Cc: linux-kernel@vger.kernel.org Subject: [PATCH RESEND 3/3] init/main.c: fix quoted value handling in unknown_bootoption Date: Sat, 23 Nov 2019 16:40:39 -0500 Message-Id: <20191123214039.139275-4-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191123214039.139275-1-nivedita@alum.mit.edu> References: <20191123210808.107904-1-nivedita@alum.mit.edu> <20191123214039.139275-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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/init/main.c b/init/main.c index a2008e7a797f..1ee92517c515 100644 --- a/init/main.c +++ b/init/main.c @@ -289,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 */ @@ -296,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) @@ -310,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