From patchwork Mon Apr 22 13:14:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 2471831 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 2E2F93FCA5 for ; Mon, 22 Apr 2013 13:14:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752734Ab3DVNOP (ORCPT ); Mon, 22 Apr 2013 09:14:15 -0400 Received: from dkim2.fusionio.com ([66.114.96.54]:39555 "EHLO dkim2.fusionio.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751919Ab3DVNOO (ORCPT ); Mon, 22 Apr 2013 09:14:14 -0400 Received: from mx2.fusionio.com (unknown [10.101.1.160]) by dkim2.fusionio.com (Postfix) with ESMTP id 46F279A0406 for ; Mon, 22 Apr 2013 07:14:14 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fusionio.com; s=default; t=1366636454; bh=W+n+ntfWusbo5g+edNItxdCKs2npWWKTH3A+5REL2Xs=; h=From:To:Subject:Date; b=ZkadXL+e8eCo5+tGw5xmGEexUj0NAIoWVAm+japfJotiRdQXSBM+061id5Pi586Iu rBVR12ICexMq9ZjqfEwk/pghGf304Y5zvHmVEZpUUv651T2Jd/vXFS0H25ywiz+TUH I2SqQKPpRgU9L/TYbxksO2cWMdRSN8OHDQNBcT98= X-ASG-Debug-ID: 1366636453-0421b569e1b05e0001-6jHSXT Received: from mail1.int.fusionio.com (mail1.int.fusionio.com [10.101.1.21]) by mx2.fusionio.com with ESMTP id vbXDZ9AJYxhErLn2 (version=TLSv1 cipher=AES128-SHA bits=128 verify=NO) for ; Mon, 22 Apr 2013 07:14:13 -0600 (MDT) X-Barracuda-Envelope-From: JBacik@fusionio.com Received: from localhost (76.182.72.146) by mail.fusionio.com (10.101.1.19) with Microsoft SMTP Server (TLS) id 8.3.83.0; Mon, 22 Apr 2013 07:14:12 -0600 From: Josef Bacik To: Subject: [PATCH] Btrfs: deal with bad mappings in btrfs_map_block Date: Mon, 22 Apr 2013 09:14:11 -0400 X-ASG-Orig-Subj: [PATCH] Btrfs: deal with bad mappings in btrfs_map_block Message-ID: <1366636451-2151-1-git-send-email-jbacik@fusionio.com> X-Mailer: git-send-email 1.7.7.6 MIME-Version: 1.0 X-Barracuda-Connect: mail1.int.fusionio.com[10.101.1.21] X-Barracuda-Start-Time: 1366636453 X-Barracuda-Encrypted: AES128-SHA X-Barracuda-URL: http://10.101.1.181:8000/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at fusionio.com X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.2.128839 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Martin Steigerwald reported a BUG_ON() in btrfs_map_block where we didn't find a chunk for a particular block we were trying to map. This happened because the block was bogus. We shouldn't be BUG_ON()'ing in this case, just print a message and return an error. This came from reada_add_block and it appears to deal with an error fine so we should be good there. Thanks, Reported-by: Martin Steigerwald Signed-off-by: Josef Bacik --- fs/btrfs/volumes.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 76ded9e..c8a315d 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4406,10 +4406,16 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, btrfs_crit(fs_info, "unable to find logical %llu len %llu", (unsigned long long)logical, (unsigned long long)*length); - BUG(); + return -EINVAL; + } + + if (em->start > logical || em->start + em->len < logical) { + btrfs_crit(fs_info, "found a bad mapping, wanted %Lu, " + "found %Lu-%Lu\n", logical, em->start, + em->start + em->len); + return -EINVAL; } - BUG_ON(em->start > logical || em->start + em->len < logical); map = (struct map_lookup *)em->bdev; offset = logical - em->start;