From patchwork Tue Apr 23 15:31:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 2478201 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 150EC3FD1A for ; Tue, 23 Apr 2013 15:31:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756857Ab3DWPbn (ORCPT ); Tue, 23 Apr 2013 11:31:43 -0400 Received: from dkim2.fusionio.com ([66.114.96.54]:51773 "EHLO dkim2.fusionio.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756565Ab3DWPbm (ORCPT ); Tue, 23 Apr 2013 11:31:42 -0400 Received: from mx2.fusionio.com (unknown [10.101.1.160]) by dkim2.fusionio.com (Postfix) with ESMTP id 4AC8D9A0425 for ; Tue, 23 Apr 2013 09:31:42 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fusionio.com; s=default; t=1366731102; bh=DSkcyc3+ehJWhRHQk+TGe2LcPBvpMGJODR6aPg/Au3k=; h=From:To:Subject:Date; b=akHbl3TxKF+Yg5Z/5mD/wRADMbPznPbnKhsUsYy74Kp4EMMroUXe17B3DbJl5tczY PV0x7XxWDHFsvMDX6feIJCguujfh05txp/GdFK6IxLr0kxtEDXX1zPsUlcarRYpjGt AyajdvSdR9YaBpYdLSdSUUbKaWQLXkFap9D76zj4= X-ASG-Debug-ID: 1366731101-0421b537aba1740001-6jHSXT Received: from mail1.int.fusionio.com (mail1.int.fusionio.com [10.101.1.21]) by mx2.fusionio.com with ESMTP id kAU8Co7fAdw7NOgg (version=TLSv1 cipher=AES128-SHA bits=128 verify=NO) for ; Tue, 23 Apr 2013 09:31:41 -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; Tue, 23 Apr 2013 09:31:41 -0600 From: Josef Bacik To: Subject: [PATCH] Btrfs: add tree block level sanity check Date: Tue, 23 Apr 2013 11:31:39 -0400 X-ASG-Orig-Subj: [PATCH] Btrfs: add tree block level sanity check Message-ID: <1366731099-1940-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: 1366731101 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.128943 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 With a users corrupted fs I was getting weird behavior and panics and it turns out it was because one of his tree blocks had a bogus header level. So add this to the sanity checks in the endio handler for tree blocks. Thanks, Signed-off-by: Josef Bacik Reviewed-by: David Sterba --- fs/btrfs/disk-io.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index f4628c7..fb0e5c2 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -651,6 +651,12 @@ static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end, goto err; } found_level = btrfs_header_level(eb); + if (found_level >= BTRFS_MAX_LEVEL) { + btrfs_info(root->fs_info, "bad tree block level %d\n", + (int)btrfs_header_level(eb)); + ret = -EIO; + goto err; + } btrfs_set_buffer_lockdep_class(btrfs_header_owner(eb), eb, found_level);