Re: [PATCH v3 2/6] printk: add bounds checking to boot_delay
From: Petr Mladek
Date: Thu Jul 16 2026 - 09:14:31 EST
On Sun 2026-07-12 11:20:33, Andrew Murray wrote:
> As the boot_delay kernel parameter represents a duration in
> milliseconds, let's set its type to be unsigned int and add
> bounds checking.
>
> Please note that the existing pr_debug will only be displayed
> when boot_delay is non-zero:
>
> pr_debug("printk_delay: %u, preset_lpj: %ld, lpj: %lu, "
> "HZ: %d, loops_per_msec: %llu\n",
> printk_delay_msec, preset_lpj, lpj, HZ, loops_per_msec);
>
> Signed-off-by: Andrew Murray <amurray@xxxxxxxxxxxxxxxxxxxx>
> ---
> kernel/printk/printk.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 31aabdf8248cc39c54ee11685d4a37deac1c174c..8be562c9be277670ba3209ed1f810fc87175848a 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -1291,19 +1291,22 @@ static bool suppress_message_printing(int level)
>
> #ifdef CONFIG_BOOT_PRINTK_DELAY
>
> -static int boot_delay; /* msecs delay after each printk during bootup */
> +static unsigned int boot_delay; /* msecs delay after each printk during bootup */
> static unsigned long long loops_per_msec; /* based on boot_delay */
>
> static int __init boot_delay_setup(char *str)
> {
> unsigned long lpj;
> + int boot_delay_val;
As Sashiko AI pointed out [1], the variable should get initialized:
int boot_delay_val = 0;
get_option() keeps the original (random) value, for example, when the given
string is empty.
[1] https://sashiko.dev/#/patchset/20260712-printkcleanup-v3-0-574547b8f71b%40thegoodpenguin.co.uk
> lpj = preset_lpj ? preset_lpj : 1000000; /* some guess */
> loops_per_msec = (unsigned long long)lpj / 1000 * HZ;
>
> - get_option(&str, &boot_delay);
> - if (boot_delay > 10 * 1000)
> - boot_delay = 0;
> + get_option(&str, &boot_delay_val);
> + if (boot_delay_val < 0 || boot_delay_val > 10 * 1000)
> + return 0;
> +
> + boot_delay = (unsigned int)boot_delay_val;
>
> pr_debug("boot_delay: %u, preset_lpj: %ld, lpj: %lu, "
> "HZ: %d, loops_per_msec: %llu\n",
The problem gets fixed in 4th patch. But should fix it here as well
to do not break bisection. Also later changes might get reverted from
other reasons, ...
With the initialized variable:
Reviewed-by: Petr Mladek <pmladek@xxxxxxxx>
Best Regards,
Petr