All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: YueHaibing <yuehaibing@huawei.com>
Cc: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH -next] btrfs: Fix type conversion in btrfs_read_root_item
Date: Wed, 20 Feb 2019 06:10:09 +0000	[thread overview]
Message-ID: <20190220061009.GN17104@kadam> (raw)
In-Reply-To: <20190220055621.GM17104@kadam>

On Wed, Feb 20, 2019 at 08:58:43AM +0300, Dan Carpenter wrote:
> On Wed, Feb 20, 2019 at 03:08:40AM +0000, YueHaibing wrote:
> > btrfs_item_size_nr return value is u32, convert it to int may result
> > in truncation.Also read_extent_buffer expect a unsigned param, so
> > min_t should use type u32 to compare.
> > 
> > Fixes: 8ea05e3a4262 ("Btrfs: introduce subvol uuids and times")
> > Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> > ---
> >  fs/btrfs/root-tree.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
> > index 02d1a57af78b..893d12fbfda0 100644
> > --- a/fs/btrfs/root-tree.c
> > +++ b/fs/btrfs/root-tree.c
> > @@ -21,12 +21,12 @@ static void btrfs_read_root_item(struct extent_buffer *eb, int slot,
> >  				struct btrfs_root_item *item)
> >  {
> >  	uuid_le uuid;
> > -	int len;
> > +	u32 len;
> >  	int need_reset = 0;
> >  
> >  	len = btrfs_item_size_nr(eb, slot);
> >  	read_extent_buffer(eb, item, btrfs_item_ptr_offset(eb, slot),
> > -			min_t(int, len, (int)sizeof(*item)));
>                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Yeah, min_t() should normally cast to unsigned and the extra cast is
> silly.
> 

Btw, I shouldn't have had to dig through the patch to find the *real*
reason you wrote it.  A better description would have said:

    There is a messy cast here:

	min_t(int, len, (int)sizeof(*item)));

    min_t() should normally cast to unsigned.  It's not possible for
    "len" to be negative, but if it were then then we definitely
    wouldn't want to pass negatives to read_extent_buffer().  Also there
    is an extra cast.

    This patch shouldn't affect runtime, it's just a clean up.

regards,
dan carpenter

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: YueHaibing <yuehaibing@huawei.com>
Cc: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH -next] btrfs: Fix type conversion in btrfs_read_root_item
Date: Wed, 20 Feb 2019 09:10:09 +0300	[thread overview]
Message-ID: <20190220061009.GN17104@kadam> (raw)
In-Reply-To: <20190220055621.GM17104@kadam>

On Wed, Feb 20, 2019 at 08:58:43AM +0300, Dan Carpenter wrote:
> On Wed, Feb 20, 2019 at 03:08:40AM +0000, YueHaibing wrote:
> > btrfs_item_size_nr return value is u32, convert it to int may result
> > in truncation.Also read_extent_buffer expect a unsigned param, so
> > min_t should use type u32 to compare.
> > 
> > Fixes: 8ea05e3a4262 ("Btrfs: introduce subvol uuids and times")
> > Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> > ---
> >  fs/btrfs/root-tree.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
> > index 02d1a57af78b..893d12fbfda0 100644
> > --- a/fs/btrfs/root-tree.c
> > +++ b/fs/btrfs/root-tree.c
> > @@ -21,12 +21,12 @@ static void btrfs_read_root_item(struct extent_buffer *eb, int slot,
> >  				struct btrfs_root_item *item)
> >  {
> >  	uuid_le uuid;
> > -	int len;
> > +	u32 len;
> >  	int need_reset = 0;
> >  
> >  	len = btrfs_item_size_nr(eb, slot);
> >  	read_extent_buffer(eb, item, btrfs_item_ptr_offset(eb, slot),
> > -			min_t(int, len, (int)sizeof(*item)));
>                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Yeah, min_t() should normally cast to unsigned and the extra cast is
> silly.
> 

Btw, I shouldn't have had to dig through the patch to find the *real*
reason you wrote it.  A better description would have said:

    There is a messy cast here:

	min_t(int, len, (int)sizeof(*item)));

    min_t() should normally cast to unsigned.  It's not possible for
    "len" to be negative, but if it were then then we definitely
    wouldn't want to pass negatives to read_extent_buffer().  Also there
    is an extra cast.

    This patch shouldn't affect runtime, it's just a clean up.

regards,
dan carpenter


  reply	other threads:[~2019-02-20  6:10 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-20  2:55 [PATCH -next] btrfs: Fix type conversion in btrfs_read_root_item YueHaibing
2019-02-20  3:08 ` YueHaibing
2019-02-20  3:38 ` Qu Wenruo
2019-02-20  3:38   ` Qu Wenruo
2019-02-20  5:58 ` Dan Carpenter
2019-02-20  5:58   ` Dan Carpenter
2019-02-20  6:10   ` Dan Carpenter [this message]
2019-02-20  6:10     ` Dan Carpenter
2019-02-20  9:10     ` YueHaibing
2019-02-20  9:10       ` YueHaibing
2019-02-20 12:32 ` [PATCH v2 -next] btrfs: Remove unnecessary casts " YueHaibing
2019-02-20 12:32   ` YueHaibing
2019-02-20 12:33   ` Dan Carpenter
2019-02-20 12:33     ` Dan Carpenter
2019-02-20 12:36   ` Qu Wenruo
2019-02-20 12:36     ` Qu Wenruo
2019-02-22 14:39   ` David Sterba
2019-02-22 14:39     ` 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=20190220061009.GN17104@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yuehaibing@huawei.com \
    /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.