From: Nikolay Borisov <nborisov@suse.com>
To: Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/2] btrfs: lzo: Avoid decompressing obviously corrupted data
Date: Tue, 15 May 2018 11:05:35 +0300 [thread overview]
Message-ID: <d36602d1-c23b-0e3a-2eb8-0609ac2ec6ba@suse.com> (raw)
In-Reply-To: <20180515073622.18732-3-wqu@suse.com>
On 15.05.2018 10:36, Qu Wenruo wrote:
> Unlike zlib decompression, lzo decompression doesn't need any
> initialization, thus we can't detect early corruption from
> initialization.
>
> However for lzo compressed extent, its first 4bytes records the real
> unaligned compressed data size.
> We could use this as a clue, since any compressed extent should not
> exceed 128K, thus if we find such compressed data length, we are sure
> it's corrupted, then no need to continue decompression.
>
> Normally, such problem won't really bother anyone, as compression relies
> on dataCoW and data csum, which means normally such corruption should be
> detect by data csum before going into compression.
> However due to a bug in compression condition, it's possible to create
> compressed extent without csum.
>
> So we still need to do extra check for lzo just in case the compressed
> data is corrupted.
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> lease note that, even with the binary dump of corrupted extent provided
> by the original reporter, James Harvey, I can only reproduce the "decompress
> failed" error message, but not the serious memory corruption followed.
> So there must be something missing, maybe we need to double check both
> btrfs lzo caller and kernel lzo lib.
>
> But anyway, making btrfs lzo compression a little more robust is never a
> bad thing.
> ---
> fs/btrfs/compression.h | 1 +
> fs/btrfs/lzo.c | 4 ++++
> 2 files changed, 5 insertions(+)
>
> diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h
> index cc605f7b23fb..317703d9b073 100644
> --- a/fs/btrfs/compression.h
> +++ b/fs/btrfs/compression.h
> @@ -6,6 +6,7 @@
> #ifndef BTRFS_COMPRESSION_H
> #define BTRFS_COMPRESSION_H
>
> +#include <linux/sizes.h>
Stray include otherwise:
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
> /*
> * We want to make sure that amount of RAM required to uncompress an extent is
> * reasonable, so we limit the total size in ram of a compressed extent to
> diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
> index 0667ea07f766..7ae2c0925770 100644
> --- a/fs/btrfs/lzo.c
> +++ b/fs/btrfs/lzo.c
> @@ -271,6 +271,10 @@ static int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
>
> data_in = kmap(pages_in[0]);
> tot_len = read_compress_length(data_in);
> + if (tot_len > BTRFS_MAX_COMPRESSED) {
> + ret = -EIO;
> + goto done;
> + }
>
> tot_in = LZO_LEN;
> in_offset = LZO_LEN;
>
next prev parent reply other threads:[~2018-05-15 8:05 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-15 7:36 [PATCH 0/2] btrfs: Enhance btrfs handling compression and Qu Wenruo
2018-05-15 7:36 ` [PATCH 1/2] btrfs: inode: Don't compress if NODATASUM or NODATACOW set Qu Wenruo
2018-05-15 8:21 ` Nikolay Borisov
2018-05-15 8:30 ` Qu Wenruo
2018-05-15 8:35 ` Nikolay Borisov
2018-05-15 8:48 ` Qu Wenruo
2018-05-15 10:36 ` Nikolay Borisov
2018-05-15 10:48 ` Qu Wenruo
2019-06-25 8:24 ` Qu Wenruo
2019-06-27 14:58 ` David Sterba
2019-06-28 1:26 ` Qu Wenruo
2019-06-28 11:34 ` David Sterba
2019-06-28 12:09 ` Qu Wenruo
2019-06-28 16:38 ` David Sterba
2019-06-28 2:47 ` Anand Jain
2019-06-28 5:58 ` Qu Wenruo
2019-06-28 6:56 ` Anand Jain
2019-06-28 7:09 ` Qu Wenruo
2018-05-15 7:36 ` [PATCH 2/2] btrfs: lzo: Avoid decompressing obviously corrupted data Qu Wenruo
2018-05-15 8:05 ` Nikolay Borisov [this message]
2018-05-15 8:32 ` Qu Wenruo
2018-05-15 8:34 ` Nikolay Borisov
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=d36602d1-c23b-0e3a-2eb8-0609ac2ec6ba@suse.com \
--to=nborisov@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).