Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1126596ybl; Thu, 12 Dec 2019 10:02:37 -0800 (PST) X-Google-Smtp-Source: APXvYqyGeSZRG73kMmQPZMSM443yiMlcmETFUEzJvrP+el2YKkybm9nmIDCy3yzqBUXydvAVuT8m X-Received: by 2002:aca:b7c5:: with SMTP id h188mr5971242oif.100.1576173757001; Thu, 12 Dec 2019 10:02:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576173756; cv=none; d=google.com; s=arc-20160816; b=XFSYJRUXtmoSKVkez5qaWxcIA8+LYVA45PUOOBbt3gfDfSmW8geu2wNZ6dy+APMGUO DiaTNJhdANq6eDbFKE2hyblMzyehhlLaED6kGDQKOfI/zpqyj8ur5PXdWU+nLfDb9Hil nyP87TNa3QqNWXiP08mtd+6iWzL9aaf1JpqU9UM0+uYY/4oD7QrGi24gWdXfhegS8YNN kzDrdzx91eopw3o3JtkNt7C7EixmxZNbPWSjBp9MZecnfHH8uWObwNCSaSYOF2sa0GAX Am/goTMtd7w+2pqhQXIJlaCX8oatrtXfZ0ZakALcH1TAaAV2v+S1MSaVKy+IY0fX8NWN wadw== 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=rBuDgfE9sLA4203asMoCDWk+/8WmQc7l3W+E9Z8j78g=; b=WwwtssyGlQ2/KlZfFzg1G2Cqq9rXa0RxoGLnyFxnkjK4eb8k1w5zi5B3Qso4k6wISS uuquF/MabgQL5Cq4BRoVhhN35Dcjtlucp+UuKrLc8chzpADcPa837/TfDd9fBtjwkgiv ZVPG+6FlfVESTPbvlgk/HNgJmJF/bKn3YKxLPMnxYquhQ8anw2WG1Ksl87uvwyl3PfGc TSaLtxlukT2xILaZkPNcG7W5VBB4uPxGV4OYo3esIhLqDX11dF/IcxI2YhHQBWd1Z+Zx 0D2LMImqdCsKUvRkyHfrz9aYgCHUVqdDhGpdS0TS3ob7YLbnjb8zo+akeIfLuazrrIA3 aGyw== 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 p26si3727987oto.240.2019.12.12.10.02.19; Thu, 12 Dec 2019 10:02:36 -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 S1730234AbfLLSA0 (ORCPT + 99 others); Thu, 12 Dec 2019 13:00:26 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:42677 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730003AbfLLSA0 (ORCPT ); Thu, 12 Dec 2019 13:00:26 -0500 Received: by mail-qk1-f193.google.com with SMTP id z14so2327462qkg.9 for ; Thu, 12 Dec 2019 10:00:26 -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=rBuDgfE9sLA4203asMoCDWk+/8WmQc7l3W+E9Z8j78g=; b=cKLtvvZJliZrTDwE6hpd5dGzMkCdZi83ZXrLL82eYxh+1o40FZXnVXRI0oTLQBHA7B WAxIxJCkiAMBZTV9q23Gqp6DDH3zYAcWlUV1L2TIjyEku9PGi9PsQYwTfUyYmCQeoStd 582fEed6uqCpj3nNqzGplF/xvd60Dp64emPLS3+NoJi6F0OhDDhUuGh24YbpxhAfr400 GMeJhUhCuxSbnnAMcC8vz6fElnDlH0ZQQ5eCeH/tYna8CgydtljqS3SXuTKtdwCA5N2B t7bAjaZOPhK2AR9l9dAlq2u0CDEcf5ykjSHp7GAETNwySBBlK8C1Yy3uasu1tK4Rxt12 CxKA== X-Gm-Message-State: APjAAAWMaSFZ+Qwqx6sGz/gzAsAXq9ndrIbLGR6mVlD3uQk7S1cTl4CZ ADx+GUezetzVhsqPu961xOrOy0Q9 X-Received: by 2002:a37:9bc2:: with SMTP id d185mr2045075qke.422.1576173624670; Thu, 12 Dec 2019 10:00:24 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2019 10:00:23 -0800 (PST) From: Arvind Sankar To: Andrew Morton , Linus Torvalds Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 0/3] init/main.c: minor cleanup/bugfix of envvar handling Date: Thu, 12 Dec 2019 13:00:20 -0500 Message-Id: <20191212180023.24339-1-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191123214039.139275-1-nivedita@alum.mit.edu> References: <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 unknown_bootoption passes unrecognized command line arguments to init as either environment variables or arguments. Some of the logic in the function is broken for quoted command line arguments. When an argument of the form param="value" is processed by parse_args and passed to unknown_bootoption, the command line has param\0"value\0 with val pointing to the beginning of value. The helper function repair_env_string is then used to restore the '=' character that was removed by parse_args, and strip the quotes off fully. This results in param=value\0\0 and val ends up pointing to the 'a' instead of the 'v' in value. This bug was introduced when repair_env_string was refactored into a separate function, and the decrement of val in repair_env_string became dead code. This causes two problems in unknown_bootoption in the two places where the val pointer is used as a substitute for the length of param: 1. An argument of the form param=".value" is misinterpreted as a potential module parameter, with the result that it will not be placed in init's environment. 2. An argument of the form param="value" is checked to see if param is an existing environment variable that should be overwritten, but the comparison is off-by-one and compares 'param=v' instead of 'param=' against the existing environment. So passing, for example, TERM="vt100" on the command line results in init being passed both TERM=linux and TERM=vt100 in its environment. Patch 1 adds logging for the arguments and environment passed to init and is independent of the rest: it can be dropped if this is unnecessarily verbose. Patch 2 removes repair_env_string from initcall parameter parsing in do_initcall_level, as that uses a separate copy of the command line now and the repairing is no longer necessary. Patch 3 fixes the bug in unknown_bootoption by recording the length of param explicitly instead of implying it from val-param. Changes from v1: - use pr_debug for additional logging in patch 1 - move removal of dead val--; line from patch 2 to patch 3 Arvind Sankar (3): init/main.c: log arguments and environment passed to init init/main.c: remove unnecessary repair_env_string in do_initcall_level init/main.c: fix quoted value handling in unknown_bootoption init/main.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) -- 2.23.0