From: Zhenwen Liang <zhenwenliang@google.com>
To: Luis Chamberlain <mcgrof@kernel.org>, linux-kernel@vger.kernel.org
Cc: Oleg Nesterov <oleg@redhat.com>, "Rafael J. Wysocki" <rafael@kernel.org>
Subject: [PATCH] umh: restore the full barrier in __usermodehelper_disable()
Date: Sat, 5 Dec 2026 17:32:22 +0000 [thread overview]
Message-ID: <20261205173222.233754-1-zhenwenliang@google.com> (raw)
__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;
}
reply other threads:[~2026-12-05 17:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261205173222.233754-1-zhenwenliang@google.com \
--to=zhenwenliang@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=oleg@redhat.com \
--cc=rafael@kernel.org \
/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®