From: Liu Bo <bo.li.liu@oracle.com>
To: dsterba@suse.cz
Cc: linux-btrfs@vger.kernel.org, Josef Bacik <jbacik@fb.com>,
Chris Mason <clm@fb.com>
Subject: Re: [PATCH] Btrfs: memset to avoid stale content in btree node block
Date: Tue, 20 Sep 2016 10:57:41 -0700 [thread overview]
Message-ID: <20160920175741.GA3319@localhost.localdomain> (raw)
In-Reply-To: <20160920131636.GY16983@twin.jikos.cz>
On Tue, Sep 20, 2016 at 03:16:36PM +0200, David Sterba wrote:
> On Wed, Sep 14, 2016 at 05:22:57PM -0700, Liu Bo wrote:
> > During updating btree, we could push items between sibling
> > nodes/leaves, for leaves data sections starts reversely from
> > the end of the block while for nodes we only have key pairs
> > which are stored one by one from the start of the block.
> >
> > So we could do try to push key pairs from one node to the next
> > node right in the tree, and after that, we update the node's
> > nritems to reflect the correct end while leaving the stale
> > content in the node. One may intentionally corrupt the fs
> > image and access the stale content by bumping the nritems and
> > causes various crashes.
> >
> > This takes the in-memory @nritems as the correct one and
> > gets to memset the unused part of a btree node.
> >
> > Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
>
> Reviewed-by: David Sterba <dsterba@suse.com>
>
> > ---
> > fs/btrfs/extent_io.c | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> > index c2325c3..56c9dee 100644
> > --- a/fs/btrfs/extent_io.c
> > +++ b/fs/btrfs/extent_io.c
> > @@ -3732,6 +3732,17 @@ static noinline_for_stack int write_one_eb(struct extent_buffer *eb,
> > if (btrfs_header_owner(eb) == BTRFS_TREE_LOG_OBJECTID)
> > bio_flags = EXTENT_BIO_TREE_LOG;
> >
> > + /* set btree node beyond nritems with 0 to avoid stale content */
> > + if (btrfs_header_level(eb) > 0) {
>
> We can do the same for leaves.
In theory, the problem also applies for leaves, but I haven't got a
reproducer for leaf case.
So I'll update a v2 with leaf memset, please review that part more
carefully :)
Thanks,
-liubo
next prev parent reply other threads:[~2016-09-20 17:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-15 0:22 [PATCH] Btrfs: memset to avoid stale content in btree node block Liu Bo
2016-09-20 13:16 ` David Sterba
2016-09-20 17:57 ` Liu Bo [this message]
2016-09-21 8:04 ` David Sterba
2016-09-21 13:09 ` Chris Mason
2016-09-22 1:20 ` 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=20160920175741.GA3319@localhost.localdomain \
--to=bo.li.liu@oracle.com \
--cc=clm@fb.com \
--cc=dsterba@suse.cz \
--cc=jbacik@fb.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).