* [PATCH driver-core v2] kobject: terminate the uevent helper environment
@ 2026-11-25 8:51 Ren Wei
2026-11-25 9:14 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Ren Wei @ 2026-11-25 8:51 UTC (permalink / raw)
To: driver-core, linux-kernel, gregkh
Cc: rafael, dakr, johan, akpm, kay.sievers, vega, caoruide123, weir
From: Ruide Cao <caoruide123@gmail.com>
struct kobj_uevent_env has room for UEVENT_NUM_ENVP (64) environment
pointers and add_uevent_var() lets all of them be used. Once the last
slot is filled there is no room left for a NULL terminator.
The usermode helper path passes env->envp straight to
call_usermodehelper_setup(), and kernel_execve() expects a NULL
terminated array. A synthetic uevent written to a sysfs uevent file can
supply enough variables to fill all 64 slots. With CONFIG_UEVENT_HELPER
enabled and a helper configured, kernel_execve() then walks past the
array into envp_idx and buf, and dereferences that data as string
pointers.
Lowering the limit to 63 would avoid the overrun, but it would also
reduce the capacity available to every uevent, including the netlink
path that does not need a terminator, and could make existing callers
with many variables start failing.
Add a dedicated sentinel slot instead, keep the limit at
UEVENT_NUM_ENVP, and keep the array NULL terminated after a variable is
added and after zap_modalias_env() removes one.
Fixes: 7eff2e7a8b65 ("Driver core: change add_uevent_var to use a struct")
Cc: stable@vger.kernel.org
Reported-by: Vega <vega@nebusec.ai>
Signed-off-by: Ruide Cao <caoruide123@gmail.com>
Signed-off-by: Ren Wei <weir@nebusec.ai>
---
Changes in v2:
- Keep the capacity at 64 variables by adding a sentinel slot instead of
lowering the add_uevent_var() limit, which would regress callers that
emit many variables.
- Compare against UEVENT_NUM_ENVP explicitly.
- Keep envp[] NULL terminated after zap_modalias_env() removes MODALIAS.
v1: https://lore.kernel.org/all/cover.1795426787.git.caoruide123@gmail.com/
---
include/linux/kobject.h | 2 +-
lib/kobject_uevent.c | 4 +++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 55e37a5d405e..f546f0f732e1 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -124,7 +124,7 @@ struct kobj_type {
struct kobj_uevent_env {
char *argv[3];
- char *envp[UEVENT_NUM_ENVP];
+ char *envp[UEVENT_NUM_ENVP + 1];
int envp_idx;
char buf[UEVENT_BUFFER_SIZE];
int buflen;
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 1d29378d4f55..25e388acc5ba 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -459,6 +459,7 @@ static void zap_modalias_env(struct kobj_uevent_env *env)
}
env->envp_idx--;
+ env->envp[env->envp_idx] = NULL;
env->buflen -= len;
}
}
@@ -673,7 +674,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 >= UEVENT_NUM_ENVP) {
WARN(1, KERN_ERR "add_uevent_var: too many keys\n");
return -ENOMEM;
}
@@ -690,6 +691,7 @@ int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
}
env->envp[env->envp_idx++] = &env->buf[env->buflen];
+ env->envp[env->envp_idx] = NULL;
env->buflen += len + 1;
return 0;
}
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH driver-core v2] kobject: terminate the uevent helper environment
2026-11-25 8:51 [PATCH driver-core v2] kobject: terminate the uevent helper environment Ren Wei
@ 2026-11-25 9:14 ` Greg KH
2026-11-25 9:40 ` Ruide Cao
0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2026-11-25 9:14 UTC (permalink / raw)
To: Ren Wei
Cc: driver-core, linux-kernel, rafael, dakr, johan, akpm, kay.sievers,
vega, caoruide123
On Wed, Nov 25, 2026 at 04:51:00PM +0800, Ren Wei wrote:
> From: Ruide Cao <caoruide123@gmail.com>
>
> struct kobj_uevent_env has room for UEVENT_NUM_ENVP (64) environment
> pointers and add_uevent_var() lets all of them be used. Once the last
> slot is filled there is no room left for a NULL terminator.
>
> The usermode helper path passes env->envp straight to
> call_usermodehelper_setup(), and kernel_execve() expects a NULL
> terminated array. A synthetic uevent written to a sysfs uevent file can
> supply enough variables to fill all 64 slots. With CONFIG_UEVENT_HELPER
> enabled and a helper configured, kernel_execve() then walks past the
> array into envp_idx and buf, and dereferences that data as string
> pointers.
>
> Lowering the limit to 63 would avoid the overrun, but it would also
> reduce the capacity available to every uevent, including the netlink
> path that does not need a terminator, and could make existing callers
> with many variables start failing.
>
> Add a dedicated sentinel slot instead, keep the limit at
> UEVENT_NUM_ENVP, and keep the array NULL terminated after a variable is
> added and after zap_modalias_env() removes one.
>
> Fixes: 7eff2e7a8b65 ("Driver core: change add_uevent_var to use a struct")
> Cc: stable@vger.kernel.org
> Reported-by: Vega <vega@nebusec.ai>
> Signed-off-by: Ruide Cao <caoruide123@gmail.com>
> Signed-off-by: Ren Wei <weir@nebusec.ai>
> ---
> Changes in v2:
> - Keep the capacity at 64 variables by adding a sentinel slot instead of
> lowering the add_uevent_var() limit, which would regress callers that
> emit many variables.
> - Compare against UEVENT_NUM_ENVP explicitly.
> - Keep envp[] NULL terminated after zap_modalias_env() removes MODALIAS.
>
> v1: https://lore.kernel.org/all/cover.1795426787.git.caoruide123@gmail.com/
Why did you not actually reply to my previous email?
Why did your previous patch not work? What testing was done differently
between the previous patch and this one to require this patch?
Without an actual discussion, just throwing random patches at us does
nothing to make us want to accept the change at all, for obvious reasons
(i.e. what would you want to see if you were in my position here?)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH driver-core v2] kobject: terminate the uevent helper environment
2026-11-25 9:14 ` Greg KH
@ 2026-11-25 9:40 ` Ruide Cao
2026-11-25 9:59 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Ruide Cao @ 2026-11-25 9:40 UTC (permalink / raw)
To: Greg KH
Cc: Ren Wei, driver-core, linux-kernel, rafael, dakr, johan, akpm,
kay.sievers, vega
Hi Greg,
Sorry. We took your comments seriously and did not mean to skip the discussion.
I wanted the reply to include a lore link to the new patch, so that
you could look at the change and the explanation together.
Going forward, I will always reply on the thread first and only then
send any follow-up patch.
Please find our reply to your previous questions here:
https://lore.kernel.org/all/CACveakTAopfuvAVQnbzzU3c6z2efTgySV5xo7330KAD6nMSxYQ@mail.gmail.com/
Thanks,
Ruide
Greg KH <gregkh@linuxfoundation.org> 于2026年11月25日周三 17:18写道:
>
> On Wed, Nov 25, 2026 at 04:51:00PM +0800, Ren Wei wrote:
> > From: Ruide Cao <caoruide123@gmail.com>
> >
> > struct kobj_uevent_env has room for UEVENT_NUM_ENVP (64) environment
> > pointers and add_uevent_var() lets all of them be used. Once the last
> > slot is filled there is no room left for a NULL terminator.
> >
> > The usermode helper path passes env->envp straight to
> > call_usermodehelper_setup(), and kernel_execve() expects a NULL
> > terminated array. A synthetic uevent written to a sysfs uevent file can
> > supply enough variables to fill all 64 slots. With CONFIG_UEVENT_HELPER
> > enabled and a helper configured, kernel_execve() then walks past the
> > array into envp_idx and buf, and dereferences that data as string
> > pointers.
> >
> > Lowering the limit to 63 would avoid the overrun, but it would also
> > reduce the capacity available to every uevent, including the netlink
> > path that does not need a terminator, and could make existing callers
> > with many variables start failing.
> >
> > Add a dedicated sentinel slot instead, keep the limit at
> > UEVENT_NUM_ENVP, and keep the array NULL terminated after a variable is
> > added and after zap_modalias_env() removes one.
> >
> > Fixes: 7eff2e7a8b65 ("Driver core: change add_uevent_var to use a struct")
> > Cc: stable@vger.kernel.org
> > Reported-by: Vega <vega@nebusec.ai>
> > Signed-off-by: Ruide Cao <caoruide123@gmail.com>
> > Signed-off-by: Ren Wei <weir@nebusec.ai>
> > ---
> > Changes in v2:
> > - Keep the capacity at 64 variables by adding a sentinel slot instead of
> > lowering the add_uevent_var() limit, which would regress callers that
> > emit many variables.
> > - Compare against UEVENT_NUM_ENVP explicitly.
> > - Keep envp[] NULL terminated after zap_modalias_env() removes MODALIAS.
> >
> > v1: https://lore.kernel.org/all/cover.1795426787.git.caoruide123@gmail.com/
>
> Why did you not actually reply to my previous email?
>
> Why did your previous patch not work? What testing was done differently
> between the previous patch and this one to require this patch?
>
> Without an actual discussion, just throwing random patches at us does
> nothing to make us want to accept the change at all, for obvious reasons
> (i.e. what would you want to see if you were in my position here?)
>
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH driver-core v2] kobject: terminate the uevent helper environment
2026-11-25 9:40 ` Ruide Cao
@ 2026-11-25 9:59 ` Greg KH
0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2026-11-25 9:59 UTC (permalink / raw)
To: Ruide Cao
Cc: Ren Wei, driver-core, linux-kernel, rafael, dakr, johan, akpm,
kay.sievers, vega
A: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
A: No.
Q: Should I include quotations after my reply?
http://daringfireball.net/2007/07/on_top
On Wed, Nov 25, 2026 at 05:40:04PM +0800, Ruide Cao wrote:
> Hi Greg,
>
> Sorry. We took your comments seriously and did not mean to skip the discussion.
>
> I wanted the reply to include a lore link to the new patch, so that
> you could look at the change and the explanation together.
>
> Going forward, I will always reply on the thread first and only then
> send any follow-up patch.
>
> Please find our reply to your previous questions here:
> https://lore.kernel.org/all/CACveakTAopfuvAVQnbzzU3c6z2efTgySV5xo7330KAD6nMSxYQ@mail.gmail.com/
Ok, let's take it there, and PLEASE do not just use AI to respond to my
questions, that's rude for all of us involved...
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-25 10:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 8:51 [PATCH driver-core v2] kobject: terminate the uevent helper environment Ren Wei
2026-11-25 9:14 ` Greg KH
2026-11-25 9:40 ` Ruide Cao
2026-11-25 9:59 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox