linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 1/2] btrfs-progs: Fix DIR_ITEM checking in lowmem
Date: Fri, 23 Mar 2018 16:48:13 +0200	[thread overview]
Message-ID: <1521816494-22947-1-git-send-email-nborisov@suse.com> (raw)

When checking the validity of a DIR_ITEM item the index variable
is explicitly set to -1 so that the index check in find_inode_ref()
is ignored. This is necessary due to possible name collisions in DIR_ITEMS
(i.e multiple files with the same crc32c for their names, resulting in the
identical key->offset). Currently the code is broken due to index being set to
-1 at the beginning of check_dir_item and subsequently reset to the index found
in find_inode_ref. On subsequent iterations of the while loop in check_dir_items
we are going to erroneously perform index checking, since index is not -1 but 
whatever the index value of the last handled INODE_REF ITEM.
Without this patch check in lowmem mode produces the following false warnings 
positivess:

ERROR: root 5 INODE REF[1991456, 256] name 5ab4e28b~~~~~~~~QBXUT2GBJDRT5CB6ZWAJVDHK filetype 1 missing

But the items for this name are in fact correct: 

------------------SNIP------------------------
item 13 key (256 DIR_ITEM 4227063046) itemoff 2945 itemsize 140
	location key (220890 INODE_ITEM 0) type FILE
	transid 2278 data_len 0 name_len 40
	name: 5ab4e1bb~~~~~~~~65KNTAWVJ5VD4SV2R3BKFCXL
	location key (1991456 INODE_ITEM 0) type FILE
	transid 2285 data_len 0 name_len 40
	name: 5ab4e28b~~~~~~~~QBXUT2GBJDRT5CB6ZWAJVDHK

item 21 key (1991456 INODE_REF 256) itemoff 2104 itemsize 50
	index 1934146 namelen 40 name: 5ab4e28b~~~~~~~~QBXUT2GBJDRT5CB6ZWAJVDHK
-------------------SNIP-------------------------

Fix this by moving the code setting index at the beginning of the while
loop. This ensure that for each item in DIR_ITEM we have index set
correctly.

Fixes: 564901eac7a4 ("btrfs-progs: check: introduce print_dir_item_err()")
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 check/mode-lowmem.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 2982e92..8bd50d1 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -1217,14 +1217,6 @@ static int check_dir_item(struct btrfs_root *root, struct btrfs_key *di_key,
 	int tmp_err;
 	int need_research = 0;
 
-	/*
-	 * For DIR_ITEM set index to (u64)-1, so that find_inode_ref
-	 * ignore index check.
-	 */
-	if (di_key->type == BTRFS_DIR_INDEX_KEY)
-		index = di_key->offset;
-	else
-		index = (u64)-1;
 begin:
 	err = 0;
 	cur = 0;
@@ -1254,6 +1246,15 @@ begin:
 	memset(namebuf, 0, sizeof(namebuf) / sizeof(*namebuf));
 
 	while (cur < total) {
+		/*
+		 * For DIR_ITEM set index to (u64)-1, so that find_inode_ref
+		 * ignore index check.
+		 */
+		if (di_key->type == BTRFS_DIR_INDEX_KEY)
+			index = di_key->offset;
+		else
+			index = (u64)-1;
+
 		data_len = btrfs_dir_data_len(node, di);
 		tmp_err = 0;
 		if (data_len)
-- 
2.7.4


             reply	other threads:[~2018-03-23 14:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-23 14:48 Nikolay Borisov [this message]
2018-03-23 14:48 ` [PATCH 2/2] btrfs-progs: Add test for collision DIR_ITEM handling Nikolay Borisov
2018-03-25 11:44   ` Qu Wenruo
2018-03-26 13:24     ` Nikolay Borisov
2018-03-26 13:31       ` Qu Wenruo
2018-03-26 13:37       ` David Sterba
2018-03-25 11:39 ` [PATCH 1/2] btrfs-progs: Fix DIR_ITEM checking in lowmem Qu Wenruo
2018-03-26  1:17 ` Su Yue
2018-03-26 13:59 ` [PATCH v2] btrfs-progs: Add test for collision DIR_ITEM handling Nikolay Borisov
2018-03-26 14:19   ` Qu Wenruo
2018-05-02  5:50 ` [PATCH 1/2] btrfs-progs: Fix DIR_ITEM checking in lowmem Nikolay Borisov
2018-05-09 11:22   ` 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=1521816494-22947-1-git-send-email-nborisov@suse.com \
    --to=nborisov@suse.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).