mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: torvalds@linux-foundation.org, akpm@linux-foundation.org,
	alan@lxorguk.ukuu.org.uk, Neil Horman <nhorman@tuxdriver.com>
Subject: [03/20] firmware: Fix an oops on reading fw_priv->fw in sysfs loading file
Date: Tue, 10 Jan 2012 12:06:54 -0800	[thread overview]
Message-ID: <20120110200850.032402629@clark.kroah.org> (raw)
In-Reply-To: <20120110200902.GA5674@kroah.com>

2.6.32-longterm review patch.  If anyone has any objections, please let me know.

------------------

From: Neil Horman <nhorman@tuxdriver.com>

commit eea915bb0d1358755f151eaefb8208a2d5f3e10c upstream.

This oops was reported recently:
firmware_loading_store+0xf9/0x17b
dev_attr_store+0x20/0x22
sysfs_write_file+0x101/0x134
vfs_write+0xac/0xf3
sys_write+0x4a/0x6e
system_call_fastpath+0x16/0x1b

The complete backtrace was unfortunately not captured, but details can be found
here:
https://bugzilla.redhat.com/show_bug.cgi?id=769920

The cause is fairly clear.

Its caused by the fact that firmware_loading_store has a case 0 in its
switch statement that reads and writes the fw_priv->fw poniter without the
protection of the fw_lock mutex.  since there is a window between the time that
_request_firmware sets fw_priv->fw to NULL and the time the corresponding sysfs
file is unregistered, its possible for a user space application to race in, and
write a zero to the loading file, causing a NULL dereference in
firmware_loading_store.  Fix it by extending the protection of the fw_lock mutex
to cover all of the firware_loading_store function.

Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/base/firmware_class.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -161,13 +161,13 @@ static ssize_t firmware_loading_store(st
 	int loading = simple_strtol(buf, NULL, 10);
 	int i;
 
+	mutex_lock(&fw_lock);
+
+	if (!fw_priv->fw)
+		goto out;
+
 	switch (loading) {
 	case 1:
-		mutex_lock(&fw_lock);
-		if (!fw_priv->fw) {
-			mutex_unlock(&fw_lock);
-			break;
-		}
 		firmware_free_data(fw_priv->fw);
 		memset(fw_priv->fw, 0, sizeof(struct firmware));
 		/* If the pages are not owned by 'struct firmware' */
@@ -178,7 +178,6 @@ static ssize_t firmware_loading_store(st
 		fw_priv->page_array_size = 0;
 		fw_priv->nr_pages = 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)) {
@@ -209,7 +208,8 @@ static ssize_t firmware_loading_store(st
 		fw_load_abort(fw_priv);
 		break;
 	}
-
+out:
+	mutex_unlock(&fw_lock);
 	return count;
 }
 



  parent reply	other threads:[~2012-01-10 20:10 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-10 20:09 [00/20] 2.6.32.54-longterm review Greg KH
2012-01-10 20:06 ` [01/20] MAINTAINERS: stable: Update address Greg KH
2012-01-10 20:06 ` [02/20] Documentation: Update stable address Greg KH
2012-01-10 20:06 ` Greg KH [this message]
2012-01-10 20:06 ` [04/20] offb: Fix setting of the pseudo-palette for >8bpp Greg KH
2012-01-10 20:06 ` [05/20] offb: Fix bug in calculating requested vram size Greg KH
2012-01-10 20:06 ` [06/20] asix: new device id Greg KH
2012-01-10 20:06 ` [07/20] reiserfs: Fix quota mount option parsing Greg KH
2012-01-10 20:06 ` [08/20] reiserfs: Force inode evictions before umount to avoid crash Greg KH
2012-01-10 20:07 ` [09/20] USB: update documentation for usbmon Greg KH
2012-01-10 20:07 ` [10/20] drivers/usb/class/cdc-acm.c: clear dangling pointer Greg KH
2012-01-10 20:07 ` [11/20] USB: isight: fix kernel bug when loading firmware Greg KH
2012-01-10 20:07 ` [12/20] usb: usb-storage doesnt support dynamic id currently, the patch disables the feature to fix an oops Greg KH
2012-01-10 20:07 ` [13/20] USB: add quirk for another camera Greg KH
2012-01-10 20:07 ` [14/20] USB: omninet: fix write_room Greg KH
2012-01-10 20:07 ` [15/20] USB: Add USB-ID for Multiplex RC serial adapter to cp210x.c Greg KH
2012-01-10 20:07 ` [16/20] asix: fix infinite loop in rx_fixup() Greg KH
2012-01-10 20:07 ` [17/20] PM / Sleep: Fix race between CPU hotplug and freezer Greg KH
2012-01-10 20:07 ` [18/20] SCSI: scsi_dh: check queuedata pointer before proceeding further Greg KH
2012-01-10 20:07 ` [19/20] xfs: validate acl count Greg KH
2012-01-10 20:07 ` [20/20] xfs: fix acl count validation in xfs_acl_from_disk() Greg KH

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=20120110200850.032402629@clark.kroah.org \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.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®