linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <n.borisov.lkml@gmail.com>
To: Liu Bo <bo.li.liu@oracle.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] Btrfs: fix segment fault when doing dio read
Date: Sun, 9 Apr 2017 20:08:05 +0300	[thread overview]
Message-ID: <5afa50b0-2e6c-d3fa-4dd8-dedbdf1af8b4@gmail.com> (raw)
In-Reply-To: <1491595870-9633-1-git-send-email-bo.li.liu@oracle.com>



On  7.04.2017 23:11, Liu Bo wrote:
> Commit 2dabb3248453 ("Btrfs: Direct I/O read: Work on sectorsized blocks")
> introduced this bug during iterating bio pages in dio read's endio hook,
> and it could end up with segment fault of the dio reading task.
> 
> So the reason is 'if (nr_sectors--)', and it makes the code assume that
> there is one more block in the same page, so page offset is increased and
> the bio which is created to repair the bad block then has an incorrect
> bvec.bv_offset, and a later access of the page content would throw a
> segment fault.
> 
> This also adds ASSERT to check page offset against page size.
> 
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> ---
>  fs/btrfs/inode.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index c875e68..5e71f1e 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -7972,8 +7972,10 @@ static int __btrfs_correct_data_nocsum(struct inode *inode,
>  
>  		start += sectorsize;
>  
> -		if (nr_sectors--) {
> +		nr_sectors--;
Why not if(--nr_sectors)? I know it's more of a style issue but it will
reduce the size of the diff ?
> +		if (nr_sectors) {
>  			pgoff += sectorsize;
> +			ASSERT(pgoff < PAGE_SIZE);
>  			goto next_block_or_try_again;
>  		}
>  	}
> @@ -8074,8 +8076,10 @@ static int __btrfs_subio_endio_read(struct inode *inode,
>  
>  		ASSERT(nr_sectors);
>  
> -		if (--nr_sectors) {
> +		nr_sectors--;
> +		if (nr_sectors) {
>  			pgoff += sectorsize;
> +			ASSERT(pgoff < PAGE_SIZE);
>  			goto next_block;
>  		}
>  	}
> 

  reply	other threads:[~2017-04-09 17:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-07 20:11 [PATCH] Btrfs: fix segment fault when doing dio read Liu Bo
2017-04-09 17:08 ` Nikolay Borisov [this message]
2017-04-10 16:26   ` David Sterba
2017-04-10 18:32   ` Liu Bo

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=5afa50b0-2e6c-d3fa-4dd8-dedbdf1af8b4@gmail.com \
    --to=n.borisov.lkml@gmail.com \
    --cc=bo.li.liu@oracle.com \
    --cc=linux-btrfs@vger.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).