Re: [PATCH 1/4] lib/dynamic_debug: add NULL check after kstrdup

From: Andrew Morton

Date: Mon Jun 29 2026 - 19:51:56 EST


On Mon, 29 Jun 2026 16:30:51 +0700 Martin Weiss <martin.githubacc@xxxxxxxxx> wrote:

> kstrdup(saved_command_line, GFP_KERNEL) may return NULL under memory
> pressure. Add a check to avoid NULL pointer dereference during boot-time
> dynamic debug parameter parsing.
>

Thanks.

> --- a/lib/dynamic_debug.c
> +++ b/lib/dynamic_debug.c
> @@ -1479,6 +1479,8 @@ static int __init dynamic_debug_init(void)
> * slightly noisy if verbose, but harmless.
> */
> cmdline = kstrdup(saved_command_line, GFP_KERNEL);
> + if (!cmdline)
> + return 0; /* prevents a boot-time NULL deref */
> parse_args("dyndbg params", cmdline, NULL,
> 0, 0, 0, NULL, &ddebug_dyndbg_boot_param_cb);
> kfree(cmdline);

We conventionally assume that memory allocations at __init time cannot
fail. Sashiko explains why ;)

https://sashiko.dev/#/patchset/20260629093056.591498-1-Martin.weiss2410@xxxxxxxxx