Files
kernel_nothing_sm7325/block
Ming Lei 3aeff14796 UPSTREAM: blk-mq: fix kernel panic during iterating over flush request
For fixing use-after-free during iterating over requests, we grabbed
request's refcount before calling ->fn in commit 2e315dc07df0 ("blk-mq:
grab rq->refcount before calling ->fn in blk_mq_tagset_busy_iter").
Turns out this way may cause kernel panic when iterating over one flush
request:

1) old flush request's tag is just released, and this tag is reused by
one new request, but ->rqs[] isn't updated yet

2) the flush request can be re-used for submitting one new flush command,
so blk_rq_init() is called at the same time

3) meantime blk_mq_queue_tag_busy_iter() is called, and old flush request
is retrieved from ->rqs[tag]; when blk_mq_put_rq_ref() is called,
flush_rq->end_io may not be updated yet, so NULL pointer dereference
is triggered in blk_mq_put_rq_ref().

Fix the issue by calling refcount_set(&flush_rq->ref, 1) after
flush_rq->end_io is set. So far the only other caller of blk_rq_init() is
scsi_ioctl_reset() in which the request doesn't enter block IO stack and
the request reference count isn't used, so the change is safe.

Fixes: 2e315dc07df0 ("blk-mq: grab rq->refcount before calling ->fn in blk_mq_tagset_busy_iter")
Reported-by: "Blank-Burian, Markus, Dr." <blankburian@uni-muenster.de>
Tested-by: "Blank-Burian, Markus, Dr." <blankburian@uni-muenster.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.garry@huawei.com>
Link: https://lore.kernel.org/r/20210811142624.618598-1-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
(cherry picked from commit c2da19ed50554ce52ecbad3655c98371fe58599f)
Bug: 187129171
Signed-off-by: Connor O'Brien <connoro@google.com>
Change-Id: Id7fb5f38b0fe35331df98ec2f96e4914f15d981c
2022-01-24 11:41:01 -08:00
..
2020-09-03 11:26:54 +02:00
2020-09-03 11:26:54 +02:00
2020-09-03 11:26:54 +02:00
2021-04-16 12:16:55 +02:00
2021-11-17 10:19:21 +01:00
2021-01-06 09:12:49 -08:00
2021-08-31 18:35:29 +00:00
2019-10-14 13:54:09 -06:00
2020-01-07 16:02:49 -08:00
2019-07-15 09:20:27 -03:00
2020-01-31 16:27:30 -08:00
2019-07-15 09:20:27 -03:00
2019-09-23 08:05:19 -06:00