From: Julian Braha <julianbraha@gmail.com>
To: Dmitrii Tulnov <tulnov.dl@gmail.com>, nathan@kernel.org, nsc@kernel.org
Cc: jacmet@uclibc.org, yann.morin.1998@free.fr,
linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] kconfig: warn about malformed KCONFIG_PROBABILITY values
Date: Thu, 10 Sep 2026 22:17:57 +0100 [thread overview]
Message-ID: <55e18f27-0ba1-433e-b4dc-a7db70172f7a@gmail.com> (raw)
In-Reply-To: <20260910120442.26-1-tulnov.dl@gmail.com>
On 9/10/26 13:04, Dmitrii Tulnov wrote:
> randconfig checks the numeric range of each probability but does not
> validate where strtol() stops. For example, KCONFIG_PROBABILITY=50% is
> accepted as 50:0:0: the '%' is parsed repeatedly as zero. For the
> documented value 50, tristate y/m/n probabilities are 25%/25%/50%.
> With 50%, both y/m probabilities silently become zero, reducing the
> coverage of random configuration builds. Empty fields and extra fields
> are also accepted.
>
> Warn when the value does not follow the documented decimal format. For
> malformed inputs whose parsed probabilities are in range, preserve the
> existing interpretation unless KCONFIG_WERROR is set. In that case, exit
> with an error before writing the configuration. Leading whitespace and
> signs are accepted by strtol(), but also trigger the warning because they
> are outside the documented format.
>
> Keep the strtol() result as long until the range check. This rejects
> out-of-range values that narrowing to int previously made valid, such as
> 4294967296 becoming zero on a 64-bit host, regardless of KCONFIG_WERROR.
>
> Add regression tests for one warning per malformed input, preserved
> configurations, KCONFIG_WERROR, out-of-range values, the supported
> probability formats, and the documented empty-value default.
>
> Fixes: e43956e60769 ("kconfig: implement KCONFIG_PROBABILITY for randconfig")
> Assisted-by: LLM
> Signed-off-by: Dmitrii Tulnov <tulnov.dl@gmail.com>
> ---
> Changes since v2:
> - Move the expected tristate distribution into the problem description.
> - Simplify the initial format check to !isdigit((unsigned char)*env).
> - Pass probability values and seeds through conf._run_conf(extra_env=...).
> Use monkeypatch.delenv only to remove inherited variables.
> - Add -0, +0, bare + and - warning cases, and the +101 range-error case.
> - Honor KCONFIG_WERROR for malformed format warnings, as discussed with
> Julian. Check unset, empty, 0 and 1 flag behavior.
> - Compare 50% with 50:0:0 and -0 with 0 across 20 fixed seeds and check
> that each malformed input produces exactly one warning.
> - Clarify that compatibility applies to malformed in-range inputs with
> KCONFIG_WERROR unset; values previously accepted by narrowing now fail.
>
> Changes since v1:
> - Warn about malformed in-range values while retaining their previous
> interpretation by default.
> - Warn about leading whitespace and signs as undocumented input.
> - Clarify that 50 gives tristate y/m/n probabilities of 25%/25%/50%, and
> compare it with the equivalent input 50:25:25 across 20 fixed seeds.
>
> Validation on kbuild-next, x86_64, GCC 13.3.0:
> - make testconfig with HOSTCFLAGS=-Werror: 138 passed. With the unpatched
> conf: 74 failed, 64 passed; failures cover missing format warnings,
> unchecked narrowing and ignored KCONFIG_WERROR. The previous v3 draft
> fails only the nine strict-mode regression cases; 129 tests pass.
> - ASan/UBSan at -O1, with leak detection disabled: the same 138 tests passed.
> - Both v3 builds matched the submitted v2 on 1,635 inputs: 916 accepted
> values and 719 range errors, with KCONFIG_WERROR unset. Each also matched
> the original on 380 documented-input comparisons with fixed seeds.
> - Each build passed 120 strict format-error checks: no output created in
> a fresh directory; existing .config, .config.old and input files stayed
> unchanged, including with KCONFIG_ALLCONFIG and KCONFIG_OVERWRITECONFIG.
> Valid inputs, range diagnostics and other configuration modes were also
> checked with KCONFIG_WERROR set.
> - The probability tests also passed with conflicting probability and seed
> values and KCONFIG_WERROR=1 inherited from the test runner's environment.
> - make defconfig, allnoconfig, allmodconfig and valid randconfig passed.
> KCONFIG_PROBABILITY=50% now produces a warning and remains compatible.
> - No vmlinux build or boot test; this changes the host configuration tool.
> 32-bit hosts and other libc implementations were not tested.
>
> scripts/kconfig/conf.c | 16 +-
> .../tests/randconfig_probability/Kconfig | 12 ++
> .../tests/randconfig_probability/__init__.py | 137 ++++++++++++++++++
> 3 files changed, 164 insertions(+), 1 deletion(-)
> create mode 100644 scripts/kconfig/tests/randconfig_probability/Kconfig
> create mode 100644 scripts/kconfig/tests/randconfig_probability/__init__.py
>
> diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
> index fe8ba09b0..ca6d9d735 100644
> --- a/scripts/kconfig/conf.c
> +++ b/scripts/kconfig/conf.c
> @@ -186,12 +186,23 @@ static void conf_set_all_new_symbols(enum conf_def_mode mode)
>
> if (mode == def_random) {
> int n, p[3];
> + bool warned = false;
> char *env = getenv("KCONFIG_PROBABILITY");
>
> n = 0;
> while (env && *env) {
> char *endp;
> - int tmp = strtol(env, &endp, 10);
> + long tmp = strtol(env, &endp, 10);
> +
> + if (!isdigit((unsigned char)*env) ||
> + (*endp && *endp != ':') ||
> + (*endp == ':' && (!endp[1] || n == 2))) {
> + if (!warned) {
> + fprintf(stderr,
> + "warning: KCONFIG_PROBABILITY has malformed format\n");
> + warned = true;
> + }
> + }
>
> if (tmp >= 0 && tmp <= 100) {
> p[n++] = tmp;
> @@ -227,6 +238,9 @@ static void conf_set_all_new_symbols(enum conf_def_mode mode)
> perror("KCONFIG_PROBABILITY");
> exit(1);
> }
> +
> + if (warned && getenv("KCONFIG_WERROR"))
> + exit(1);
> }
>
> menu_for_each_entry(menu) {
> diff --git a/scripts/kconfig/tests/randconfig_probability/Kconfig b/scripts/kconfig/tests/randconfig_probability/Kconfig
> new file mode 100644
> index 000000000..84f4e5fcc
> --- /dev/null
> +++ b/scripts/kconfig/tests/randconfig_probability/Kconfig
> @@ -0,0 +1,12 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +
> +config MODULES
> + bool
> + default y
> + modules
> +
> +config BOOL
> + bool "Bool"
> +
> +config TRI
> + tristate "Tristate"
> diff --git a/scripts/kconfig/tests/randconfig_probability/__init__.py b/scripts/kconfig/tests/randconfig_probability/__init__.py
> new file mode 100644
> index 000000000..76fc39c94
> --- /dev/null
> +++ b/scripts/kconfig/tests/randconfig_probability/__init__.py
> @@ -0,0 +1,137 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +"""Validate KCONFIG_PROBABILITY without changing the supported distributions."""
> +
> +import pytest
> +
> +
> +@pytest.fixture(autouse=True)
> +def clear_werror(monkeypatch):
> + # extra_env can set strict mode, but cannot remove an inherited flag.
> + monkeypatch.delenv('KCONFIG_WERROR', raising=False)
Clearing this environment variable doesn't belong here, it should be
part of scripts/kconfig/tests/conftest.py.
- Julian Braha
next prev parent reply other threads:[~2026-09-10 21:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 19:45 [PATCH] kconfig: reject " Dmitrii Tulnov
2026-09-08 19:24 ` Julian Braha
2026-09-08 20:35 ` Dmitrii Tulnov
2026-09-08 20:36 ` [PATCH v2] kconfig: warn about " Dmitrii Tulnov
2026-09-10 0:05 ` Julian Braha
2026-09-10 9:13 ` Dmitrii Tulnov
2026-09-10 11:25 ` Julian Braha
2026-09-10 12:04 ` [PATCH v3] " Dmitrii Tulnov
2026-09-10 21:17 ` Julian Braha [this message]
2026-09-10 21:52 ` [PATCH v4] " Dmitrii Tulnov
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=55e18f27-0ba1-433e-b4dc-a7db70172f7a@gmail.com \
--to=julianbraha@gmail.com \
--cc=jacmet@uclibc.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
--cc=tulnov.dl@gmail.com \
--cc=yann.morin.1998@free.fr \
/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
all inboxes | Powered by JetHome®