linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block_dev: fix crash on chained bios with O_DIRECT
@ 2019-03-20  8:12 Hannes Reinecke
  2019-03-20  8:45 ` Johannes Thumshirn
  0 siblings, 1 reply; 8+ messages in thread
From: Hannes Reinecke @ 2019-03-20  8:12 UTC (permalink / raw)
  To: Jan Kara
  Cc: Jens Axboe, linux-block, linux-fsdevel, Hannes Reinecke, Hannes Reinecke

__blkdev_direct_IO_simple() is allocating a bio on the stack.
When that bio needs to be split bio_chain_endio() invokes bio_put()
on this bio, causing the kernel to crash in mempool_free() as the
bio was never allocated from a mempool in the first place.
So call bio_get() before submitting to avoid this problem.

Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 fs/block_dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index c546cdce77e6..4b3a04c3b8bd 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -235,6 +235,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,
 	if (iocb->ki_flags & IOCB_HIPRI)
 		bio.bi_opf |= REQ_HIPRI;
 
+	bio_get(&bio);
 	qc = submit_bio(&bio);
 	for (;;) {
 		set_current_state(TASK_UNINTERRUPTIBLE);
@@ -254,7 +255,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,
 
 	if (unlikely(bio.bi_status))
 		ret = blk_status_to_errno(bio.bi_status);
-
+	bio_put(&bio);
 out:
 	if (vecs != inline_vecs)
 		kfree(vecs);
-- 
2.16.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-03-21  8:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-20  8:12 [PATCH] block_dev: fix crash on chained bios with O_DIRECT Hannes Reinecke
2019-03-20  8:45 ` Johannes Thumshirn
2019-03-20  8:51   ` Hannes Reinecke
2019-03-20  8:53     ` Johannes Thumshirn
2019-03-20 11:47       ` Jan Kara
2019-03-20 13:19         ` Johannes Thumshirn
2019-03-20 19:57           ` Jens Axboe
2019-03-21  8:28             ` Johannes Thumshirn

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).