Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1007423ybc; Sat, 23 Nov 2019 13:11:23 -0800 (PST) X-Google-Smtp-Source: APXvYqwMdlBU8/JPpgfEC+tmB9c8crDiXDPUTlYlDbIudImKHx0/mSy6eviPKObUMLVPndDftmxh X-Received: by 2002:a50:f058:: with SMTP id u24mr9120239edl.288.1574543483789; Sat, 23 Nov 2019 13:11:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574543483; cv=none; d=google.com; s=arc-20160816; b=WApieouP+3LDTmxHZM0AWeuYX9h3X1isiLlt/cGjBPRzo/TKSCKaUKnpPAnzCr7rac 1wPXvyOdyIuoVGhyXgmKtzeik4DSXivP7iHSowa9clNzxxYwpMQSdjPmJaPxT7cU/tem Q+Yn4GdXY/7x3AaUYDuSkDRxO3Lqzr/Iz/Gy3cFYx7vhvfclER31AUx2pGnlgU/cjhyw GIVR8X27MQQN8YAwTpCkqrE2WUMepLA/bu3idww16zopQxyJmpAqwpDUNLgrRlkZEL96 cLlg1GNnWVJBBNnh2zuYnPNclQZgmZY6r/UOVWGx8KVVd3UqgcoUmg+HWzdXGXEUlZMw Ghiw== 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 :message-id:date:subject:to:from; bh=ks6VXyhQYbwbWdDu7jOK7bIaMkmqq8TaCySgeWCd3V0=; b=jLP9BWj6eJ/ueqVsv1mFKuqAXLgMyOkJNpAaXqHeunup9dAjRSH5SOTWwc4k4Ypqfc uw7CXMs2p2lgv3/wYfAYIOBfS7uYQrnulwnMRTaTNPN5wafhHJL95gjIyiVLbq8vYRWf DkuRRs0Flubp1rrrcTrWZqXYo0/3ZW4IkV/ILu/zgXucMFJpNlcLIyQ5p76+kJWnYoGa rkYYz+o6f2alfXTzJRbLPcCDPVOZzzZnCk2dgr/XBsS0b4xnbk5IOm1qUZz7b5GlUeyd HXDhT8StwpLnyB04UKgNASZb0B2dZFv5reg0hv316NLrCeGow/Qb+kHy0Q/mJQP9cH6m vIVw== 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 i47si1551543eda.91.2019.11.23.13.10.29; Sat, 23 Nov 2019 13:11:23 -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 S1726762AbfKWVIU (ORCPT + 99 others); Sat, 23 Nov 2019 16:08:20 -0500 Received: from mail-qk1-f196.google.com ([209.85.222.196]:40031 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726638AbfKWVIT (ORCPT ); Sat, 23 Nov 2019 16:08:19 -0500 Received: by mail-qk1-f196.google.com with SMTP id a137so7588911qkc.7 for ; Sat, 23 Nov 2019 13:08:19 -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:subject:date:message-id:mime-version :content-transfer-encoding; bh=ks6VXyhQYbwbWdDu7jOK7bIaMkmqq8TaCySgeWCd3V0=; b=ZQPOVJsmnr/YB4JJUh7M4A17p3WJUMZkzKOe6eFJEX2piFQ60VIVnAlAk0Js7bC63J ViluqgLhjzkz8pN3GTLIOPOKPJWLehgtDU6YxDrAvFR0wKpFMYgYqONazdJy+ScQGnO0 0FRbQGquIY9AlFkOUsWq7NlbpOiCPWTD1scQHSQ5UG7EYfCeR62bF7JcdUXdRBxtwceY Q9tpulvXr7DA0jKsBH6IktU+GwSll6VJy08dSxnrn1l0hlvxJekLDdgGG5+eP8qGj8Wa cWlmJ+j/DQL4YywAgFtJVHw1UVw4cTBMuO4Jv7D/jUeUlCo/svlCsDJcRxbqcMEkJq1T MBXw== X-Gm-Message-State: APjAAAXdoxfgz35JeLT4BMCNflIc/fzLWpWpuke3F99Cx1Qij1u1DWn5 nDNrah+NcNkRxrCi4IV8zNAJMnifq0w= X-Received: by 2002:a37:6481:: with SMTP id y123mr2854280qkb.171.1574543298296; Sat, 23 Nov 2019 13:08:18 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id c37sm1164978qta.56.2019.11.23.13.08.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Nov 2019 13:08:17 -0800 (PST) From: Arvind Sankar To: linux-kernel@vger.kernel.org Subject: [PATCH 0/3] init/main.c: minor cleanup/bugfix of envvar handling Date: Sat, 23 Nov 2019 16:08:05 -0500 Message-Id: <20191123210808.107904-1-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.23.0 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.