linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Bart Van Assche <bvanassche@acm.org>, Tejun Heo <tj@kernel.org>,
	Ming Lei <ming.lei@redhat.com>, Hannes Reinecke <hare@suse.com>,
	Johannes Thumshirn <jthumshirn@suse.de>,
	Alexandru Moise <00moses.alexander00@gmail.com>,
	Joseph Qi <joseph.qi@linux.alibaba.com>,
	syzbot+ff9ab4a23afa7553@syzkaller.appspotmail.com
Subject: [PATCH 2/2] block: Fix a race condition in submit_bio()
Date: Tue, 30 Jul 2019 11:17:57 -0700	[thread overview]
Message-ID: <20190730181757.248832-3-bvanassche@acm.org> (raw)
In-Reply-To: <20190730181757.248832-1-bvanassche@acm.org>

generic_make_request_checks() needs to be protected by a
blk_queue_enter() / blk_queue_exit() pair because it calls
blkcg_bio_issue_check() and because that last function calls
blkg_lookup().

This patch fixes https://syzkaller.appspot.com/bug?id=ff9ab4a23afa7553fb79f745a92be87ba4144508.

This patch also fixes the following kernel warning, triggered by
blktests:

WARNING: CPU: 5 PID: 10706 at block/blk-core.c:903 generic_make_request_checks+0x9c6/0xe60
RIP: 0010:generic_make_request_checks+0x9c6/0xe60
Call Trace:
 generic_make_request+0x7a/0x5c0
 submit_bio+0x92/0x280
 mpage_readpages+0x2b1/0x300
 blkdev_readpages+0x1d/0x20
 read_pages+0xd9/0x2c0
 __do_page_cache_readahead+0x2e0/0x310
 force_page_cache_readahead+0xfb/0x170
 page_cache_sync_readahead+0x28d/0x2a0
 generic_file_read_iter+0xc13/0x1530
 blkdev_read_iter+0x7d/0x90
 new_sync_read+0x2c5/0x3d0
 __vfs_read+0x7b/0x90
 vfs_read+0xc6/0x1f0
 ksys_read+0xc3/0x160
 __x64_sys_read+0x43/0x50
 do_syscall_64+0x71/0x270
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Cc: Tejun Heo <tj@kernel.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Cc: Alexandru Moise <00moses.alexander00@gmail.com>
Cc: Joseph Qi <joseph.qi@linux.alibaba.com>
Reported-by: syzbot+ff9ab4a23afa7553@syzkaller.appspotmail.com
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 block/blk-core.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index ff27c3080348..cd844c54e9f1 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1150,6 +1150,9 @@ EXPORT_SYMBOL_GPL(direct_make_request);
  */
 blk_qc_t submit_bio(struct bio *bio)
 {
+	struct request_queue *q = bio->bi_disk->queue;
+	blk_qc_t ret;
+
 	if (blkcg_punt_bio_submit(bio))
 		return BLK_QC_T_NONE;
 
@@ -1182,7 +1185,15 @@ blk_qc_t submit_bio(struct bio *bio)
 		}
 	}
 
-	return generic_make_request(bio);
+	if (unlikely(blk_queue_enter(q, 0) < 0)) {
+		bio->bi_status = BLK_STS_IOERR;
+		bio->bi_end_io(bio);
+		return BLK_QC_T_NONE;
+	}
+	ret = generic_make_request(bio);
+	blk_queue_exit(q);
+
+	return ret;
 }
 EXPORT_SYMBOL(submit_bio);
 
-- 
2.22.0.709.g102302147b-goog


  parent reply	other threads:[~2019-07-30 18:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-30 18:17 [PATCH 0/2] Fix a race condition triggered by submit_bio() Bart Van Assche
2019-07-30 18:17 ` [PATCH 1/2] block: Verify whether blk_queue_enter() is used when necessary Bart Van Assche
2019-07-31  1:46   ` Ming Lei
2019-07-31 18:26     ` Bart Van Assche
2019-07-30 18:17 ` Bart Van Assche [this message]
2019-07-30 18:18   ` [PATCH 2/2] block: Fix a race condition in submit_bio() syzbot
2019-07-31  1:53   ` Ming Lei
2019-07-31  1:53     ` syzbot

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=20190730181757.248832-3-bvanassche@acm.org \
    --to=bvanassche@acm.org \
    --cc=00moses.alexander00@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=joseph.qi@linux.alibaba.com \
    --cc=jthumshirn@suse.de \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=syzbot+ff9ab4a23afa7553@syzkaller.appspotmail.com \
    --cc=tj@kernel.org \
    /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).