linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 1/3] btrfs-progs: check/lowmem: Add checks for compressed extent without csum
Date: Mon, 14 May 2018 15:03:08 +0800	[thread overview]
Message-ID: <20180514070310.27197-2-wqu@suse.com> (raw)
In-Reply-To: <20180514070310.27197-1-wqu@suse.com>

There is one report of compressed extent happens in btrfs, but has no
csum and then leads to possible decompress error screwing up kernel
memory.

Although it's a kernel bug, and won't cause problem until compressed
data get corrupted, let's catch such problem in advance.

This patch will catch any unexpected compressed extent with:

1) 0 or less than expected csum

2) nodatasum flag set in the inode item

This is for lowmem mode.

Reported-by: James Harvey <jamespharvey20@gmail.com>
Issue: #134
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/mode-lowmem.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index dac3201b7d99..8e6d5e8de12a 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -1543,6 +1543,24 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_key *fkey,
 			      csum_found);
 		}
 	}
+	/*
+	 * Extra check for compressed extents.
+	 * Btrfs doesn't allow NODATASUM and compressed extent co-exist, thus
+	 * all compressed extent should have csum.
+	 */
+	if (compressed && csum_found < search_len) {
+		error(
+"root %llu EXTENT_DATA[%llu %llu] compressed extent must have csum, but only %llu bytes has csum, expect %llu",
+		      root->objectid, fkey->objectid, fkey->offset, csum_found,
+		      search_len);
+		err |= CSUM_ITEM_MISSING;
+	}
+	if (compressed && nodatasum) {
+		error(
+"root %llu EXTENT_DATA[%llu %llu] is compressed, but inode flag doesn't allow it",
+		      root->objectid, fkey->objectid, fkey->offset);
+		err |= FILE_EXTENT_ERROR;
+	}
 
 	/* Check EXTENT_DATA hole */
 	if (!no_holes && *end != fkey->offset) {
-- 
2.17.0


  reply	other threads:[~2018-05-14  7:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-14  7:03 [PATCH 0/3] btrfs-progs: Detect compressed extent without csum Qu Wenruo
2018-05-14  7:03 ` Qu Wenruo [this message]
2018-05-14  7:24   ` [PATCH 1/3] btrfs-progs: check/lowmem: Add checks for " Su Yue
2018-05-14  7:03 ` [PATCH 2/3] btrfs-progs: check/original: " Qu Wenruo
2018-05-14  7:24   ` Su Yue
2018-05-14  7:03 ` [PATCH 3/3] btrfs-progs: fsck-tests: Add test case for detecting " Qu Wenruo
  -- strict thread matches above, loose matches on Subject: below --
2018-05-14  6:54 [PATCH 0/3] btrfs-progs: Detect " Qu Wenruo
2018-05-14  6:54 ` [PATCH 1/3] btrfs-progs: check/lowmem: Add checks for " Qu Wenruo

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=20180514070310.27197-2-wqu@suse.com \
    --to=wqu@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).