From: Linus Torvalds <torvalds@linux-foundation.org>
To: Frederik Deweerdt <frederik.deweerdt@xprog.eu>
Cc: greg@kroah.org, Lars Ericsson <Lars_Ericsson@telia.com>,
David.Woodhouse@intel.com, sachinp@in.ibm.com,
linux-kernel@vger.kernel.org,
"'Ivo van Doorn'" <ivdoorn@gmail.com>
Subject: Re: [patch -stable] firware_class oops: fix firmware_loading_store locking
Date: Wed, 23 Sep 2009 09:42:41 -0700 (PDT) [thread overview]
Message-ID: <alpine.LFD.2.01.0909230936320.3303@localhost.localdomain> (raw)
In-Reply-To: <20090921133223.GA13038@gambetta>
On Mon, 21 Sep 2009, Frederik Deweerdt wrote:
<
> I'd rather wait someone picks it up for mainline inclusion. I've added
> your {Reported,Tested}-by tags.
>
> The bug its vanilla 2.6.31, and should be considered for -stable inclusion.
>
> Regards,
> Frederik
>
> ----
>
> The code introduced by commit 6e03a201bbe8137487f340d26aa662110e324b20 leads
> to a potential null deref. The following patch adds the proper locking
> around the accesses to fw_priv->fw.
> See http://bugzilla.kernel.org/show_bug.cgi?id=14185 for a full bug report.
I don't think this is correct.
I think you should protect the FW_STATUS_LOADING bit too, shouldn't you?
As it is, it does this:
if (test_bit(FW_STATUS_LOADING, &fw_priv->status)) {
mutex_lock(&fw_lock);
...
clear_bit(FW_STATUS_LOADING, &fw_priv->status);
mutex_unlock(&fw_lock);
break;
}
and if this code can race (which it obviously can, since your addition of
fw_lock mutex matters), then I think it can race on that FW_STATUS_LOADING
bit too. No?
So my gut feel is that the whole damn function should be protected by the
mutex_lock thing. IOW, the patch would be something like the appended.
UNTESTED. Somebody needs to test this, verify, and send it back to me.
Am I missing something?
Linus
---
drivers/base/firmware_class.c | 9 ++++-----
1 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 7376367..1b803df 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -150,13 +150,12 @@ static ssize_t firmware_loading_store(struct device *dev,
int loading = simple_strtol(buf, NULL, 10);
int i;
+ mutex_lock(&fw_lock);
switch (loading) {
case 1:
- mutex_lock(&fw_lock);
- if (!fw_priv->fw) {
- mutex_unlock(&fw_lock);
+ if (!fw_priv->fw)
break;
- }
+
vfree(fw_priv->fw->data);
fw_priv->fw->data = NULL;
for (i = 0; i < fw_priv->nr_pages; i++)
@@ -167,7 +166,6 @@ static ssize_t firmware_loading_store(struct device *dev,
fw_priv->nr_pages = 0;
fw_priv->fw->size = 0;
set_bit(FW_STATUS_LOADING, &fw_priv->status);
- mutex_unlock(&fw_lock);
break;
case 0:
if (test_bit(FW_STATUS_LOADING, &fw_priv->status)) {
@@ -195,6 +193,7 @@ static ssize_t firmware_loading_store(struct device *dev,
fw_load_abort(fw_priv);
break;
}
+ mutex_unlock(&fw_lock);
return count;
}
next prev parent reply other threads:[~2009-09-23 16:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-16 18:44 Oops in drivers\base\firmware_class Lars Ericsson
2009-09-16 20:57 ` Frederik Deweerdt
2009-09-18 17:53 ` Lars Ericsson
2009-09-21 13:32 ` [patch -stable] firware_class oops: fix firmware_loading_store locking Frederik Deweerdt
2009-09-23 16:42 ` Linus Torvalds [this message]
2009-09-24 15:13 ` Sachin Sant
2009-09-24 15:26 ` Frederik Deweerdt
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=alpine.LFD.2.01.0909230936320.3303@localhost.localdomain \
--to=torvalds@linux-foundation.org \
--cc=David.Woodhouse@intel.com \
--cc=Lars_Ericsson@telia.com \
--cc=frederik.deweerdt@xprog.eu \
--cc=greg@kroah.org \
--cc=ivdoorn@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sachinp@in.ibm.com \
/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®