From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Sasha Levin <sashal@kernel.org>
Cc: stable@vger.kernel.org,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Masami Hiramatsu <mhiramat@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 5.15.y 1/3] bootconfig: do not put quotes on cmdline items unless necessary
Date: Wed, 29 Jul 2026 08:34:59 +0900 [thread overview]
Message-ID: <20260729083459.366013da57b7df11f5e8638e@kernel.org> (raw)
In-Reply-To: <20260728221750.745951-1-sashal@kernel.org>
Thanks Sasha for backporting the series!
These look good to me!
On Tue, 28 Jul 2026 18:17:48 -0400
Sasha Levin <sashal@kernel.org> wrote:
> From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
>
> [ Upstream commit 212f863fa8811c780abacc1d0404c573fdc0a2de ]
>
> 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.
>
> Link: https://lkml.kernel.org/r/20240320101952.62135-1-linux@rasmusvillemoes.dk
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Stable-dep-of: dec4d8118c17 ("bootconfig: fix NULL-pointer arithmetic in xbc_snprint_cmdline()")
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> init/main.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/init/main.c b/init/main.c
> index 4e9c76a0e5a478..f9e98fb3a3e098 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -328,7 +328,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) {
> @@ -346,8 +346,14 @@ 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);
> + /*
> + * For prettier and more readable /proc/cmdline, only
> + * quote the value when necessary, i.e. when it contains
> + * whitespace.
> + */
> + 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.53.0
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
prev parent reply other threads:[~2026-07-28 23:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 8:57 FAILED: patch "[PATCH] bootconfig: fix NULL-pointer arithmetic in" failed to apply to 5.15-stable tree gregkh
2026-07-28 22:17 ` [PATCH 5.15.y 1/3] bootconfig: do not put quotes on cmdline items unless necessary Sasha Levin
2026-07-28 22:17 ` [PATCH 5.15.y 2/3] bootconfig: move xbc_snprint_cmdline() to lib/bootconfig.c Sasha Levin
2026-07-28 22:17 ` [PATCH 5.15.y 3/3] bootconfig: fix NULL-pointer arithmetic in xbc_snprint_cmdline() Sasha Levin
2026-07-28 23:34 ` Masami Hiramatsu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260729083459.366013da57b7df11f5e8638e@kernel.org \
--to=mhiramat@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux@rasmusvillemoes.dk \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).