mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julian Braha <julianbraha@gmail.com>
To: Nathan Chancellor <nathan@kernel.org>,
	Priyanshu Singh <singhpriyanshu9838@gmail.com>
Cc: Nicolas Schier <nsc@kernel.org>,
	"Yann E . MORIN" <yann.morin.1998@free.fr>,
	linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kconfig: warn about malformed KCONFIG_SEED values
Date: Wed, 25 Nov 2026 23:40:04 +0000	[thread overview]
Message-ID: <eebb7d7d-48f8-47d0-810e-b03e47929fcd@gmail.com> (raw)
In-Reply-To: <179564821041.3369856.2083626361406656618.b4-reply@b4>


[-- Attachment #1.1: Type: text/plain, Size: 4466 bytes --]

On 11/25/26 23:10, Nathan Chancellor wrote:
> On 2026-11-18 07:15 +0000, Priyanshu Singh wrote:
>> randconfig parses KCONFIG_SEED with signed strtol(), causing several
>> validation and cross-architecture bugs:
>>
>> - Artificial constraints and portability issues:
>>   32-bit seeds in [0x80000000, 0xFFFFFFFF] and values > UINT_MAX
>>   are capped to LONG_MAX (0x7FFFFFFF) on 32-bit hosts instead of
>>   matching 64-bit host behavior.
>> - Whitespace handling asymmetry: Trailing whitespace leaves
>>   *endp != '\0', discarding the seed in favor of gettimeofday()
>>   while leading whitespace is accepted.
>> - Garbage handling: Invalid strings (e.g., "xyz", "42_foo") fall back
>>   to the clock seed and exit with status 0, ignoring KCONFIG_WERROR.
>>
>> Switch to strtoull(..., 0) and consume trailing whitespace so
>> whitespace-padded seeds are not discarded. Reject 0b/0B prefixes
>> explicitly so C11 and C23 builds behave identically.
>>
>> Emit a warning whenever KCONFIG_SEED deviates from a canonical unsigned
>> 32-bit integer, and exit(1) if KCONFIG_WERROR is set. Otherwise, retain
>> modulo 2^32 truncation for parseable 64-bit integers and fall back to
>> the clock seed on unparseable inputs or ERANGE overflow.
>>
>> Add regression tests in scripts/kconfig/tests/randconfig_seed/.
>>
>> Fixes: 0d8024c6ebad ("kconfig: allow specifying the seed for randconfig")
>> Signed-off-by: Priyanshu Singh <singhpriyanshu9838@gmail.com>
>> ---
>> Notes for reviewers:
>> - 0b/0B guard: Under glibc 2.38+ with -std=gnu2x/-std=c23, strtoull()
>>   maps to __isoc23_strtoull() which accepts 0b/0B binary prefixes in
>>   base 0, whereas C11 stops at 'b'. Rejecting 0b/0B prior to strtoull()
>>   keeps behavior identical across toolchains.
>> - Backward compatibility (KCONFIG_WERROR unset): Non-canonical but
>>   parseable 64-bit integers (whitespace, signs, -1, or > UINT_MAX
>>   timestamps like `date +%s%N`) emit a warning and truncate modulo 2^32
>>   across both 32-bit and 64-bit hosts, while unparseable strings or
>>   > 64-bit ERANGE overflows fall back to gettimeofday().
>>
>> Input                   Pre-Patch (64-bit)    Pre-Patch (32-bit)    Post-Patch (32 & 64-bit)
>> ----------------------  --------------------  --------------------  ------------------------------------
>> "42" / "0x2a"           0x2A (quiet)          0x2A (quiet)          0x2A (quiet)
>> "0x80000000"            0x80000000 (quiet)    0x7FFFFFFF (clamp)    0x80000000 (quiet)
>> " 42"                   0x2A (quiet)          0x2A (quiet)          0x2A + warn (WERROR -> exit 1)
>> "42 "                   Clock fallback        Clock fallback        0x2A + warn (WERROR -> exit 1)
>> "-1"                    0xFFFFFFFF (quiet)    0xFFFFFFFF (quiet)    0xFFFFFFFF + warn (WERROR -> exit 1)
>> "4294967296" (2^32)     0x0 (quiet)           0x7FFFFFFF (clamp)    0x0 + warn (WERROR -> exit 1)
>> "18446744073709551616"  0xFFFFFFFF (clamp)    0x7FFFFFFF (clamp)    Clock fallback + warn (WERROR -> 1)
>> "0b1010"                Clock (C11)/10 (C23)  Clock (C11)/10 (C23)  Clock fallback + warn (WERROR -> 1)
>> "xyz" / "42_foo"        Clock (ignores WERR)  Clock (ignores WERR)  Clock fallback + warn (WERROR -> 1)
>>
>> Tested via `make testconfig` (40 passed).
> I am pretty ambivalent about this patch. Most of what you bring up in
> the commit message is in "who cares" territory for me personally since
> 
> - 32-bit builds are going to be pretty uncommon nowadays
> 
> - Fixes is over 13 years old and it does not look like anyone has
>   noticed this in practice based on searching linux-kbuild
> 
> - The documentation states this is just an integer value; if people are
>   plugging in arbitrary values, that's on them
> 
> - Most people are just going to be using a previously generated
>   KCONFIG_SEED; can these issues happen with the default logic?
> 
> That said, Julian and Nicolas are free to disagree with me.
Sorry, wrote up a whole review on this last week but then fell down a
rabbit hole with another series...

I do appreciate improvements to input validation for Kconfig, and we
recently took a similar patch improving KCONFIG_PROBABILITY input
validation.

But, I also agree with you Nathan that some of these particular bits in
this patch are just not necessary to handle.

If a smaller, cleaner revision comes in then I'd be happy to give my
R-B.

- Julian Braha

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

  reply	other threads:[~2026-11-25 23:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  7:15 Priyanshu Singh
2026-11-25 23:10 ` Nathan Chancellor
2026-11-25 23:40   ` Julian Braha [this message]
2026-11-25 23:30 ` Julian Braha

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=eebb7d7d-48f8-47d0-810e-b03e47929fcd@gmail.com \
    --to=julianbraha@gmail.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=singhpriyanshu9838@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®