[PATCH v3 2/6] printk: add bounds checking to boot_delay
From: Andrew Murray
Date: Sun Jul 12 2026 - 06:21:00 EST
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;
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",
--
2.34.1