From: Christoph Hellwig Subject: hfsplus: fix oops on mount with corrupted btree extent records Date: Tue, 12 Oct 2010 15:56:49 +0200 Message-ID: <20101012135649.GB26867@lst.de> References: <20101012135634.GA26867@lst.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii To: linux-fsdevel@vger.kernel.org Return-path: Received: from verein.lst.de ([213.95.11.210]:51588 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932477Ab0JLN4u (ORCPT ); Tue, 12 Oct 2010 09:56:50 -0400 Received: from verein.lst.de (localhost [127.0.0.1]) by verein.lst.de (8.12.3/8.12.3/Debian-7.1) with ESMTP id o9CDun88026980 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Tue, 12 Oct 2010 15:56:49 +0200 Received: (from hch@localhost) by verein.lst.de (8.12.3/8.12.3/Debian-7.2) id o9CDunmN026979 for linux-fsdevel@vger.kernel.org; Tue, 12 Oct 2010 15:56:49 +0200 Content-Disposition: inline In-Reply-To: <20101012135634.GA26867@lst.de> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: From: Jeff Mahoney A particular fsfuzzer run caused an hfs file system to crash on mount. This is due to a corrupted MDB extent record causing a miscalculation of HFSPLUS_I(inode)->first_blocks for the extent tree. If the extent records are zereod out, then it won't trigger the first_blocks special case and instead falls through to the extent code, which we're in the middle of initializing. This patch catches the 0 size extent records, reports the corruption, and fails the mount. [hch: ported of commit 47f365eb575735c6b2edf5d08e0d16d26a9c23bd from hfs] Reported-by: Ramon de Carvalho Valle Signed-off-by: Jeff Mahoney Signed-off-by: Christoph Hellwig Index: linux-2.6/fs/hfsplus/btree.c =================================================================== --- linux-2.6.orig/fs/hfsplus/btree.c 2010-10-01 16:52:32.362010219 +0200 +++ linux-2.6/fs/hfsplus/btree.c 2010-10-01 16:53:49.328291422 +0200 @@ -39,10 +39,16 @@ struct hfs_btree *hfs_btree_open(struct goto free_tree; tree->inode = inode; + if (!HFSPLUS_I(tree->inode)->first_blocks) { + printk(KERN_ERR + "hfs: invalid btree extent records (0 size).\n"); + goto free_inode; + } + mapping = tree->inode->i_mapping; page = read_mapping_page(mapping, 0, NULL); if (IS_ERR(page)) - goto free_tree; + goto free_inode; /* Load the header */ head = (struct hfs_btree_header_rec *)(kmap(page) + sizeof(struct hfs_bnode_desc)); @@ -89,8 +95,9 @@ struct hfs_btree *hfs_btree_open(struct fail_page: tree->inode->i_mapping->a_ops = &hfsplus_aops; page_cache_release(page); - free_tree: + free_inode: iput(tree->inode); + free_tree: kfree(tree); return NULL; }