From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH v2 2/2] btrfs: Add extra check for sub_stripes to avoid hostile 0 division attack.
Date: Fri, 24 Apr 2015 09:12:41 +0800 [thread overview]
Message-ID: <1429837961-2255-2-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1429837961-2255-1-git-send-email-quwenruo@cn.fujitsu.com>
Although only RAID10 use sub_stripes, a hostile attack can modify chunk
tree and just add RAID10 bit to a single chunk.
Then btrfs_map_block will trigger a 0 division in kernel and destroy
everything.
Just add extra check when reading chunk from disk.
Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
v2:
Return -EIO, and add kernel message output.
---
fs/btrfs/volumes.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 8222f6f..fdcecf7 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -6061,6 +6061,17 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
map->stripe_len = btrfs_chunk_stripe_len(leaf, chunk);
map->type = btrfs_chunk_type(leaf, chunk);
map->sub_stripes = btrfs_chunk_sub_stripes(leaf, chunk);
+
+ /* Add extra check to avoid hostile 0 division attack */
+ if (map->type & BTRFS_BLOCK_GROUP_RAID10 &&
+ map->sub_stripes == 0) {
+ btrfs_warn(root->fs_info,
+ "RAID10 chunk found but with no sub stripe for bytenr: %llu\n",
+ logical);
+ free_extent_map(em);
+ return -EIO;
+ }
+
for (i = 0; i < num_stripes; i++) {
map->stripes[i].physical =
btrfs_stripe_offset_nr(leaf, chunk, i);
--
2.3.5
next prev parent reply other threads:[~2015-04-24 1:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-24 1:12 [PATCH v2 1/2] btrfs: Fix superblock csum type check Qu Wenruo
2015-04-24 1:12 ` Qu Wenruo [this message]
2015-04-24 15:05 ` [PATCH v2 2/2] btrfs: Add extra check for sub_stripes to avoid hostile 0 division attack David Sterba
2015-04-24 15:05 ` [PATCH v2 1/2] btrfs: Fix superblock csum type check David Sterba
2015-04-27 0:25 ` Qu Wenruo
2015-04-27 10:59 ` David Sterba
2015-04-28 0:57 ` 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=1429837961-2255-2-git-send-email-quwenruo@cn.fujitsu.com \
--to=quwenruo@cn.fujitsu.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).