mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ren Wei <weir@nebusec.ai>
To: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev
Cc: gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org,
	johan@kernel.org, akpm@linux-foundation.org,
	kay.sievers@vrfy.org, vega@nebusec.ai, caoruide123@gmail.com,
	weir@nebusec.ai
Subject: [PATCH driver-core 1/1] kobject: reserve an envp slot for the terminator
Date: Mon, 23 Nov 2026 20:16:37 +0800	[thread overview]
Message-ID: <cd35c5682ebe0f5a58fa6beed90bb7d0e7d5e9a2.1795426787.git.caoruide123@gmail.com> (raw)
In-Reply-To: <cover.1795426787.git.caoruide123@gmail.com>

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


  reply	other threads:[~2026-11-23 12:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 12:16 [PATCH driver-core 0/1] " Ren Wei
2026-11-23 12:16 ` Ren Wei [this message]
2026-11-23 12:57   ` [PATCH driver-core 1/1] " Greg KH
2026-11-23 12:56 ` [PATCH driver-core 0/1] " Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cd35c5682ebe0f5a58fa6beed90bb7d0e7d5e9a2.1795426787.git.caoruide123@gmail.com \
    --to=weir@nebusec.ai \
    --cc=akpm@linux-foundation.org \
    --cc=caoruide123@gmail.com \
    --cc=dakr@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=vega@nebusec.ai \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®