From patchwork Thu Apr 23 03:00:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 6259571 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B372ABF4A6 for ; Thu, 23 Apr 2015 03:03:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E95A82043C for ; Thu, 23 Apr 2015 03:03:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E2F2920430 for ; Thu, 23 Apr 2015 03:03:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758635AbbDWDDG (ORCPT ); Wed, 22 Apr 2015 23:03:06 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:29057 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1757899AbbDWDDE (ORCPT ); Wed, 22 Apr 2015 23:03:04 -0400 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="91101663" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Apr 2015 10:58:55 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t3N31Wa0003480; Thu, 23 Apr 2015 11:01:32 +0800 Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 23 Apr 2015 11:02:45 +0800 From: Qu Wenruo To: CC: Subject: [PATCH] btrfs: Add extra check for sub_stripes to avoid hostile 0 division attack. Date: Thu, 23 Apr 2015 11:00:45 +0800 Message-ID: <1429758045-27027-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.3.5 MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Qu Wenruo --- fs/btrfs/volumes.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 8222f6f..a764726 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6061,6 +6061,14 @@ 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) { + free_extent_map(em); + return -EINVAL; + } + for (i = 0; i < num_stripes; i++) { map->stripes[i].physical = btrfs_stripe_offset_nr(leaf, chunk, i);