public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kobject_uevent: add uevent_helper exist check
@ 2025-04-04 17:31 zhoumin
  2025-04-05 22:52 ` Andrew Morton
  2025-04-07  7:00 ` Greg KH
  0 siblings, 2 replies; 8+ messages in thread
From: zhoumin @ 2025-04-04 17:31 UTC (permalink / raw)
  To: gregkh, rafael, dakr, akpm; +Cc: linux-kernel, zhoumin

The kernel creates uevent_helper process for every uevent sent,
even if the uevent_helper does not exist. Before the rootfs is
mounted, a large number of events are generated. This change
introduces uevent_helper existence check to prevent unnecessary
operations.

Logs a debug messase before call_usermodehelper_setup.
e.g.: pr_emerg("action:%s devpath:%s\n", action_string, devpath);
You will see a large number of uevent_helper processes
are attempted to be created before the rootfs is mounted.

Signed-off-by: zhoumin <teczm@foxmail.com>
---
 lib/kobject_uevent.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index b7f2fa08d9c8..f3d34ded141a 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -28,6 +28,7 @@
 #include <net/sock.h>
 #include <net/netlink.h>
 #include <net/net_namespace.h>
+#include <linux/namei.h>
 
 
 atomic64_t uevent_seqnum;
@@ -58,6 +59,23 @@ static const char *kobject_actions[] = {
 	[KOBJ_UNBIND] =		"unbind",
 };
 
+#ifdef CONFIG_UEVENT_HELPER
+static int uevent_helper_lookup(void)
+{
+	static int ret = -ENOENT;
+	struct path path;
+
+	if (!ret)
+		return ret;
+
+	ret = kern_path(uevent_helper, LOOKUP_FOLLOW, &path);
+	if (!ret)
+		path_put(&path);
+
+	return ret;
+}
+#endif
+
 static int kobject_action_type(const char *buf, size_t count,
 			       enum kobject_action *type,
 			       const char **args)
@@ -610,7 +628,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
 
 #ifdef CONFIG_UEVENT_HELPER
 	/* call uevent_helper, usually only enabled during early boot */
-	if (uevent_helper[0] && !kobj_usermode_filter(kobj)) {
+	if (uevent_helper[0] && !uevent_helper_lookup() && !kobj_usermode_filter(kobj)) {
 		struct subprocess_info *info;
 
 		retval = add_uevent_var(env, "HOME=/");
-- 
2.43.0


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

end of thread, other threads:[~2025-04-07 16:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-04 17:31 [PATCH] kobject_uevent: add uevent_helper exist check zhoumin
2025-04-05 22:52 ` Andrew Morton
2025-04-06  6:19   ` zhoumin
2025-04-07  7:01     ` Greg KH
2025-04-07  7:00 ` Greg KH
2025-04-07 15:18   ` zhoumin
2025-04-07 15:35     ` Greg KH
2025-04-07 16:22       ` zhoumin

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