All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Liu Bo <bo.li.liu@oracle.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] Btrfs: fix divide error upon chunk's stripe_len
Date: Fri, 29 Apr 2016 18:22:26 +0200	[thread overview]
Message-ID: <20160429162226.GB29353@suse.cz> (raw)
In-Reply-To: <20160428174836.GA12012@localhost.localdomain>

On Thu, Apr 28, 2016 at 10:48:36AM -0700, Liu Bo wrote:
> On Wed, Apr 27, 2016 at 07:33:18PM +0200, David Sterba wrote:
> > On Wed, Apr 27, 2016 at 10:23:35AM -0700, Liu Bo wrote:
> > > On Wed, Apr 27, 2016 at 06:39:03PM +0200, David Sterba wrote:
> > > > On Tue, Apr 26, 2016 at 05:53:31PM -0700, Liu Bo wrote:
> > > > > The struct 'map_lookup' uses type int for @stripe_len, while
> > > > > btrfs_chunk_stripe_len() can return a u64 value, and it may end up with
> > > > > @stripe_len being undefined value and it can lead to 'divide error' in
> > > > >  __btrfs_map_block().
> > > > > 
> > > > > This changes 'map_lookup' to use type u64 for stripe_len, also right now
> > > > > we only use BTRFS_STRIPE_LEN for stripe_len, so this adds a valid checker for
> > > > > BTRFS_STRIPE_LEN.
> > > > > 
> > > > > Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
> > > > > Reported-by: Quentin Casasnovas <quentin.casasnovas@oracle.com>
> > > > 
> > > > I smell some fuzzing :) do you have the image available? I'll add it to
> > > > the rest in btrfsprogs.
> > > 
> > > Sure, it's on the way, I'll send it along with a patch for btrfsck (we
> > > have to add the same validation check for superblock and chunk in
> > > btrfsck.)
> > 
> > Great!
> > 
> > > > > Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> > > > > ---
> > > > >  fs/btrfs/volumes.c | 2 +-
> > > > >  fs/btrfs/volumes.h | 2 +-
> > > > >  2 files changed, 2 insertions(+), 2 deletions(-)
> > > > > 
> > > > > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> > > > > index e2b54d5..b5cb859 100644
> > > > > --- a/fs/btrfs/volumes.c
> > > > > +++ b/fs/btrfs/volumes.c
> > > > > @@ -6242,7 +6242,7 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
> > > > >  			"invalid chunk length %llu", length);
> > > > >  		return -EIO;
> > > > >  	}
> > > > > -	if (!is_power_of_2(stripe_len)) {
> > > > > +	if (!is_power_of_2(stripe_len) || stripe_len != BTRFS_STRIPE_LEN) {
> 
> We don't need the first 'is_power_of_2' check.
> 
> And I think we may need to have another helper, such as btrfs_check_chunk_valid(),
> to cover all these (both current and future) validation checks.  What do you think?

Sounds good.

  parent reply	other threads:[~2016-04-29 16:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-27  0:53 [PATCH] Btrfs: fix divide error upon chunk's stripe_len Liu Bo
2016-04-27 16:39 ` David Sterba
2016-04-27 17:23   ` Liu Bo
2016-04-27 17:33     ` David Sterba
2016-04-28 17:48       ` Liu Bo
2016-04-29  3:20         ` Qu Wenruo
2016-04-29 17:09           ` Liu Bo
2016-04-29 16:22         ` David Sterba [this message]
     [not found] ` <877ffgp7g2.fsf@gmail.com>
2016-04-30  4:09   ` Liu Bo
2016-05-02  8:16   ` David Sterba

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=20160429162226.GB29353@suse.cz \
    --to=dsterba@suse.cz \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.