From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: Su Yue <suy.fnst@cn.fujitsu.com>, Qu Wenruo <wqu@suse.com>,
linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 3/3] btrfs-progs: print-tree: Enhance btrfs_print_tree() check to avoid out-of-boundary memory access
Date: Wed, 9 May 2018 13:57:34 +0200 [thread overview]
Message-ID: <20180509115734.GU6649@twin.jikos.cz> (raw)
In-Reply-To: <3d5df980-bd16-e28c-f342-922db55f63f2@gmx.com>
On Mon, Apr 30, 2018 at 11:51:19AM +0800, Qu Wenruo wrote:
> >> btrfs_print_leaf(eb);
> >> return;
> >> }
> >> + /* We are crossing eb boundary, this node must be corrupted */
> >> + if (nr > BTRFS_NODEPTRS_PER_EXTENT_BUFFER(eb))
> >> + warning(
> >> + "node nr_items corrupted, has %u limit %u, continue print
> >> anyway",
> >> + nr, BTRFS_NODEPTRS_PER_EXTENT_BUFFER(eb));
> >> printf("node %llu level %d items %d free %u generation %llu
> >> owner ",
> >> (unsigned long long)eb->start,
> >> btrfs_header_level(eb), nr,
> >> @@ -1386,7 +1391,11 @@ void btrfs_print_tree(struct extent_buffer *eb,
> >> int follow)
> >> print_uuids(eb);
> >> fflush(stdout);
> >>
> >> - u64 blocknr = btrfs_node_blockptr(eb, i);
> >> + u64 blocknr;
> >> +
> >> + if (i > BTRFS_NODEPTRS_PER_EXTENT_BUFFER(eb))
> >> + break;
> >
> > Should it be i >= BTRFS_NODEPTRS_PER_EXTENT_BUFFER(eb)?
>
> BTRFS_NODEPTRS_PER_EXTENT_BUFFER() provides the maximum valid number.
> So it 's >=.
>
> >
> > Here BTRFS_NODEPTRS_PER_EXTENT_BUFFER() is called during iterations.
> > The judement can be calculated in advance like:
> >
> > ptr_num = BTRFS_NODEPTRS_PER_EXTENT_BUFFER(eb);
> > ...
> > for (i = 0; i < nr && i < ptr_num ; i++) {
>
> Indeed looks better.
Please resend this patch with the suggested updates, thanks.
next prev parent reply other threads:[~2018-05-09 12:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-30 3:15 [PATCH 1/3] btrfs-progs: Remove fs_info parameter from btrfs_leaf_free_space() Qu Wenruo
2018-04-30 3:15 ` [PATCH 2/3] btrfs-progs: Allow tree to be printed without an fs_info Qu Wenruo
2018-04-30 3:33 ` Su Yue
2018-04-30 3:15 ` [PATCH 3/3] btrfs-progs: print-tree: Enhance btrfs_print_tree() check to avoid out-of-boundary memory access Qu Wenruo
2018-04-30 3:49 ` Su Yue
2018-04-30 3:51 ` Qu Wenruo
2018-05-09 11:57 ` David Sterba [this message]
2018-05-10 1:50 ` Qu Wenruo
2018-05-31 11:54 ` David Sterba
2018-04-30 3:27 ` [PATCH 1/3] btrfs-progs: Remove fs_info parameter from btrfs_leaf_free_space() Su Yue
2018-05-09 11:58 ` 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=20180509115734.GU6649@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=quwenruo.btrfs@gmx.com \
--cc=suy.fnst@cn.fujitsu.com \
--cc=wqu@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox