From: Ming Lei <ming.lei@redhat.com>
To: Yufen Yu <yuyufen@huawei.com>
Cc: axboe@kernel.dk, linux-block@vger.kernel.org, hch@infradead.org,
keith.busch@intel.com, tj@kernel.org, zhangxiaoxu5@huawei.com
Subject: Re: [PATCH] block: fix null pointer dereference in blk_mq_rq_timed_out()
Date: Thu, 12 Sep 2019 12:16:59 +0800 [thread overview]
Message-ID: <20190912041658.GA5020@ming.t460p> (raw)
In-Reply-To: <b3d7b459-5f31-d473-2508-20048119c1b2@huawei.com>
On Thu, Sep 12, 2019 at 11:29:18AM +0800, Yufen Yu wrote:
>
>
> On 2019/9/12 10:46, Ming Lei wrote:
> > On Sat, Sep 07, 2019 at 06:24:50PM +0800, Yufen Yu wrote:
> > > There is a race condition between timeout check and completion for
> > > flush request as follow:
> > >
> > > timeout_work issue flush issue flush
> > > blk_insert_flush
> > > blk_insert_flush
> > > blk_mq_timeout_work
> > > blk_kick_flush
> > >
> > > blk_mq_queue_tag_busy_iter
> > > blk_mq_check_expired(flush_rq)
> > >
> > > __blk_mq_end_request
> > > flush_end_io
> > > blk_kick_flush
> > > blk_rq_init(flush_rq)
> > > memset(flush_rq, 0)
> > Not see there is memset(flush_rq, 0) in block/blk-flush.c
>
> Call path as follow:
>
> blk_kick_flush
> blk_rq_init
> memset(rq, 0, sizeof(*rq));
Looks I miss this one in blk_rq_init(), sorry for that.
Given there are only two users of blk_rq_init(), one simple fix could be
not clearing queue in blk_rq_init(), something like below?
diff --git a/block/blk-core.c b/block/blk-core.c
index 77807a5d7f9e..25e6a045c821 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -107,7 +107,9 @@ EXPORT_SYMBOL_GPL(blk_queue_flag_test_and_set);
void blk_rq_init(struct request_queue *q, struct request *rq)
{
- memset(rq, 0, sizeof(*rq));
+ const int offset = offsetof(struct request, q);
+
+ memset((void *)rq + offset, 0, sizeof(*rq) - offset);
INIT_LIST_HEAD(&rq->queuelist);
rq->q = q;
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 1ac790178787..382e71b8787d 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -130,7 +130,7 @@ enum mq_rq_state {
* especially blk_mq_rq_ctx_init() to take care of the added fields.
*/
struct request {
- struct request_queue *q;
+ struct request_queue *q; /* Must be the 1st field */
struct blk_mq_ctx *mq_ctx;
struct blk_mq_hw_ctx *mq_hctx;
Thanks,
Ming
next prev parent reply other threads:[~2019-09-12 4:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-07 10:24 [PATCH] block: fix null pointer dereference in blk_mq_rq_timed_out() Yufen Yu
2019-09-12 2:46 ` Ming Lei
2019-09-12 3:29 ` Yufen Yu
2019-09-12 4:16 ` Ming Lei [this message]
2019-09-12 8:49 ` Yufen Yu
2019-09-12 10:07 ` Ming Lei
2019-09-16 2:40 ` Yufen Yu
2019-09-16 9:27 ` Yufen Yu
2019-09-17 0:50 ` Ming Lei
2019-09-12 8:59 ` Guoqing Jiang
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=20190912041658.GA5020@ming.t460p \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=hch@infradead.org \
--cc=keith.busch@intel.com \
--cc=linux-block@vger.kernel.org \
--cc=tj@kernel.org \
--cc=yuyufen@huawei.com \
--cc=zhangxiaoxu5@huawei.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;
as well as URLs for NNTP newsgroup(s).