Linux driver-core infrastructure
 help / color / mirror / Atom feed
* [PATCH driver-core 0/1] kobject: reserve an envp slot for the terminator
@ 2026-11-23 12:16 Ren Wei
  2026-11-23 12:16 ` [PATCH driver-core 1/1] " Ren Wei
  2026-11-23 12:56 ` [PATCH driver-core 0/1] " Greg KH
  0 siblings, 2 replies; 4+ messages in thread
From: Ren Wei @ 2026-11-23 12:16 UTC (permalink / raw)
  To: linux-kernel, driver-core
  Cc: gregkh, rafael, dakr, johan, akpm, kay.sievers, vega, caoruide123,
	weir

From: Ruide Cao <caoruide123@gmail.com>

Hi Linux kernel maintainers,

We found an issue in lib/kobject_uevent.c.

This bug is tracked at: https://bugtracker.nebusec.ai/f/16082

add_uevent_var() permits envp_idx to reach ARRAY_SIZE(env->envp), filling
the final pointer slot without reserving a trailing NULL. With
CONFIG_UEVENT_HELPER and a nonempty helper path, an event containing
exactly 61 variables before SEQNUM causes SEQNUM, HOME, and PATH to fill
all 64 slots. call_usermodehelper then asynchronously passes this
unterminated array to kernel_execve(). count_strings_kernel() reads beyond
envp into envp_idx and env->buf, interprets those bytes as pointers, and
later dereferences invalid addresses while copying the environment.
Synthetic arguments allow the environment count to be tuned, resulting in
an out-of-bounds scan and kernel crash.

Privilege model: writing a synthetic uevent to /sys/module/kernel/uevent
and setting /proc/sys/kernel/hotplug require CAP_SYS_ADMIN; the
reproducer runs as root. The crash also depends on CONFIG_UEVENT_HELPER
and a nonempty helper path.

Compatibility: no uAPI change.

Reproducer:

#!/bin/sh
set -eu

# This PoC must run as root inside the guest.
printf '%s' /bin/true > /proc/sys/kernel/hotplug
echo 0 > /proc/sys/kernel/panic_on_warn

msg='add 11111111-1111-1111-1111-111111111111'
i=1
while [ "$i" -le 57 ]; do
	msg="$msg K$i=V$i"
	i=$((i + 1))
done

printf '%s\n' "$msg" > /sys/module/kernel/uevent
sleep 2



We run the PoC in a 2 GB RAM x86 QEMU environment.

------BEGIN PoC------

#!/bin/sh
set -eu

# This PoC must run as root inside the guest.
printf '%s' /bin/true > /proc/sys/kernel/hotplug
echo 0 > /proc/sys/kernel/panic_on_warn

msg='add 11111111-1111-1111-1111-111111111111'
i=1
while [ "$i" -le 57 ]; do
	msg="$msg K$i=V$i"
	i=$((i + 1))
done

printf '%s\n' "$msg" > /sys/module/kernel/uevent
sleep 2


------END PoC--------

----BEGIN crash log----

[  161.975900][ T1043] BUG: unable to handle page fault for address: 0000000000656c75
[  161.977567][ T1043] #PF: supervisor read access in kernel mode
[  161.978836][ T1043] #PF: error_code(0x0000) - not-present page
[  161.979824][ T1043] PGD 0 P4D 0
[  161.980319][ T1043] Oops: Oops: 0000 [#1] SMP KASAN NOPTI
[  161.981257][ T1043] CPU: 0 UID: 0 PID: 1043 Comm: kworker/u16:0 Not tainted 6.12.95 #4 53deed68f5e8c87eac9412ec2ca16e6c37d9fe62
[  161.983040][ T1043] Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
[  161.985205][ T1043] RIP: 0010:strnlen+0x1b/0x40
[  161.986083][ T1043] Code: 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa 48 8d 14 37 48 89 f8 48 85 f6 75 0b eb 21 48 83 c0 01 48 39 c2 74 0d <80> 38 00 75 f2 48 29 f8 e9 c3 bd 36 00 48 89 d0 48 29 f8 e9 b8 bd
[  161.989083][ T1043] RSP: 0018:ffffc90003127e30 EFLAGS: 00010206
[  161.990058][ T1043] RAX: 0000000000656c75 RBX: ffff88810df296a8 RCX: ffffffff81f0516d
[  161.991261][ T1043] RDX: 0000000000676c75 RSI: 0000000000020000 RDI: 0000000000656c75
[  161.992481][ T1043] RBP: ffff888110090040 R08: 0000000000000001 R09: fffff9400006ea00
[  161.993709][ T1043] R10: ffffea00003751f7 R11: 0000000000000001 R12: 0000000000656c75
[  161.994995][ T1043] R13: ffff888117b20200 R14: ffff88810df29010 R15: dffffc0000000000
[  161.996234][ T1043] FS:  0000000000000000(0000) GS:ffff888119a00000(0000) knlGS:0000000000000000
[  161.997606][ T1043] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  161.998664][ T1043] CR2: 0000000000656c75 CR3: 0000000008534002 CR4: 0000000000770ef0
[  161.999992][ T1043] PKRU: 55555554
[  162.000517][ T1043] Call Trace:
[  162.001100][ T1043]  <TASK>
[  162.001523][ T1043]  copy_string_kernel+0x27/0x440
[  162.002422][ T1043]  ? srso_alias_return_thunk+0x5/0xfbef5
[  162.003347][ T1043]  ? __asan_memcpy+0x3c/0x60
[  162.004120][ T1043]  copy_strings_kernel+0x92/0x130
[  162.004951][ T1043]  kernel_execve+0x201/0x2e0
[  162.005615][ T1043]  call_usermodehelper_exec_async+0x21f/0x440
[  162.006658][ T1043]  ? trace_hardirqs_on+0x5b/0x110
[  162.007530][ T1043]  ? __pfx_call_usermodehelper_exec_async+0x10/0x10
[  162.008499][ T1043]  ret_from_fork+0x31/0x70
[  162.009271][ T1043]  ? __pfx_call_usermodehelper_exec_async+0x10/0x10
[  162.010331][ T1043]  ret_from_fork_asm+0x1a/0x30
[  162.011099][ T1043]  </TASK>
[  162.011639][ T1043] Modules linked in:
[  162.012264][ T1043] CR2: 0000000000656c75
[  162.012984][ T1043] ---[ end trace 0000000000000000 ]---
[  162.013800][ T1043] RIP: 0010:strnlen+0x1b/0x40
[  162.014558][ T1043] Code: 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa 48 8d 14 37 48 89 f8 48 85 f6 75 0b eb 21 48 83 c0 01 48 39 c2 74 0d <80> 38 00 75 f2 48 29 f8 e9 c3 bd 36 00 48 89 d0 48 29 f8 e9 b8 bd
[  162.017573][ T1043] RSP: 0018:ffffc90003127e30 EFLAGS: 00010206
[  162.018548][ T1043] RAX: 0000000000656c75 RBX: ffff88810df296a8 RCX: ffffffff81f0516d
[  162.019831][ T1043] RDX: 0000000000676c75 RSI: 0000000000020000 RDI: 0000000000656c75
[  162.021036][ T1043] RBP: ffff888110090040 R08: 0000000000000001 R09: fffff9400006ea00
[  162.022264][ T1043] R10: ffffea00003751f7 R11: 0000000000000001 R12: 0000000000656c75
[  162.023449][ T1043] R13: ffff888117b20200 R14: ffff88810df29010 R15: dffffc0000000000
[  162.024845][ T1043] FS:  0000000000000000(0000) GS:ffff888119a00000(0000) knlGS:0000000000000000
[  162.026300][ T1043] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  162.027378][ T1043] CR2: 0000000000656c75 CR3: 0000000008534002 CR4: 0000000000770ef0
[  162.028229][ T1043] PKRU: 55555554
[  162.028615][ T1043] Kernel panic - not syncing: Fatal exception
[  162.029525][ T1043] Kernel Offset: disabled
[  162.030001][ T1043] Rebooting in 10 seconds..


-----END crash log-----

Best regards,
Ruide Cao

Ruide Cao (1):
  kobject: reserve an envp slot for the terminator

 lib/kobject_uevent.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
-- 
2.47.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH driver-core 1/1] kobject: reserve an envp slot for the terminator
  2026-11-23 12:16 [PATCH driver-core 0/1] kobject: reserve an envp slot for the terminator Ren Wei
@ 2026-11-23 12:16 ` Ren Wei
  2026-11-23 12:57   ` Greg KH
  2026-11-23 12:56 ` [PATCH driver-core 0/1] " Greg KH
  1 sibling, 1 reply; 4+ messages in thread
From: Ren Wei @ 2026-11-23 12:16 UTC (permalink / raw)
  To: linux-kernel, driver-core
  Cc: gregkh, rafael, dakr, johan, akpm, kay.sievers, vega, caoruide123,
	weir

From: Ruide Cao <caoruide123@gmail.com>

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@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>
---
 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;
 	}
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH driver-core 0/1] kobject: reserve an envp slot for the terminator
  2026-11-23 12:16 [PATCH driver-core 0/1] kobject: reserve an envp slot for the terminator Ren Wei
  2026-11-23 12:16 ` [PATCH driver-core 1/1] " Ren Wei
@ 2026-11-23 12:56 ` Greg KH
  1 sibling, 0 replies; 4+ messages in thread
From: Greg KH @ 2026-11-23 12:56 UTC (permalink / raw)
  To: Ren Wei
  Cc: linux-kernel, driver-core, rafael, dakr, johan, akpm, kay.sievers,
	vega, caoruide123

On Mon, Nov 23, 2026 at 08:16:36PM +0800, Ren Wei wrote:
> From: Ruide Cao <caoruide123@gmail.com>
> 
> Hi Linux kernel maintainers,
> 
> We found an issue in lib/kobject_uevent.c.
> 
> This bug is tracked at: https://bugtracker.nebusec.ai/f/16082
> 
> add_uevent_var() permits envp_idx to reach ARRAY_SIZE(env->envp), filling
> the final pointer slot without reserving a trailing NULL. With
> CONFIG_UEVENT_HELPER and a nonempty helper path, an event containing
> exactly 61 variables before SEQNUM causes SEQNUM, HOME, and PATH to fill
> all 64 slots. call_usermodehelper then asynchronously passes this
> unterminated array to kernel_execve(). count_strings_kernel() reads beyond
> envp into envp_idx and env->buf, interprets those bytes as pointers, and
> later dereferences invalid addresses while copying the environment.
> Synthetic arguments allow the environment count to be tuned, resulting in
> an out-of-bounds scan and kernel crash.
> 
> Privilege model: writing a synthetic uevent to /sys/module/kernel/uevent
> and setting /proc/sys/kernel/hotplug require CAP_SYS_ADMIN; the
> reproducer runs as root. The crash also depends on CONFIG_UEVENT_HELPER
> and a nonempty helper path.

This has come up many times in the past, nice to see your LLM has read
the mailing list archives :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH driver-core 1/1] kobject: reserve an envp slot for the terminator
  2026-11-23 12:16 ` [PATCH driver-core 1/1] " Ren Wei
@ 2026-11-23 12:57   ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2026-11-23 12:57 UTC (permalink / raw)
  To: Ren Wei
  Cc: linux-kernel, driver-core, rafael, dakr, johan, akpm, kay.sievers,
	vega, caoruide123

On Mon, Nov 23, 2026 at 08:16:37PM +0800, Ren Wei wrote:
> From: Ruide Cao <caoruide123@gmail.com>
> 
> 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@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>
> ---
>  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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-23 12:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 12:16 [PATCH driver-core 0/1] kobject: reserve an envp slot for the terminator Ren Wei
2026-11-23 12:16 ` [PATCH driver-core 1/1] " Ren Wei
2026-11-23 12:57   ` Greg KH
2026-11-23 12:56 ` [PATCH driver-core 0/1] " Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox