stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: loop: fix filesystem corruption in case of aio/dio
@ 2016-04-15 10:51 Ming Lei
       [not found] ` <5710E3C9.6020408@googlemail.com>
  2016-04-15 14:25 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Ming Lei @ 2016-04-15 10:51 UTC (permalink / raw)
  To: Jens Axboe, linux-kernel
  Cc: linux-block, Christoph Hellwig, Ming Lei, Keith Busch, Al Viro,
	4.5

Starting from commit e36f620428(block: split bios to max possible length),
block core starts to split bio in the middle of bvec.

Unfortunately loop dio/aio doesn't consider this situation, and
always treat 'iter.iov_offset' as zero. Then filesystem corruption
is observed.

This patch figures out the offset of the base bvevc via
'bio->bi_iter.bi_bvec_done' and fixes the issue by passing the offset
to iov iterator.

Fixes: e36f6204288088f (block: split bios to max possible length)
Cc: Keith Busch <keith.busch@intel.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: stable@vger.kernel.org (4.5)
Signed-off-by: Ming Lei <ming.lei@canonical.com>
---
 drivers/block/loop.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 7e5e27a..1fa8cc2 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -488,6 +488,12 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
 	bvec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
 	iov_iter_bvec(&iter, ITER_BVEC | rw, bvec,
 		      bio_segments(bio), blk_rq_bytes(cmd->rq));
+	/*
+	 * This bio may be started from the middle of the 'bvec'
+	 * because of bio splitting, so offset from the bvec must
+	 * be passed to iov iterator
+	 */
+	iter.iov_offset = bio->bi_iter.bi_bvec_done;
 
 	cmd->iocb.ki_pos = pos;
 	cmd->iocb.ki_filp = file;
-- 
1.9.1


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

* Re: [PATCH] block: loop: fix filesystem corruption in case of aio/dio
       [not found]   ` <CACVXFVND3phh95c+_Yr+OYhDuWWdL681Q6_A8-2ho4j2YLoJQA@mail.gmail.com>
@ 2016-04-15 13:50     ` Holger Hoffstätte
  0 siblings, 0 replies; 3+ messages in thread
From: Holger Hoffstätte @ 2016-04-15 13:50 UTC (permalink / raw)
  To: Ming Lei, Jens Axboe, linux-kernel, linux-block, stable
  Cc: Christoph Hellwig, Keith Busch

-------- Forwarded Message --------
Subject: Re: [PATCH] block: loop: fix filesystem corruption in case of aio/dio
Date: Fri, 15 Apr 2016 21:16:42 +0800
From: Ming Lei <ming.lei@canonical.com>
To: Holger Hoffstätte <holger.hoffstaette@googlemail.com>

On Fri, Apr 15, 2016 at 8:51 PM, Holger Hoffstätte
<holger.hoffstaette@googlemail.com> wrote:
> (off-list since I'm likely missing something..)
>
> Hello Ming Lei,
>
> quick question -
>
> On 04/15/16 12:51, Ming Lei wrote:
>> Starting from commit e36f620428(block: split bios to max possible length),
>> block core starts to split bio in the middle of bvec.
>>
>> Unfortunately loop dio/aio doesn't consider this situation, and
>> always treat 'iter.iov_offset' as zero. Then filesystem corruption
>> is observed.
>>
>> This patch figures out the offset of the base bvevc via
>> 'bio->bi_iter.bi_bvec_done' and fixes the issue by passing the offset
>> to iov iterator.
>>
>> Fixes: e36f6204288088f (block: split bios to max possible length)
>> Cc: Keith Busch <keith.busch@intel.com>
>> Cc: Al Viro <viro@zeniv.linux.org.uk>
>> Cc: stable@vger.kernel.org (4.5)
>                              ^^^^^
>
> The previous patch went into 4.4.x-stable, so should this one not go
> into 4.4.x as well? It applies cleanly and does not seem to hurt.
> Apologies in advance if this is a bad idea. :)

You are absolutely right, this patch should have been marked as stable 4.4+,
thanks for point it out!

Jens, please let me know if you need me to resend the patch for fixing
the stable tag.

Thanks,
Ming

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

* Re: [PATCH] block: loop: fix filesystem corruption in case of aio/dio
  2016-04-15 10:51 [PATCH] block: loop: fix filesystem corruption in case of aio/dio Ming Lei
       [not found] ` <5710E3C9.6020408@googlemail.com>
@ 2016-04-15 14:25 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2016-04-15 14:25 UTC (permalink / raw)
  To: Ming Lei, linux-kernel
  Cc: linux-block, Christoph Hellwig, Keith Busch, Al Viro, 4.5

On 04/15/2016 04:51 AM, Ming Lei wrote:
> Starting from commit e36f620428(block: split bios to max possible length),
> block core starts to split bio in the middle of bvec.
>
> Unfortunately loop dio/aio doesn't consider this situation, and
> always treat 'iter.iov_offset' as zero. Then filesystem corruption
> is observed.
>
> This patch figures out the offset of the base bvevc via
> 'bio->bi_iter.bi_bvec_done' and fixes the issue by passing the offset
> to iov iterator.
>
> Fixes: e36f6204288088f (block: split bios to max possible length)
> Cc: Keith Busch <keith.busch@intel.com>
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> Cc: stable@vger.kernel.org (4.5)
> Signed-off-by: Ming Lei <ming.lei@canonical.com>

Thanks Ming, queued up.

-- 
Jens Axboe


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

end of thread, other threads:[~2016-04-15 14:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-15 10:51 [PATCH] block: loop: fix filesystem corruption in case of aio/dio Ming Lei
     [not found] ` <5710E3C9.6020408@googlemail.com>
     [not found]   ` <CACVXFVND3phh95c+_Yr+OYhDuWWdL681Q6_A8-2ho4j2YLoJQA@mail.gmail.com>
2016-04-15 13:50     ` Holger Hoffstätte
2016-04-15 14:25 ` Jens Axboe

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