All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] firmware: Fix an oops on reading fw_priv->fw in sysfs loading file
@ 2012-01-02 20:31 Neil Horman
  2012-01-03  1:12 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Neil Horman @ 2012-01-02 20:31 UTC (permalink / raw)
  To: linux-kernel; +Cc: Neil Horman, Greg Kroah-Hartman, stable

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>
CC: Greg Kroah-Hartman <greg@kroah.com>
CC: stable@kernel.org
---
 drivers/base/firmware_class.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 06ed6b4..3719c94 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -226,13 +226,13 @@ static ssize_t firmware_loading_store(struct device *dev,
 	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' */
@@ -243,7 +243,6 @@ static ssize_t firmware_loading_store(struct device *dev,
 		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)) {
@@ -274,7 +273,8 @@ static ssize_t firmware_loading_store(struct device *dev,
 		fw_load_abort(fw_priv);
 		break;
 	}
-
+out:
+	mutex_unlock(&fw_lock);
 	return count;
 }
 
-- 
1.7.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] firmware: Fix an oops on reading fw_priv->fw in sysfs loading file
  2012-01-02 20:31 [PATCH] firmware: Fix an oops on reading fw_priv->fw in sysfs loading file Neil Horman
@ 2012-01-03  1:12 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2012-01-03  1:12 UTC (permalink / raw)
  To: Neil Horman; +Cc: linux-kernel, stable

On Mon, Jan 02, 2012 at 03:31:23PM -0500, Neil Horman wrote:
> 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.

Thanks, this patch should also fix the same problem that the Motorola
developers were seeing, yet failed to create a useful patch for :)

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-01-03  1:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-02 20:31 [PATCH] firmware: Fix an oops on reading fw_priv->fw in sysfs loading file Neil Horman
2012-01-03  1:12 ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.