linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.cz
Subject: [PATCH v2 2/4] btrfs: Check if item pointer overlap with item itself
Date: Wed, 23 Aug 2017 16:57:57 +0900	[thread overview]
Message-ID: <20170823075759.13982-3-quwenruo.btrfs@gmx.com> (raw)
In-Reply-To: <20170823075759.13982-1-quwenruo.btrfs@gmx.com>

Function check_leaf() checks if any item pointer points outside of the
leaf, but it doesn't check if the pointer overlap with the item itself.

Normally only the last item may be the victim, but adding such check is
never a bad idea anyway.

Signed-off-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
---
 fs/btrfs/disk-io.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index ebc719b790ee..e034d08bd036 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -643,6 +643,13 @@ static noinline int check_leaf(struct btrfs_root *root,
 			return -EUCLEAN;
 		}
 
+		/* Also check if the item pointer overlaps with btrfs item. */
+		if (btrfs_item_nr_offset(slot) + sizeof(struct btrfs_item) >
+		    btrfs_item_ptr_offset(leaf, slot)) {
+			CORRUPT("slot overlap with its data", leaf, root, slot);
+			return -EUCLEAN;
+		}
+
 		prev_key.objectid = key.objectid;
 		prev_key.type = key.type;
 		prev_key.offset = key.offset;
-- 
2.14.1


  parent reply	other threads:[~2017-08-23  7:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-23  7:57 [PATCH v2 0/3] Introduce comprehensive sanity check framework and Qu Wenruo
2017-08-23  7:57 ` [PATCH v2 1/4] btrfs: Refactor check_leaf function for later expansion Qu Wenruo
2017-08-23  7:57 ` Qu Wenruo [this message]
2017-08-23  7:57 ` [PATCH v2 3/4] btrfs: Add sanity check for EXTENT_DATA when reading out leaf Qu Wenruo
2017-09-25 15:45   ` David Sterba
2017-09-26  0:28     ` Qu Wenruo
2017-09-26  0:46       ` Qu Wenruo
2017-09-26 12:13         ` David Sterba
2017-09-26 12:49           ` Qu Wenruo
2017-09-26 14:42             ` David Sterba
2017-09-26 12:05       ` David Sterba
2017-09-26 12:42         ` Qu Wenruo
2017-08-23  7:57 ` [PATCH v2 4/4] btrfs: Add checker for EXTENT_CSUM Qu Wenruo
2017-08-23 15:19 ` [PATCH v2 0/3] Introduce comprehensive sanity check framework and Nikolay Borisov
2017-09-25 15:17 ` 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=20170823075759.13982-3-quwenruo.btrfs@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=dsterba@suse.cz \
    --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).