[PATCH v2 0/5] kconfig: improve input validation for numeric options

Julian Braha posted 5 patches 1 week, 2 days ago
scripts/kconfig/confdata.c                    |  6 ++
scripts/kconfig/lkc.h                         |  2 +-
scripts/kconfig/lkc_proto.h                   |  1 +
scripts/kconfig/menu.c                        | 62 ++++++++++-----
scripts/kconfig/parser.y                      |  2 +-
scripts/kconfig/symbol.c                      | 61 +++++++++++---
scripts/kconfig/tests/err_num_bounds/Kconfig  | 79 +++++++++++++++++++
.../kconfig/tests/err_num_bounds/__init__.py  | 12 +++
.../tests/err_num_bounds/expected_stderr      | 10 +++
.../kconfig/tests/err_num_mismatch/Kconfig    | 38 +++++++++
.../tests/err_num_mismatch/__init__.py        |  9 +++
.../tests/err_num_mismatch/expected_stderr    |  4 +
.../tests/err_num_non_numeric_ref/Kconfig     | 75 ++++++++++++++++++
.../tests/err_num_non_numeric_ref/__init__.py |  9 +++
.../err_num_non_numeric_ref/expected_stderr   | 16 ++++
.../kconfig/tests/warn_changed_input/Kconfig  |  5 ++
.../tests/warn_changed_input/expected_config  |  1 +
scripts/kconfig/tests/warn_num_bounds/Kconfig | 24 ++++++
.../kconfig/tests/warn_num_bounds/__init__.py | 25 ++++++
scripts/kconfig/tests/warn_num_bounds/config  |  7 ++
.../tests/warn_num_bounds/expected_config     | 11 +++
.../warn_num_bounds/expected_config_stderr    |  3 +
.../warn_num_bounds/expected_frontend_config  | 11 +++
.../warn_num_bounds/expected_frontend_stderr  |  0
24 files changed, 442 insertions(+), 31 deletions(-)
create mode 100644 scripts/kconfig/tests/err_num_bounds/Kconfig
create mode 100644 scripts/kconfig/tests/err_num_bounds/__init__.py
create mode 100644 scripts/kconfig/tests/err_num_bounds/expected_stderr
create mode 100644 scripts/kconfig/tests/err_num_mismatch/Kconfig
create mode 100644 scripts/kconfig/tests/err_num_mismatch/__init__.py
create mode 100644 scripts/kconfig/tests/err_num_mismatch/expected_stderr
create mode 100644 scripts/kconfig/tests/err_num_non_numeric_ref/Kconfig
create mode 100644 scripts/kconfig/tests/err_num_non_numeric_ref/__init__.py
create mode 100644 scripts/kconfig/tests/err_num_non_numeric_ref/expected_stderr
create mode 100644 scripts/kconfig/tests/warn_num_bounds/Kconfig
create mode 100644 scripts/kconfig/tests/warn_num_bounds/__init__.py
create mode 100644 scripts/kconfig/tests/warn_num_bounds/config
create mode 100644 scripts/kconfig/tests/warn_num_bounds/expected_config
create mode 100644 scripts/kconfig/tests/warn_num_bounds/expected_config_stderr
create mode 100644 scripts/kconfig/tests/warn_num_bounds/expected_frontend_config
create mode 100644 scripts/kconfig/tests/warn_num_bounds/expected_frontend_stderr
[PATCH v2 0/5] kconfig: improve input validation for numeric options
Posted by Julian Braha 1 week, 2 days ago
This series improves checks for invalid values of 'int' and 'hex' config
options in the Kconfig interpreter.

Tests are added for all new warnings and errors.

Patch 1/5 promotes an existing warning to an error, for attempting to use
a non-numeric option to set a numeric option's value. This warning did not
have a test, but one is added with the promotion to error.

Patch 2/5 adds a check that the constant values for numerics are within
the bounds of the type (64-bit signed integer for 'int', and 64-bit
unsigned integer for 'hex'). This prevents silent failures, for example in
comparisons.

Patch 3/5 adds a check that 'int' and 'hex' options aren't used to set
each other's values. Since the values are naively reused from their
internal string representations, this currently also leads to later silent
failures.

Patch 4/5 rejects out-of-bounds numeric values from the Kconfig
frontends and adds a warning upon reading in an existing .config file
with one of these values. In the future, this warning should be promoted
to an error.

Finally, patch 5/5 fixes an existing issue where checks on 'range' values
for hex options parsed them as signed integers using 'strtoll' instead of
'strtoull'.

Signed-off-by: Julian Braha <julianbraha@gmail.com>
---
Changes since v1:
- unified formatting of int/hex messages in patch 4 (Nathan)
- added a 5th patch for the hex range issue (Nathan/Sashiko)

Link to v1:
https://lore.kernel.org/all/20260829171902.1510587-1-julianbraha@gmail.com/
---
Julian Braha (5):
  kconfig: promote invalid numeric reference from warning to error
  kconfig: check for out-of-bounds numeric constants
  kconfig: check for hex and int mismatches
  kconfig: prevent out-of-bounds user input for numeric options
  kconfig: use unsigned integers for hex range checks

 scripts/kconfig/confdata.c                    |  6 ++
 scripts/kconfig/lkc.h                         |  2 +-
 scripts/kconfig/lkc_proto.h                   |  1 +
 scripts/kconfig/menu.c                        | 62 ++++++++++-----
 scripts/kconfig/parser.y                      |  2 +-
 scripts/kconfig/symbol.c                      | 61 +++++++++++---
 scripts/kconfig/tests/err_num_bounds/Kconfig  | 79 +++++++++++++++++++
 .../kconfig/tests/err_num_bounds/__init__.py  | 12 +++
 .../tests/err_num_bounds/expected_stderr      | 10 +++
 .../kconfig/tests/err_num_mismatch/Kconfig    | 38 +++++++++
 .../tests/err_num_mismatch/__init__.py        |  9 +++
 .../tests/err_num_mismatch/expected_stderr    |  4 +
 .../tests/err_num_non_numeric_ref/Kconfig     | 75 ++++++++++++++++++
 .../tests/err_num_non_numeric_ref/__init__.py |  9 +++
 .../err_num_non_numeric_ref/expected_stderr   | 16 ++++
 .../kconfig/tests/warn_changed_input/Kconfig  |  5 ++
 .../tests/warn_changed_input/expected_config  |  1 +
 scripts/kconfig/tests/warn_num_bounds/Kconfig | 24 ++++++
 .../kconfig/tests/warn_num_bounds/__init__.py | 25 ++++++
 scripts/kconfig/tests/warn_num_bounds/config  |  7 ++
 .../tests/warn_num_bounds/expected_config     | 11 +++
 .../warn_num_bounds/expected_config_stderr    |  3 +
 .../warn_num_bounds/expected_frontend_config  | 11 +++
 .../warn_num_bounds/expected_frontend_stderr  |  0
 24 files changed, 442 insertions(+), 31 deletions(-)
 create mode 100644 scripts/kconfig/tests/err_num_bounds/Kconfig
 create mode 100644 scripts/kconfig/tests/err_num_bounds/__init__.py
 create mode 100644 scripts/kconfig/tests/err_num_bounds/expected_stderr
 create mode 100644 scripts/kconfig/tests/err_num_mismatch/Kconfig
 create mode 100644 scripts/kconfig/tests/err_num_mismatch/__init__.py
 create mode 100644 scripts/kconfig/tests/err_num_mismatch/expected_stderr
 create mode 100644 scripts/kconfig/tests/err_num_non_numeric_ref/Kconfig
 create mode 100644 scripts/kconfig/tests/err_num_non_numeric_ref/__init__.py
 create mode 100644 scripts/kconfig/tests/err_num_non_numeric_ref/expected_stderr
 create mode 100644 scripts/kconfig/tests/warn_num_bounds/Kconfig
 create mode 100644 scripts/kconfig/tests/warn_num_bounds/__init__.py
 create mode 100644 scripts/kconfig/tests/warn_num_bounds/config
 create mode 100644 scripts/kconfig/tests/warn_num_bounds/expected_config
 create mode 100644 scripts/kconfig/tests/warn_num_bounds/expected_config_stderr
 create mode 100644 scripts/kconfig/tests/warn_num_bounds/expected_frontend_config
 create mode 100644 scripts/kconfig/tests/warn_num_bounds/expected_frontend_stderr

-- 
2.55.0
Re: [PATCH v2 0/5] kconfig: improve input validation for numeric options
Posted by Nathan Chancellor 1 week ago
On Tue, 15 Sep 2026 22:15:03 +0100, Julian Braha wrote:
> kconfig: improve input validation for numeric options
> 
> This series improves checks for invalid values of 'int' and 'hex' config
> options in the Kconfig interpreter.
> 
> Tests are added for all new warnings and errors.
> 
> [...]

Applied to

  https://git.kernel.org/pub/scm/linux/kernel/git/kbuild/linux.git kbuild-next-unstable

Thanks!

[1/5] kconfig: promote invalid numeric reference from warning to error
      https://git.kernel.org/kbuild/c/95fde4bcc0b7c
[2/5] kconfig: check for out-of-bounds numeric constants
      https://git.kernel.org/kbuild/c/a5e84d6f6df1f
[3/5] kconfig: check for hex and int mismatches
      https://git.kernel.org/kbuild/c/d13bad83d89d1
[4/5] kconfig: prevent out-of-bounds user input for numeric options
      https://git.kernel.org/kbuild/c/54f11924e4854
[5/5] kconfig: use unsigned integers for hex range checks
      https://git.kernel.org/kbuild/c/9b8719973ee2c

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,
-- 
Cheers,
Nathan