kconfig: fix potential NULL pointer dereference in conf_askvalue()
PATCH v2 1/1 kconfig: fix potential NULL pointer dereference in conf_askvalue()
In conf_askvalue(), the 'def' argument (retrieved via sym_get_string_value) can be NULL. While current call sites ensure that 'def' is valid, calling printf("%s\n", def) is technically undefined behavior and could lead to a segmentation fault on certain libc implementations if the function were called with a NULL pointer in the future.
Improve the robustness of conf_askvalue() by providing an empty string as a fallback.
Additionally, remove the redundant re-initialization of the 'line' buffer inside the !sym_is_changeable(sym) block, as it is already properly initialized at the function entry.
---
v2:
- Change commit message and use fewer characters in modify.
- Link to v1: https://lore.kernel.org/all/[email protected]/
scripts/kconfig/conf.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
scripts/kconfig/conf.c +2 -4
@@ -297,9 +297,7 @@ static int conf_askvalue(struct symbol *sym, const char *def) line[1 ] =0 ;if (!sym_is_changeable (sym)) { -printf ("%s\n" , def); - line[0 ] ='\n' ; - line[1 ] =0 ; + printf("%s\n", def :? "");return 0 ; }
@@ -307,7 +305,7 @@ static int conf_askvalue(struct symbol *sym, const char *def)case oldconfig:case syncconfig:if (sym_has_value (sym)) { -printf ("%s\n" , def); + printf("%s\n", def :? "");return 0 ; }/* fall through */
Signature · 1 line
2.25.1
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Xingjing,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on masahiroy-kbuild/for-next masahiroy-kbuild/fixes v7.0-rc1 next-20260227] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Xingjing-Deng/kconfig-fix-potential-NULL-pointer-dereference-in-conf_askvalue/20260301-133159 base: linus/master patch link: https://lore.kernel.org/r/20260301053035.1950087-1-micro6947%40gmail.com patch subject: [PATCH v2] kconfig: fix potential NULL pointer dereference in conf_askvalue() config: x86_64-kexec (attached as .config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260301/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> scripts/kconfig/conf.c:300:22: error: expected ')'
300 | printf("%s\n", def :? "");
| ^
scripts/kconfig/conf.c:300:9: note: to match this '('
300 | printf("%s\n", def :? "");
| ^
scripts/kconfig/conf.c:308:23: error: expected ')'
308 | printf("%s\n", def :? "");
| ^
scripts/kconfig/conf.c:308:10: note: to match this '('
308 | printf("%s\n", def :? "");
| ^ 2 errors generated.
make[3]: *** [scripts/Makefile.host:131: scripts/kconfig/conf.o] Error 1 make[3]: Target 'oldconfig' not remade because of errors. make[2]: *** [Makefile:746: oldconfig] Error 2
make[1]: *** [Makefile:248: __sub-make] Error 2
make[1]: Target 'oldconfig' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'oldconfig' not remade because of errors.
--
>> scripts/kconfig/conf.c:300:22: error: expected ')'
300 | printf("%s\n", def :? "");
| ^
scripts/kconfig/conf.c:300:9: note: to match this '('
300 | printf("%s\n", def :? "");
| ^
scripts/kconfig/conf.c:308:23: error: expected ')'
308 | printf("%s\n", def :? "");
| ^
scripts/kconfig/conf.c:308:10: note: to match this '('
308 | printf("%s\n", def :? "");
| ^ 2 errors generated.
make[3]: *** [scripts/Makefile.host:131: scripts/kconfig/conf.o] Error 1 make[3]: Target 'olddefconfig' not remade because of errors. make[2]: *** [Makefile:746: olddefconfig] Error 2
make[1]: *** [Makefile:248: __sub-make] Error 2
make[1]: Target 'olddefconfig' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'olddefconfig' not remade because of errors.
vim +300 scripts/kconfig/conf.c
290
291 static int conf_askvalue(struct symbol *sym, const char *def)
292 {
293 if (!sym_has_value(sym))
294 printf("(NEW) ");
295
296 line[0] = '\n';
297 line[1] = 0;
298
299 if (!sym_is_changeable(sym)) {
> 300 printf("%s\n", def :? ""); 301 return 0;
302 }
303
304 switch (input_mode) {
305 case oldconfig:
306 case syncconfig:
307 if (sym_has_value(sym)) {
308 printf("%s\n", def :? "");
309 return 0;
310 }
311 /* fall through */
312 default:
313 fflush(stdout);
314 xfgets(line, sizeof(line), stdin);
315 break;
316 }
317
318 return 1;
319 }
320
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Xingjing,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v7.0-rc1 next-20260227]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Xingjing-Deng/kconfig-fix-potential-NULL-pointer-dereference-in-conf_askvalue/20260301-133159 base: linus/master patch link: https://lore.kernel.org/r/20260301053035.1950087-1-micro6947%40gmail.com patch subject: [PATCH v2] kconfig: fix potential NULL pointer dereference in conf_askvalue() config: x86_64-rhel-9.4 (attached as .config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260302/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
scripts/kconfig/conf.c: In function 'conf_askvalue':
>> scripts/kconfig/conf.c:300:35: error: expected ')' before ':' token
300 | printf("%s\n", def :? "");
| ~ ^~
| )
scripts/kconfig/conf.c:308:43: error: expected ')' before ':' token
308 | printf("%s\n", def :? "");
| ~ ^~
| ) make[3]: *** [scripts/Makefile.host:131: scripts/kconfig/conf.o] Error 1 make[3]: Target 'oldconfig' not remade because of errors. make[2]: *** [Makefile:746: oldconfig] Error 2
make[1]: *** [Makefile:248: __sub-make] Error 2
make[1]: Target 'oldconfig' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'oldconfig' not remade because of errors.
--
scripts/kconfig/conf.c: In function 'conf_askvalue':
>> scripts/kconfig/conf.c:300:35: error: expected ')' before ':' token
300 | printf("%s\n", def :? "");
| ~ ^~
| )
scripts/kconfig/conf.c:308:43: error: expected ')' before ':' token
308 | printf("%s\n", def :? "");
| ~ ^~
| ) make[3]: *** [scripts/Makefile.host:131: scripts/kconfig/conf.o] Error 1 make[3]: Target 'olddefconfig' not remade because of errors. make[2]: *** [Makefile:746: olddefconfig] Error 2
make[1]: *** [Makefile:248: __sub-make] Error 2
make[1]: Target 'olddefconfig' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'olddefconfig' not remade because of errors.
vim +300 scripts/kconfig/conf.c
290
291 static int conf_askvalue(struct symbol *sym, const char *def)
292 {
293 if (!sym_has_value(sym))
294 printf("(NEW) ");
295
296 line[0] = '\n';
297 line[1] = 0;
298
299 if (!sym_is_changeable(sym)) {
> 300 printf("%s\n", def :? ""); 301 return 0;
302 }
303
304 switch (input_mode) {
305 case oldconfig:
306 case syncconfig:
307 if (sym_has_value(sym)) {
308 printf("%s\n", def :? "");
309 return 0;
310 }
311 /* fall through */
312 default:
313 fflush(stdout);
314 xfgets(line, sizeof(line), stdin);
315 break;
316 }
317
318 return 1;
319 }
320
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 29 lines · Xingjing Deng
In
conf_askvalue(), the 'def' argument (retrieved viasym_get_string_value) can be NULL. While current call sites ensure that 'def' is valid, callingprintf("%s\n", def)is technically undefined behavior and could lead to a segmentation fault on certain libc implementations if the function were called with a NULL pointer in the future.Improve the robustness of
conf_askvalue()by providing an empty string as a fallback.Additionally, remove the redundant re-initialization of the 'line' buffer inside the !sym_is_changeable(sym) block, as it is already properly initialized at the function entry.
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Signed-off-by Xingjing Deng <[email protected]>---
v2:
- Change commit message and use fewer characters in modify.
- Link to v1: https://lore.kernel.org/all/[email protected]/scripts/kconfig/conf.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)scripts/kconfig/conf.c +0
-0
scripts/kconfig/conf.c static int conf_askvalue(struct symbol *sym, const char *def) · line 300
Quoted 7 lines
scripts/kconfig/conf.c +1
-3@@ -297,9 +297,7 @@ static int conf_askvalue(struct symbol *sym, const char *def) line[1 ] =0 ;if (!sym_is_changeable (sym)) { -printf ("%s\n" , def); - line[0 ] ='\n' ; - line[1 ] =0 ; + printf("%s\n", def :? "");
As the kernel test robot pointed out, this should be ?:, not :?. Please ensure you always test build your changes before sending them out, especially scripts/kconfig since it runs so early in the build.
When sending a corrected v3, you can include:
Quoted 15 lines
scripts/kconfig/conf.c +1
-1return 0 ; }@@ -307,7 +305,7 @@ static int conf_askvalue(struct symbol *sym, const char *def)case oldconfig:case syncconfig:if (sym_has_value (sym)) { -printf ("%s\n" , def); + printf("%s\n", def :? "");return 0 ; }/* fall through */ Signature · 1 line
2.25.1