mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Akinobu Mita <akinobu.mita@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Akinobu Mita <akinobu.mita@gmail.com>,
	Jens Axboe <axboe@kernel.dk>, Ming Lei <tom.leiming@gmail.com>
Subject: [PATCH v2 2/6] blk-mq: Fix use after of free q->mq_map
Date: Thu,  2 Jul 2015 23:29:53 +0900	[thread overview]
Message-ID: <1435847397-724-3-git-send-email-akinobu.mita@gmail.com> (raw)
In-Reply-To: <1435847397-724-1-git-send-email-akinobu.mita@gmail.com>

CPU hotplug handling for blk-mq (blk_mq_queue_reinit) updates
q->mq_map by blk_mq_update_queue_map() for all request queues in
all_q_list.  On the other hand, q->mq_map is released before deleting
the queue from all_q_list.

So if CPU hotplug event occurs in the window, invalid memory access
can happen.  Fix it by releasing q->mq_map in blk_mq_release() to make
it happen latter than removal from all_q_list.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Suggested-by: Ming Lei <tom.leiming@gmail.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Ming Lei <tom.leiming@gmail.com>
---
 block/blk-mq.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index f537796..c5da908 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1928,6 +1928,9 @@ void blk_mq_release(struct request_queue *q)
 		kfree(hctx);
 	}
 
+	kfree(q->mq_map);
+	q->mq_map = NULL;
+
 	kfree(q->queue_hw_ctx);
 
 	/* ctx kobj stays in queue_ctx */
@@ -2073,11 +2076,6 @@ void blk_mq_free_queue(struct request_queue *q)
 	blk_mq_free_hw_queues(q, set);
 
 	percpu_ref_exit(&q->mq_usage_counter);
-
-	kfree(q->mq_map);
-
-	q->mq_map = NULL;
-
 	mutex_lock(&all_q_mutex);
 	list_del_init(&q->all_q_node);
 	mutex_unlock(&all_q_mutex);
-- 
1.9.1


  parent reply	other threads:[~2015-07-02 14:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-02 14:29 [PATCH v2 0/6] blk-mq: fix race conditions on cpu hotplug handling Akinobu Mita
2015-07-02 14:29 ` [PATCH v2 1/6] blk-mq: fix sysfs registration/unregistration race Akinobu Mita
2015-07-08 11:48   ` Ming Lei
2015-07-09 14:25     ` Akinobu Mita
2015-07-09 14:43       ` Ming Lei
2015-07-02 14:29 ` Akinobu Mita [this message]
2015-07-08 11:53   ` [PATCH v2 2/6] blk-mq: Fix use after of free q->mq_map Ming Lei
2015-07-02 14:29 ` [PATCH v2 3/6] blk-mq: fix q->mq_usage_counter access race Akinobu Mita
2015-07-08 11:53   ` Ming Lei
2015-07-02 14:29 ` [PATCH v2 4/6] blk-mq: avoid inserting requests before establishing new mapping Akinobu Mita
2015-07-09  7:04   ` Ming Lei
2015-07-02 14:29 ` [PATCH v2 5/6] blk-mq: fix freeze queue race Akinobu Mita
2015-07-09  6:55   ` Ming Lei
2015-07-09 21:37     ` Tejun Heo
2015-07-10  8:08       ` Ming Lei
2015-07-09 21:34   ` Tejun Heo
2015-07-02 14:29 ` [PATCH v2 6/6] blk-mq: fix deadlock when reading cpu_list Akinobu Mita

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=1435847397-724-3-git-send-email-akinobu.mita@gmail.com \
    --to=akinobu.mita@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tom.leiming@gmail.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

Powered by JetHome