Re: [PATCH driver-core 1/1] kobject: reserve an envp slot for the terminator
From: Greg KH
Date: Mon Nov 23 2026 - 07:57:07 EST
On Mon, Nov 23, 2026 at 08:16:37PM +0800, Ren Wei wrote:
> From: Ruide Cao <caoruide123@xxxxxxxxx>
>
> add_uevent_var() currently allows envp_idx to reach ARRAY_SIZE(envp).
> This fills the final pointer slot without leaving room for the NULL
> terminator expected by usermode helper consumers.
>
> A synthetic uevent can supply enough variables to make this happen.
> When CONFIG_UEVENT_HELPER is enabled, kernel_execve() then scans beyond
> the array while counting the environment and may dereference arbitrary
> data as a string pointer.
>
> Reserve the final slot so an environment is always terminated.
>
> Fixes: 7eff2e7a8b65 ("Driver core: change add_uevent_var to use a struct")
> Cc: stable@xxxxxxxxxxxxxxx
> Reported-by: Vega <vega@xxxxxxxxxx>
> Signed-off-by: Ruide Cao <caoruide123@xxxxxxxxx>
> Signed-off-by: Ren Wei <weir@xxxxxxxxxx>
> ---
> lib/kobject_uevent.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
> index 1d29378d4f55..f7aa67d6ee54 100644
> --- a/lib/kobject_uevent.c
> +++ b/lib/kobject_uevent.c
> @@ -673,7 +673,7 @@ int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
> va_list args;
> int len;
>
> - if (env->envp_idx >= ARRAY_SIZE(env->envp)) {
> + if (env->envp_idx >= ARRAY_SIZE(env->envp) - 1) {
> WARN(1, KERN_ERR "add_uevent_var: too many keys\n");
> return -ENOMEM;
> }
As "simple" as this looks, I think there's been problems with it in the
past. Have you tested this?
thanks,
greg k-h