lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240516-uevent-sysfs-notify-v1-1-2ebb39930c09@weissschuh.net>
Date: Thu, 16 May 2024 12:27:58 +0200
From: Thomas Weißschuh <linux@...ssschuh.net>
To: Andrew Morton <akpm@...ux-foundation.org>, 
 Greg Kroah-Hartman <gregkh@...uxfoundation.org>, 
 "Rafael J. Wysocki" <rafael@...nel.org>
Cc: linux-kernel@...r.kernel.org, Sebastian Reichel <sre@...nel.org>, 
 linux-pm@...r.kernel.org, 
 Thomas Weißschuh <linux@...ssschuh.net>
Subject: [PATCH RFC] kobject_uevent: notify uevent sysfs file on changes

The sysfs file "uevent" that exists for each device
contains the same information that is attached to uevents emitted via
netlink (or the usermode helper).
This is useful for userspace which interacts with sysfs directly,
without using (lib)udev.

However it is not possible to actually get notified when the data in
the "uevent" file changes.

Enable these notifications, so that the "uevent" file can be used
together with inotify and friends.

Signed-off-by: Thomas Weißschuh <linux@...ssschuh.net>
---
My original usecase is to get updates for power supplies.
Current charge status and similar.
All this data is exposed via "uevent", and on updates an KOBJ_CHANGED
event is emitted.

To me, a general solution covering all devices looked the best.

Open questions for the RFC:
* Is this a good idea?
* How to handle other actions?
  _ADD and _REMOVE should not call sysfs_notify() in any case, these
  cases can be detected otherwise.
---
 lib/kobject_uevent.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 03b427e2707e..74047a79cb13 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -24,6 +24,7 @@
 #include <linux/netlink.h>
 #include <linux/uidgid.h>
 #include <linux/uuid.h>
+#include <linux/sysfs.h>
 #include <linux/ctype.h>
 #include <net/sock.h>
 #include <net/netlink.h>
@@ -593,6 +594,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
 	retval = kobject_uevent_net_broadcast(kobj, env, action_string,
 					      devpath);
 
+	if (action == KOBJ_CHANGE)
+		sysfs_notify(kobj, NULL, "uevent");
+
 #ifdef CONFIG_UEVENT_HELPER
 	/* call uevent_helper, usually only enabled during early boot */
 	if (uevent_helper[0] && !kobj_usermode_filter(kobj)) {

---
base-commit: 3c999d1ae3c75991902a1a7dad0cb62c2a3008b4
change-id: 20240515-uevent-sysfs-notify-4eb9e95397fd

Best regards,
-- 
Thomas Weißschuh <linux@...ssschuh.net>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ