aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/firmware_class.c
diff options
context:
space:
mode:
authorChuansheng Liu <chuansheng.liu@intel.com>2012-11-09 12:27:22 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-11-14 18:04:23 -0500
commitbd9eb7fbe69111ea0ff1f999ef4a5f26d223d1d5 (patch)
treef8dbda4472687bebbb757a0835c6d1441a984abc /drivers/base/firmware_class.c
parentce2fcbd99cef580623116bb33531dbc3e6f690b0 (diff)
firmware loader: Fix the concurrent request_firmware() race for kref_get/put
There is one race that both request_firmware() with the same firmware name. The race scenerio is as below: CPU1 CPU2 request_firmware() --> _request_firmware_load() return err another request_firmware() is coming --> _request_firmware_cleanup is called --> _request_firmware_prepare --> release_firmware ---> fw_lookup_and_allocate_buf --> spin_lock(&fwc->lock) ... __fw_lookup_buf() return true fw_free_buf() will be called --> ... kref_put --> decrease the refcount to 0 kref_get(&tmp->ref) ==> it will trigger warning due to refcount == 0 __fw_free_buf() --> ... spin_unlock(&fwc->lock) spin_lock(&fwc->lock) list_del(&buf->list) spin_unlock(&fwc->lock) kfree(buf) After that, the freed buf will be used. The key race is decreasing refcount to 0 and list_del is not protected together by fwc->lock, and it is possible another thread try to get it between refcount==0 and list_del. Fix it here to protect it together. Acked-by: Ming Lei <ming.lei@canonical.com> Signed-off-by: liu chuansheng <chuansheng.liu@intel.com> Cc: stable <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base/firmware_class.c')
-rw-r--r--drivers/base/firmware_class.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index b44ed35ac38d..be5f7aae75fc 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -246,7 +246,6 @@ static void __fw_free_buf(struct kref *ref)
246 __func__, buf->fw_id, buf, buf->data, 246 __func__, buf->fw_id, buf, buf->data,
247 (unsigned int)buf->size); 247 (unsigned int)buf->size);
248 248
249 spin_lock(&fwc->lock);
250 list_del(&buf->list); 249 list_del(&buf->list);
251 spin_unlock(&fwc->lock); 250 spin_unlock(&fwc->lock);
252 251
@@ -263,7 +262,10 @@ static void __fw_free_buf(struct kref *ref)
263 262
264static void fw_free_buf(struct firmware_buf *buf) 263static void fw_free_buf(struct firmware_buf *buf)
265{ 264{
266 kref_put(&buf->ref, __fw_free_buf); 265 struct firmware_cache *fwc = buf->fwc;
266 spin_lock(&fwc->lock);
267 if (!kref_put(&buf->ref, __fw_free_buf))
268 spin_unlock(&fwc->lock);
267} 269}
268 270
269/* direct firmware loading support */ 271/* direct firmware loading support */