aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorNeil Horman <nhorman@tuxdriver.com>2012-01-02 15:31:23 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2012-01-04 19:31:29 -0500
commiteea915bb0d1358755f151eaefb8208a2d5f3e10c (patch)
tree35d593bde3caa1b79751e0ec1a6c6333b2a72506 /drivers/base
parent8f257a142fc3868d69de3f996b95d7bdbc509560 (diff)
firmware: Fix an oops on reading fw_priv->fw in sysfs loading file
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: stable <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/firmware_class.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 06ed6b4e7df5..3719c94be19c 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,
226 int loading = simple_strtol(buf, NULL, 10); 226 int loading = simple_strtol(buf, NULL, 10);
227 int i; 227 int i;
228 228
229 mutex_lock(&fw_lock);
230
231 if (!fw_priv->fw)
232 goto out;
233
229 switch (loading) { 234 switch (loading) {
230 case 1: 235 case 1:
231 mutex_lock(&fw_lock);
232 if (!fw_priv->fw) {
233 mutex_unlock(&fw_lock);
234 break;
235 }
236 firmware_free_data(fw_priv->fw); 236 firmware_free_data(fw_priv->fw);
237 memset(fw_priv->fw, 0, sizeof(struct firmware)); 237 memset(fw_priv->fw, 0, sizeof(struct firmware));
238 /* If the pages are not owned by 'struct firmware' */ 238 /* If the pages are not owned by 'struct firmware' */
@@ -243,7 +243,6 @@ static ssize_t firmware_loading_store(struct device *dev,
243 fw_priv->page_array_size = 0; 243 fw_priv->page_array_size = 0;
244 fw_priv->nr_pages = 0; 244 fw_priv->nr_pages = 0;
245 set_bit(FW_STATUS_LOADING, &fw_priv->status); 245 set_bit(FW_STATUS_LOADING, &fw_priv->status);
246 mutex_unlock(&fw_lock);
247 break; 246 break;
248 case 0: 247 case 0:
249 if (test_bit(FW_STATUS_LOADING, &fw_priv->status)) { 248 if (test_bit(FW_STATUS_LOADING, &fw_priv->status)) {
@@ -274,7 +273,8 @@ static ssize_t firmware_loading_store(struct device *dev,
274 fw_load_abort(fw_priv); 273 fw_load_abort(fw_priv);
275 break; 274 break;
276 } 275 }
277 276out:
277 mutex_unlock(&fw_lock);
278 return count; 278 return count;
279} 279}
280 280