mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] umh: restore the full barrier in __usermodehelper_disable()
@ 2026-12-05 17:32 Zhenwen Liang
  0 siblings, 0 replies; only message in thread
From: Zhenwen Liang @ 2026-12-05 17:32 UTC (permalink / raw)
  To: Luis Chamberlain, linux-kernel; +Cc: Oleg Nesterov, Rafael J. Wysocki

__usermodehelper_disable() stores usermodehelper_disabled, then reads
running_helpers; call_usermodehelper_exec() increments running_helpers,
issues smp_mb__after_atomic(), then reads usermodehelper_disabled.
up_write() is only a release, so on weakly ordered CPUs (not x86) the
disable side can report that no helper is running while a helper is
still queued afterwards. This has not been reproduced.

The smp_mb() after the store, added by commit ccd4b65aef4b ("PM:
prevent frozen user mode helpers from failing the freezing of tasks"),
was lost when the store was moved under umhelper_sem. Restore it, and
use WRITE_ONCE()/READ_ONCE() for the store and the lockless check.

The problem was found, and this patch prepared, with the help of a
formal analysis tool we are developing that uses AI assistance; I have
reviewed the analysis and the patch.

Fixes: b298d289c792 ("PM / Sleep: Fix freezer failures due to racy usermodehelper_is_disabled()")
Signed-off-by: Zhenwen Liang <zhenwenliang@google.com>
---
Compile-tested only (arm64, W=1). The barrier is only on the suspend,
hibernate and shutdown path. The requirement was stated in the 2007
review: https://lore.kernel.org/all/20070625104332.GA147@tv-sign.ru/

 kernel/umh.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/umh.c b/kernel/umh.c
index 512dc01..610ede7 100644
--- a/kernel/umh.c
+++ b/kernel/umh.c
@@ -296,8 +296,10 @@ int __usermodehelper_disable(enum umh_disable_depth depth)
 		return -EINVAL;
 
 	down_write(&umhelper_sem);
-	usermodehelper_disabled = depth;
+	WRITE_ONCE(usermodehelper_disabled, depth);
 	up_write(&umhelper_sem);
+	/* Pairs with smp_mb__after_atomic() in helper_lock() */
+	smp_mb();
 
 	/*
 	 * From now on call_usermodehelper_exec() won't start any new
@@ -407,7 +409,7 @@ int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait)
 		return -EINVAL;
 	}
 	helper_lock();
-	if (usermodehelper_disabled) {
+	if (READ_ONCE(usermodehelper_disabled)) {
 		retval = -EBUSY;
 		goto out;
 	}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-05 17:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-05 17:32 [PATCH] umh: restore the full barrier in __usermodehelper_disable() Zhenwen Liang

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®