From: "Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>
To: gregkh@suse.de
Cc: dhowells@redhat.com, eparis@redhat.com, rjw@sisk.pl,
kay.sievers@vrfy.org, jmorris@namei.org, tj@kernel.org,
bp@amd64.org, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] PM / request_firmware(): Use the refcounting solution to fix the race
Date: Tue, 06 Dec 2011 02:56:41 +0530 [thread overview]
Message-ID: <20111205212623.27496.81640.stgit@srivatsabhat.in.ibm.com> (raw)
In-Reply-To: <20111205212456.27496.35812.stgit@srivatsabhat.in.ibm.com>
It is racy to merely call usermodehelper_is_disabled() to check whether
we can successfully use usermodehelpers to get firmware from userspace,
because, an event such as suspend/hibernation in progress could disable
the usermodehelpers at the same time.
So use the pair [get|put]_usermodehelper() around the above check (reader),
to solve this race. Also, the writers, namely usermodehelper_[disable|enable]
should use umh_control_[begin|done] for this synchronization to be effective.
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
---
drivers/base/firmware_class.c | 3 +++
kernel/kmod.c | 10 +++++++++-
2 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 06ed6b4..8a04946 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -534,6 +534,8 @@ static int _request_firmware(const struct firmware **firmware_p,
return 0;
}
+ get_usermodehelper();
+
if (WARN_ON(usermodehelper_is_disabled())) {
dev_err(device, "firmware: %s will not be loaded\n", name);
retval = -EBUSY;
@@ -572,6 +574,7 @@ static int _request_firmware(const struct firmware **firmware_p,
fw_destroy_instance(fw_priv);
out:
+ put_usermodehelper();
if (retval) {
release_firmware(firmware);
*firmware_p = NULL;
diff --git a/kernel/kmod.c b/kernel/kmod.c
index acb52af..e6951b3 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -337,6 +337,8 @@ static void __call_usermodehelper(struct work_struct *work)
* If set, call_usermodehelper_exec() will exit immediately returning -EBUSY
* (used for preventing user land processes from being created after the user
* land has been frozen during a system-wide hibernation or suspend operation).
+ * Should always be manipulated under umhelper.lock, by using the functions
+ * umh_control_begin() and umh_control_done().
*/
static int usermodehelper_disabled = 1;
@@ -362,8 +364,10 @@ int usermodehelper_disable(void)
{
long retval;
+ umh_control_begin();
usermodehelper_disabled = 1;
- smp_mb();
+ umh_control_done();
+
/*
* From now on call_usermodehelper_exec() won't start any new
* helpers, so it is sufficient if running_helpers turns out to
@@ -376,7 +380,9 @@ int usermodehelper_disable(void)
if (retval)
return 0;
+ umh_control_begin();
usermodehelper_disabled = 0;
+ umh_control_done();
return -EAGAIN;
}
@@ -385,7 +391,9 @@ int usermodehelper_disable(void)
*/
void usermodehelper_enable(void)
{
+ umh_control_begin();
usermodehelper_disabled = 0;
+ umh_control_done();
}
/**
prev parent reply other threads:[~2011-12-05 21:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-05 21:25 [PATCH 0/2] PM / Usermodehelper: Fix freezer failures due to racy usermodehelper_is_disabled() Srivatsa S. Bhat
2011-12-05 21:26 ` [PATCH 1/2] PM / Usermodehelper: Introduce reference counting to solve usermodehelper_disabled race Srivatsa S. Bhat
2011-12-05 21:38 ` Tejun Heo
2011-12-07 12:21 ` Srivatsa S. Bhat
2011-12-06 0:59 ` Namhyung Kim
2011-12-07 12:30 ` Srivatsa S. Bhat
2011-12-07 13:59 ` Namhyung Kim
2011-12-05 21:26 ` Srivatsa S. Bhat [this message]
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=20111205212623.27496.81640.stgit@srivatsabhat.in.ibm.com \
--to=srivatsa.bhat@linux.vnet.ibm.com \
--cc=bp@amd64.org \
--cc=dhowells@redhat.com \
--cc=eparis@redhat.com \
--cc=gregkh@suse.de \
--cc=jmorris@namei.org \
--cc=kay.sievers@vrfy.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rjw@sisk.pl \
--cc=tj@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®