Received: by 2002:ab2:5d18:0:b0:1ef:7a0f:c32d with SMTP id j24csp418002lqk; Sat, 9 Mar 2024 17:25:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUTziNE0tO19YI6s8YrmOE2bNn1m6na8+ZZpnXOM08qvzvHtvtswzoxFoi4OvSEDsLfi1aBemrnCQ5RbpzQLsCpEe6joQEzl38oXpfzgA== X-Google-Smtp-Source: AGHT+IEmHVx8lurwcl0U2ub48k1eBA2LIycy1tDqUVqVN5k87PsIfyVEbhe083UGTJ5e2WVlbHLh X-Received: by 2002:a05:6a00:1898:b0:6e6:4e6b:5a16 with SMTP id x24-20020a056a00189800b006e64e6b5a16mr4188324pfh.4.1710033946342; Sat, 09 Mar 2024 17:25:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1710033946; cv=pass; d=google.com; s=arc-20160816; b=OFTjH5OwiYiHHWGXpnNWPoiUsz3WEC6PLHH5bqdymhB1Z1YgGLPgeoiRoyi2ns5qyC KgGPuWdLqIj5uRRVixvonib1IlJ88jjK70glyJPqfjTrES3Y2P40VFHwGoetBeula8iA NORpS9voNeAd0wj08C2UN47Ca67xa0/VKG5fcpbWrYIvNJ2Wo9D0a/t7u0QZULyr6vJa R8Gs7i+LsPHpPSdRHraXPAioMfmOAPa0VUkRLA/Um2z0KNknb3CUf3qKrSUVz+xDPAzK EAvgUwJGueu9EOD4lKUVJIgX5BPEo1ZUGIE5R2/8HWdPAd+fzpe4htzfkmqLAfdeIy1G KUww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=m6eO6RqCtkZsJk1oJau0heYLMET1tGWp48lFXNV5WHQ=; fh=xPIyA/yzqr7D1MGvI4yrhCC6HG+deBByY8K8nWrfPkQ=; b=fo3nUALRcpdmFCZIB2GPZPkTLsR9DlI0chG2td6zKp2ZSGsmqwFOxgqZMCJEpFfLSn Me/U6IpnjBfGKRl23Y3naGcGl3VtM9mFaCQyYV0F+Ui9H4DN9cEMIsuq5PSNdt4PZrfU sBxr1jTd+5pQi875jAR9ZNa1mOwdEIkNT+D2roj9qfNm1R8IozKEvV0skamaSJWGHSdR MkHl7QAxOL+FUrKQJxyVSoKc+qT6e9VNsgL9cL7vUhipmXWNt6UCorSX6WPTFhRDltgU ciCrzg8O1vy3/mkYMWhrmmDkT00tjmRc4wXXepfzDboDKPrJm+n25isGxwv7kIS1f74o xbpw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gzL89X0M; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-98077-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98077-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b6-20020a639306000000b005d9252c9d05si2331096pge.103.2024.03.09.17.25.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 17:25:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-98077-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gzL89X0M; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-98077-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98077-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 094E6281A17 for ; Sun, 10 Mar 2024 01:25:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB6D3EDB; Sun, 10 Mar 2024 01:25:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gzL89X0M" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0ED827FB for ; Sun, 10 Mar 2024 01:25:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710033939; cv=none; b=XrSUeJZuHm5HCy283gccDthPeYyIguUf/VXeL5UrJz05kuRl07ZgpsSgHhuZ6LHKkZqF6/tonNyMar1Itf9mE4ocFK5K/OGk7HX85p8x9S0w5wkYTfj0uwSVj5GgFIQYG3h4tyht85Vq18sl2WTmPBFReCNXJv0AN6oeqmR2jBc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710033939; c=relaxed/simple; bh=G40V4vpPRhyixM7l44qRiTMIVlsMvJ2N4QjvotB9vtg=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=QJM0MHG+vlp0jrLwPI2iBq6oOWI5V5ImShD1Xs62MNIlxZheiJujwZm4eT2ecZlEkzVhng4tNBcdlrO+ooWPos4hR6tvzArFzDIlqydxXn/63mw4p1JMK6bw8ptZwIj0MsXPvi628RaZq/ixv7pTRNy9kpIzN1NEMeDKbrSdd9g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gzL89X0M; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48667C433C7; Sun, 10 Mar 2024 01:25:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710033938; bh=G40V4vpPRhyixM7l44qRiTMIVlsMvJ2N4QjvotB9vtg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=gzL89X0MUOzZfAHmgAH2AUvQ1p9AYy6Y7dgcGvWbHWwnzil45oavNvtc97VJli/k7 lJzNYz7C+pUylhduMlA6nBjLK57Pl0vXy2fEI5HTLNyGbA9SSj79hFKOs7qKisGkJT asX+hTHA/nRQNx5dSDO4ggnfI8wlkHpNKxt/dOJ309DrId7LCP6HUQc2fkP4e03PgF PB2TLLKSYSb70n1crPU4JiL+2rtTV9+YcsDJGftPdLof0nvgOsrf1XoW4+TUaXw8F9 pO3Aeo3KWv37JtusdK7W6RYNsOIFB5DScH6tymFGaxNwyDGImtoSNNWWipzua5P2pS XGw9xjqRwd7mg== Date: Sun, 10 Mar 2024 10:25:34 +0900 From: Masami Hiramatsu (Google) To: Rasmus Villemoes Cc: Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] bootconfig: do not put quotes on cmdline items unless necessary Message-Id: <20240310102534.cf79e09037df23b4f51981b0@kernel.org> In-Reply-To: <20240308124401.1702046-1-linux@rasmusvillemoes.dk> References: <20240308124401.1702046-1-linux@rasmusvillemoes.dk> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 8 Mar 2024 13:44:01 +0100 Rasmus Villemoes wrote: > When trying to migrate to using bootconfig to embed the kernel's and > PID1's command line with the kernel image itself, and so allowing > changing that without modifying the bootloader, I noticed that > /proc/cmdline changed from e.g. > > console=ttymxc0,115200n8 cma=128M quiet -- --log-level=notice > > to > > console="ttymxc0,115200n8" cma="128M" quiet -- --log-level="notice" > > The kernel parameters are parsed just fine, and the quotes are indeed > stripped from the actual argv[] given to PID1. However, the quoting > doesn't really serve any purpose and looks excessive, and might > confuse some (naive) userspace tool trying to parse /proc/cmdline. So > do not quote the value unless it contains whitespace. > > Signed-off-by: Rasmus Villemoes > --- > > v2: use strpbrk(, " \t\r\n") instead of a loop doing isspace(). > Technically not quite equivalent, but much more readable, and it's > quite unlikely anybody has \f or \v or 0xa0 bytes in kernel command > line arguments. Perhaps \r and \n, and maybe even \t, could also be > dropped from that list, but those at least have some chance of > appearing in the wild. > > init/main.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/init/main.c b/init/main.c > index e24b0780fdff..3dd630132209 100644 > --- a/init/main.c > +++ b/init/main.c > @@ -324,7 +324,7 @@ static int __init xbc_snprint_cmdline(char *buf, size_t size, > { > struct xbc_node *knode, *vnode; > char *end = buf + size; > - const char *val; > + const char *val, *q; > int ret; > > xbc_node_for_each_key_value(root, knode, val) { > @@ -342,8 +342,9 @@ static int __init xbc_snprint_cmdline(char *buf, size_t size, > continue; > } > xbc_array_for_each_value(vnode, val) { > - ret = snprintf(buf, rest(buf, end), "%s=\"%s\" ", > - xbc_namebuf, val); Can you add a comment that why strpbrk(," \t\r\n") is used here? Such comment will help when we change how to parse the cmdline options. Thanks, > + q = strpbrk(val, " \t\r\n") ? "\"" : ""; > + ret = snprintf(buf, rest(buf, end), "%s=%s%s%s ", > + xbc_namebuf, q, val, q); > if (ret < 0) > return ret; > buf += ret; > -- > 2.40.1.1.g1c60b9335d > -- Masami Hiramatsu (Google)