[PATCH] umh: restore the full barrier in __usermodehelper_disable()
From: Zhenwen Liang
Date: Sat Dec 05 2026 - 12:32:26 EST
__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@xxxxxxxxxx>
---
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@xxxxxxxxxx/
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;
}