* [PATCH 0/2] scripts/config: fix string handling in --set-str and --state @ 2026-11-30 7:52 Daniel Syauqi 2026-11-30 7:52 ` [PATCH 1/2] scripts/config: preserve ampersands in string values Daniel Syauqi 2026-11-30 7:52 ` [PATCH 2/2] scripts/config: print string values literally with --state Daniel Syauqi 0 siblings, 2 replies; 11+ messages in thread From: Daniel Syauqi @ 2026-11-30 7:52 UTC (permalink / raw) To: Nathan Chancellor, Nicolas Schier; +Cc: linux-kbuild, linux-kernel Two operations in scripts/config can silently change a string. When --set-str updates an existing assignment, an ampersand in the new value expands to the old config line. When --state reads a string such as "-n", echo consumes it as an option and the query writes no output. The first patch fixes the escaping on the update path. The second fixes readback and can be reproduced with a hand-written .config. Both failures were reproduced on v7.4-rc5 in an arm64 Lima guest. With the series applied, an out-of-tree arm64 defconfig retained the literal CMDLINE value "a=1&b=2" and LOCALVERSION "-n" across make olddefconfig. Chained --state queries returned both values, each on its own line. I used OpenAI Codex to identify both bugs, draft the fixes and commit messages, and run the tests in Lima. Daniel Syauqi (2): scripts/config: preserve ampersands in string values scripts/config: print string values literally with --state scripts/config | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244 ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/2] scripts/config: preserve ampersands in string values 2026-11-30 7:52 [PATCH 0/2] scripts/config: fix string handling in --set-str and --state Daniel Syauqi @ 2026-11-30 7:52 ` Daniel Syauqi 2026-12-01 7:53 ` sashiko-bot ` (2 more replies) 2026-11-30 7:52 ` [PATCH 2/2] scripts/config: print string values literally with --state Daniel Syauqi 1 sibling, 3 replies; 11+ messages in thread From: Daniel Syauqi @ 2026-11-30 7:52 UTC (permalink / raw) To: Nathan Chancellor, Nicolas Schier; +Cc: linux-kbuild, linux-kernel Setting CMDLINE to 'a=1&b=2' with --set-str works when the symbol is absent. When replacing an existing assignment, sed expands the ampersand to the entire matched line. The command succeeds but writes a different kernel command line. Embedded quotes from the old value can also truncate the string on the next olddefconfig. Escape backslashes and quotes when forming the Kconfig string and escape backslashes and ampersands when forming the sed replacement. This lets insertion and replacement write the same value, including when a backslash precedes an ampersand. Decode the escaped backslashes when reading the value back with --state. Fixes: 1f990cf94559 ("kbuild: add generic --set-str option to scripts/config") Signed-off-by: Daniel Syauqi <syauqicode@gmail.com> --- scripts/config | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/config b/scripts/config index 32428ea90..ba66b681d 100755 --- a/scripts/config +++ b/scripts/config @@ -86,9 +86,10 @@ txt_append() { txt_subst() { local before="$1" - local after="$2" + local after="${2//\\/\\\\}" local infile="$3" + after="${after//&/\\&}" sed -E -i.swp -e "s$SED_DELIM$before$SED_DELIM$after$SED_DELIM" "$infile" SED_EDITED=1 } @@ -186,8 +187,9 @@ while [ "$1" != "" ] ; do ;; --set-str) - # sed swallows one level of escaping, so we need double-escaping - set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${1//\"/\\\\\"}\"" + # Escape backslashes and double quotes in the Kconfig string. + value="${1//\\/\\\\}" + set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${value//\"/\\\"}\"" shift ;; @@ -211,6 +213,7 @@ while [ "$1" != "" ] ; do V="${V/#\"/}" V="${V/%\"/}" V="${V//\\\"/\"}" + V="${V//\\\\/\\}" echo "${V}" fi fi ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] scripts/config: preserve ampersands in string values 2026-11-30 7:52 ` [PATCH 1/2] scripts/config: preserve ampersands in string values Daniel Syauqi @ 2026-12-01 7:53 ` sashiko-bot 2026-12-01 18:05 ` Julian Braha 2026-12-01 18:06 ` Julian Braha 2 siblings, 0 replies; 11+ messages in thread From: sashiko-bot @ 2026-12-01 7:53 UTC (permalink / raw) To: Daniel Syauqi, Nathan Chancellor, Nicolas Schier; +Cc: linux-kbuild Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] scripts/config: broken backslash and ampersand escaping on Bash 5.2+ -- commit b78b433a507d0a53d91d8991945248e47628caf3 Author: Daniel Syauqi <syauqicode@gmail.com> scripts/config: preserve ampersands in string values This commit escapes backslashes, double quotes, and ampersands when setting Kconfig string values and running sed replacements in scripts/config, and unescapes backslashes when reading string values with --state. > diff --git a/scripts/config b/scripts/config > index 32428ea909c2c..ba66b681d7429 100755 > --- a/scripts/config > +++ b/scripts/config > @@ -86,9 +86,10 @@ txt_append() { > > txt_subst() { > local before="$1" > - local after="$2" > + local after="${2//\\/\\\\}" > local infile="$3" > > + after="${after//&/\\&}" > sed -E -i.swp -e "s$SED_DELIM$before$SED_DELIM$after$SED_DELIM" "$infile" > SED_EDITED=1 > } > @@ -186,8 +187,9 @@ while [ "$1" != "" ] ; do > ;; > > --set-str) > - # sed swallows one level of escaping, so we need double-escaping > - set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${1//\"/\\\\\"}\"" > + # Escape backslashes and double quotes in the Kconfig string. > + value="${1//\\/\\\\}" > + set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${value//\"/\\\"}\"" > shift > ;; [Severity: Low] Does the double-quoted ${...//.../...} replacement in txt_subst() and --set-str lose one level of backslash escaping on bash 5.2 and newer? Bash 5.2 enables the patsub_replacement shell option by default, where & in the replacement string expands to the match and \ escapes & and \. Outer double quotes around ${parameter//pattern/replacement} do not disable patsub_replacement; instead, the outer double quotes halve the backslashes first and patsub_replacement consumes the remaining escape. As a result, "${after//&/\\&}" leaves & unescaped for sed, and "${2//\\/\\\\}" and "${1//\\/\\\\}" collapse four backslashes to a single literal backslash, causing sed to expand & to the matched line or strip backslashes from escaped double quotes when updating an existing symbol. Quoting the replacement string itself (for example, ${after//&/"\\&"} and ${1//\\/"\\\\"}) or removing the outer double quotes prevents double-quote backslash reduction before patsub_replacement runs. -- Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796024119.git.syauqicode@gmail.com?part=1 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] scripts/config: preserve ampersands in string values 2026-11-30 7:52 ` [PATCH 1/2] scripts/config: preserve ampersands in string values Daniel Syauqi 2026-12-01 7:53 ` sashiko-bot @ 2026-12-01 18:05 ` Julian Braha 2026-12-01 18:06 ` Julian Braha 2 siblings, 0 replies; 11+ messages in thread From: Julian Braha @ 2026-12-01 18:05 UTC (permalink / raw) To: Daniel Syauqi, Nathan Chancellor, Nicolas Schier Cc: linux-kbuild, linux-kernel [-- Attachment #1.1: Type: text/plain, Size: 2716 bytes --] Hi Daniel, Thanks for raising this. On 11/30/26 07:52, Daniel Syauqi wrote: > Setting CMDLINE to 'a=1&b=2' with --set-str works when the symbol is (This 'a=1&b=2' example looks more like the end of a URL to me than a boot argument...) > absent. When replacing an existing assignment, sed expands the > ampersand to the entire matched line. The command succeeds but writes > a different kernel command line. Embedded quotes from the old value > can also truncate the string on the next olddefconfig. Improvements to input validation are good. But, there aren't any cases of ampersands or embedded quotes in the string constants in-tree, and I can't imagine any real-world cases where users might encounter this. > > Escape backslashes and quotes when forming the Kconfig string and > escape backslashes and ampersands when forming the sed replacement. > This lets insertion and replacement write the same value, including > when a backslash precedes an ampersand. Decode the escaped backslashes > when reading the value back with --state. > > Fixes: 1f990cf94559 ("kbuild: add generic --set-str option to scripts/config") > Signed-off-by: Daniel Syauqi <syauqicode@gmail.com> > --- > scripts/config | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/scripts/config b/scripts/config > index 32428ea90..ba66b681d 100755 > --- a/scripts/config > +++ b/scripts/config > @@ -86,9 +86,10 @@ txt_append() { > > txt_subst() { > local before="$1" > - local after="$2" > + local after="${2//\\/\\\\}" > local infile="$3" > > + after="${after//&/\\&}" > sed -E -i.swp -e "s$SED_DELIM$before$SED_DELIM$after$SED_DELIM" "$infile" > SED_EDITED=1 > } > @@ -186,8 +187,9 @@ while [ "$1" != "" ] ; do > ;; > > --set-str) > - # sed swallows one level of escaping, so we need double-escaping > - set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${1//\"/\\\\\"}\"" > + # Escape backslashes and double quotes in the Kconfig string. > + value="${1//\\/\\\\}" > + set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${value//\"/\\\"}\"" > shift > ;; Sashiko alarmed on this hunk regarding usage with bash 5.2, but it seems to be a classic AI hallucination. > > @@ -211,6 +213,7 @@ while [ "$1" != "" ] ; do > V="${V/#\"/}" > V="${V/%\"/}" > V="${V//\\\"/\"}" > + V="${V//\\\\/\\}" > echo "${V}" > fi > fi > These substitution changes further complicate some already tricky code (and lack a real-world example). But, the changes look technically correct to me, so: Tested-by: Julian Braha <julianbraha@gmail.com> Reviewed-by: Julian Braha <julianbraha@gmail.com> [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 236 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] scripts/config: preserve ampersands in string values 2026-11-30 7:52 ` [PATCH 1/2] scripts/config: preserve ampersands in string values Daniel Syauqi 2026-12-01 7:53 ` sashiko-bot 2026-12-01 18:05 ` Julian Braha @ 2026-12-01 18:06 ` Julian Braha 2026-12-02 2:01 ` Daniel Syauqi 2 siblings, 1 reply; 11+ messages in thread From: Julian Braha @ 2026-12-01 18:06 UTC (permalink / raw) To: Daniel Syauqi, Nathan Chancellor, Nicolas Schier Cc: linux-kbuild, linux-kernel [-- Attachment #1.1: Type: text/plain, Size: 2716 bytes --] Hi Daniel, Thanks for raising this. On 11/30/26 07:52, Daniel Syauqi wrote: > Setting CMDLINE to 'a=1&b=2' with --set-str works when the symbol is (This 'a=1&b=2' example looks more like the end of a URL to me than a boot argument...) > absent. When replacing an existing assignment, sed expands the > ampersand to the entire matched line. The command succeeds but writes > a different kernel command line. Embedded quotes from the old value > can also truncate the string on the next olddefconfig. Improvements to input validation are good. But, there aren't any cases of ampersands or embedded quotes in the string constants in-tree, and I can't imagine any real-world cases where users might encounter this. > > Escape backslashes and quotes when forming the Kconfig string and > escape backslashes and ampersands when forming the sed replacement. > This lets insertion and replacement write the same value, including > when a backslash precedes an ampersand. Decode the escaped backslashes > when reading the value back with --state. > > Fixes: 1f990cf94559 ("kbuild: add generic --set-str option to scripts/config") > Signed-off-by: Daniel Syauqi <syauqicode@gmail.com> > --- > scripts/config | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/scripts/config b/scripts/config > index 32428ea90..ba66b681d 100755 > --- a/scripts/config > +++ b/scripts/config > @@ -86,9 +86,10 @@ txt_append() { > > txt_subst() { > local before="$1" > - local after="$2" > + local after="${2//\\/\\\\}" > local infile="$3" > > + after="${after//&/\\&}" > sed -E -i.swp -e "s$SED_DELIM$before$SED_DELIM$after$SED_DELIM" "$infile" > SED_EDITED=1 > } > @@ -186,8 +187,9 @@ while [ "$1" != "" ] ; do > ;; > > --set-str) > - # sed swallows one level of escaping, so we need double-escaping > - set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${1//\"/\\\\\"}\"" > + # Escape backslashes and double quotes in the Kconfig string. > + value="${1//\\/\\\\}" > + set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${value//\"/\\\"}\"" > shift > ;; Sashiko alarmed on this hunk regarding usage with bash 5.2, but it seems to be a classic AI hallucination. > > @@ -211,6 +213,7 @@ while [ "$1" != "" ] ; do > V="${V/#\"/}" > V="${V/%\"/}" > V="${V//\\\"/\"}" > + V="${V//\\\\/\\}" > echo "${V}" > fi > fi > These substitution changes further complicate some already tricky code (and lack a real-world example). But, the changes look technically correct to me, so: Tested-by: Julian Braha <julianbraha@gmail.com> Reviewed-by: Julian Braha <julianbraha@gmail.com> [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 236 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] scripts/config: preserve ampersands in string values 2026-12-01 18:06 ` Julian Braha @ 2026-12-02 2:01 ` Daniel Syauqi 0 siblings, 0 replies; 11+ messages in thread From: Daniel Syauqi @ 2026-12-02 2:01 UTC (permalink / raw) To: julianbraha; +Cc: Nathan Chancellor, Nicolas Schier, linux-kbuild, linux-kernel Hi Julian, > (This 'a=1&b=2' example looks more like the end of a URL to me than a > boot argument...) Thanks for testing and reviewing this. You're right about the URL. In an arm64 Lima test, I used --set-str to change an existing CONFIG_CMDLINE from console=ttyAMA0 to netboot=https://boot.example/image?a=1&b=2. After make olddefconfig, the value ended at a=1CONFIG_CMDLINE=. With the patch, the full URL survived. This was a test case I constructed in Lima. Thanks, Daniel ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 2/2] scripts/config: print string values literally with --state 2026-11-30 7:52 [PATCH 0/2] scripts/config: fix string handling in --set-str and --state Daniel Syauqi 2026-11-30 7:52 ` [PATCH 1/2] scripts/config: preserve ampersands in string values Daniel Syauqi @ 2026-11-30 7:52 ` Daniel Syauqi 2026-12-01 18:06 ` Julian Braha 1 sibling, 1 reply; 11+ messages in thread From: Daniel Syauqi @ 2026-11-30 7:52 UTC (permalink / raw) To: Nathan Chancellor, Nicolas Schier; +Cc: linux-kbuild, linux-kernel With CONFIG_LOCALVERSION="-n", querying --state LOCALVERSION exits successfully without printing any bytes. Bash's echo interprets the decoded string as an option. Values such as "-e" yield only a newline. Use printf with a fixed format so that each query produces the value followed by a newline, including when multiple queries are chained. Fixes: d6686da814c8 ("scripts/config: properly report and set string options") Signed-off-by: Daniel Syauqi <syauqicode@gmail.com> --- scripts/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/config b/scripts/config index ba66b681d..143dae061 100755 --- a/scripts/config +++ b/scripts/config @@ -214,7 +214,7 @@ while [ "$1" != "" ] ; do V="${V/%\"/}" V="${V//\\\"/\"}" V="${V//\\\\/\\}" - echo "${V}" + printf '%s\n' "$V" fi fi ;; ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] scripts/config: print string values literally with --state 2026-11-30 7:52 ` [PATCH 2/2] scripts/config: print string values literally with --state Daniel Syauqi @ 2026-12-01 18:06 ` Julian Braha 2026-12-01 18:12 ` Randy Dunlap 2026-12-02 2:01 ` Daniel Syauqi 0 siblings, 2 replies; 11+ messages in thread From: Julian Braha @ 2026-12-01 18:06 UTC (permalink / raw) To: Daniel Syauqi, Nathan Chancellor, Nicolas Schier Cc: linux-kbuild, linux-kernel [-- Attachment #1.1: Type: text/plain, Size: 1187 bytes --] On 11/30/26 07:52, Daniel Syauqi wrote: > With CONFIG_LOCALVERSION="-n", querying --state LOCALVERSION exits Again, this example is quite contrived. > successfully without printing any bytes. Bash's echo interprets the > decoded string as an option. Values such as "-e" yield only a newline. > > Use printf with a fixed format so that each query produces the value > followed by a newline, including when multiple queries are chained. > > Fixes: d6686da814c8 ("scripts/config: properly report and set string options") I don't think improvements in input validation warrants a Fixes tag. > Signed-off-by: Daniel Syauqi <syauqicode@gmail.com> > --- > scripts/config | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/scripts/config b/scripts/config > index ba66b681d..143dae061 100755 > --- a/scripts/config > +++ b/scripts/config > @@ -214,7 +214,7 @@ while [ "$1" != "" ] ; do > V="${V/%\"/}" > V="${V//\\\"/\"}" > V="${V//\\\\/\\}" > - echo "${V}" > + printf '%s\n' "$V" > fi > fi > ;; > Tested-by: Julian Braha <julianbraha@gmail.com> Reviewed-by: Julian Braha <julianbraha@gmail.com> [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 236 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] scripts/config: print string values literally with --state 2026-12-01 18:06 ` Julian Braha @ 2026-12-01 18:12 ` Randy Dunlap 2026-12-01 18:26 ` Julian Braha 2026-12-02 2:01 ` Daniel Syauqi 1 sibling, 1 reply; 11+ messages in thread From: Randy Dunlap @ 2026-12-01 18:12 UTC (permalink / raw) To: Julian Braha, Daniel Syauqi, Nathan Chancellor, Nicolas Schier Cc: linux-kbuild, linux-kernel On 12/1/26 10:06 AM, Julian Braha wrote: > On 11/30/26 07:52, Daniel Syauqi wrote: >> With CONFIG_LOCALVERSION="-n", querying --state LOCALVERSION exits > > Again, this example is quite contrived. Only because "-n" is short. :) More realistic would be: -next-20261201 >> successfully without printing any bytes. Bash's echo interprets the >> decoded string as an option. Values such as "-e" yield only a newline. -- ~Randy ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] scripts/config: print string values literally with --state 2026-12-01 18:12 ` Randy Dunlap @ 2026-12-01 18:26 ` Julian Braha 0 siblings, 0 replies; 11+ messages in thread From: Julian Braha @ 2026-12-01 18:26 UTC (permalink / raw) To: Randy Dunlap, Daniel Syauqi, Nathan Chancellor, Nicolas Schier Cc: linux-kbuild, linux-kernel [-- Attachment #1.1: Type: text/plain, Size: 527 bytes --] On 12/1/26 18:12, Randy Dunlap wrote: > > On 12/1/26 10:06 AM, Julian Braha wrote: >> On 11/30/26 07:52, Daniel Syauqi wrote: >>> With CONFIG_LOCALVERSION="-n", querying --state LOCALVERSION exits >> Again, this example is quite contrived. > Only because "-n" is short. :) > More realistic would be: > -next-20261201 No your example wouldn't work here ;) echo won't process any of "-next" as flags, because it contains non-flag character 'x' after the 'n' and 'e' (those two could be flags). - Julian Braha [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 236 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] scripts/config: print string values literally with --state 2026-12-01 18:06 ` Julian Braha 2026-12-01 18:12 ` Randy Dunlap @ 2026-12-02 2:01 ` Daniel Syauqi 1 sibling, 0 replies; 11+ messages in thread From: Daniel Syauqi @ 2026-12-02 2:01 UTC (permalink / raw) To: julianbraha; +Cc: Nathan Chancellor, Nicolas Schier, linux-kbuild, linux-kernel Hi Julian, > I don't think improvements in input validation warrants a Fixes tag. Thanks for testing this one too. I included Fixes because CONFIG_LOCALVERSION="-n" is a valid string. With that value already in .config, --state LOCALVERSION exits successfully and writes zero bytes. That drops a whole line when several queries are chained. I traced the zero-byte output to d6686da814c8 ("scripts/config: properly report and set string options"). Thanks, Daniel ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-12-02 2:01 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-30 7:52 [PATCH 0/2] scripts/config: fix string handling in --set-str and --state Daniel Syauqi 2026-11-30 7:52 ` [PATCH 1/2] scripts/config: preserve ampersands in string values Daniel Syauqi 2026-12-01 7:53 ` sashiko-bot 2026-12-01 18:05 ` Julian Braha 2026-12-01 18:06 ` Julian Braha 2026-12-02 2:01 ` Daniel Syauqi 2026-11-30 7:52 ` [PATCH 2/2] scripts/config: print string values literally with --state Daniel Syauqi 2026-12-01 18:06 ` Julian Braha 2026-12-01 18:12 ` Randy Dunlap 2026-12-01 18:26 ` Julian Braha 2026-12-02 2:01 ` Daniel Syauqi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox