kconfig: fix infinite loop in conf_choice() when no choice value is visible
PATCH v2 1/1 kconfig: fix infinite loop in conf_choice() when no choice value is visible
If a choice is visible but none of its choice values is, conf_choice() counts cnt == 0 visible values and finds no default. When the choice has to be asked, e.g. because a new symbol was added to the same menu (oldconfig, syncconfig) or because stdin is at EOF (oldaskconfig), the loop that maps the answer to a menu entry never finds one and the while (1) loop repeats forever, printing "choice[1-0?]: 0" each time.
This happens in the tree for s390 when the compiler supports none of the -march=z* options (e.g. a non-s390 host compiler), so that all values of the "Processor type" choice are invisible:
$ make ARCH=s390 defconfig $ sed -i '/^CONFIG_NR_CPUS=/d' .config $ make ARCH=s390 oldconfig # hangs
Before the removal of tristate choice support, conf_choice() returned early in this case. Do the same when there is no visible choice value.
Found by fuzzing Kconfig input with ASan/UBSan.
---
v2:
- Use my real name in the From and Signed-off-by lines. No code changes.
v1: https://lore.kernel.org/r/[email protected]
scripts/kconfig/conf.c | 3 +++ 1 file changed, 3 insertions(+)
scripts/kconfig/conf.c +3 -0
@@ -483,6 +483,9 @@ static void conf_choice(struct menu *menu) }printf ("\n" ); } +/* Nothing to ask if none of the choice values is visible. */ +if (!cnt) +return ;printf ("%*schoice" , indent -1 ,"" );if (cnt ==1 ) {printf ("[1]: 1\n" );
Signature · 1 line
2.34.1
Quoted 15 lines · Leizhen Zhang
If a choice is visible but none of its choice values is,
conf_choice()counts cnt == 0 visible values and finds no default. When the choice has to be asked, e.g. because a new symbol was added to the same menu (oldconfig, syncconfig) or because stdin is at EOF (oldaskconfig), the loop that maps the answer to a menu entry never finds one and the while (1) loop repeats forever, printing "choice[1-0?]: 0" each time.This happens in the tree for s390 when the compiler supports none of the -march=z* options (e.g. a non-s390 host compiler), so that all values of the "Processor type" choice are invisible:
$ make ARCH=s390 defconfig $ sed -i '/^CONFIG_NR_CPUS=/d' .config $ make ARCH=s390 oldconfig # hangs
Quoted 8 lines
Before the removal of tristate choice support,
conf_choice()returned early in this case. Do the same when there is no visible choice value.Found by fuzzing
Kconfiginput with ASan/UBSan.Fixes fde192511bdb ("kconfig: remove tristate choice support")Assisted-by Claude:claude-opus-5-5 libFuzzerSigned-off-by Leizhen Zhang <[email protected]>
Nathan Chancellor
maintainerQuoted 1 line · Leizhen Zhang
kconfig: fix infinite loop in
conf_choice()when no choice value is visible
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/kbuild/linux.git kbuild-next-unstable
Thanks!
[1/1] kconfig: fix infinite loop in conf_choice() when no choice value is visible
https://git.kernel.org/kbuild/c/52f26261e27db
Please look out for regression or issue reports or other follow up comments, as they may result in the patch/series getting dropped or reverted. Patches applied to an "unstable" branch are accepted pending wider testing in -next and any post-commit review; they will generally be moved to the main branch in a week if no issues are found.
Best regards,
Signature · 2 lines
Cheers, Nathan