aboutsummaryrefslogtreecommitdiffstats
path: root/fs/hfs/btree.c
diff options
context:
space:
mode:
authorEric Sandeen <sandeen@redhat.com>2008-01-08 18:33:20 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-01-08 19:10:36 -0500
commitcf0594625083111ae522496dc1c256f7476939c2 (patch)
treef83641f74c89fa4fb17adb2f216b074f2352639c /fs/hfs/btree.c
parent467bc461d2845f6a04b124bca1ae6ecc554e1ee5 (diff)
hfs: handle more on-disk corruptions without oopsing
hfs seems prone to bad things when it encounters on disk corruption. Many values are read from disk, and used as lengths to memcpy, as an example. This patch fixes up several of these problematic cases. o sanity check the on-disk maximum key lengths on mount (these are set to a defined value at mkfs time and shouldn't differ) o check on-disk node keylens against the maximum key length for each tree o fix hfs_btree_open so that going out via free_tree: doesn't wind up in hfs_releasepage, which wants to follow the very pointer we were trying to set up: HFS_SB(sb)->cat_tree = hfs_btree_open() ... failure gets to hfs_releasepage and tries to follow HFS_SB(sb)->cat_tree Tested with the fsfuzzer; it survives more than it used to. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Cc: Roman Zippel <zippel@linux-m68k.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/hfs/btree.c')
-rw-r--r--fs/hfs/btree.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/fs/hfs/btree.c b/fs/hfs/btree.c
index 8a3a650abc87..31284c77bba8 100644
--- a/fs/hfs/btree.c
+++ b/fs/hfs/btree.c
@@ -81,6 +81,17 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke
81 goto fail_page; 81 goto fail_page;
82 if (!tree->node_count) 82 if (!tree->node_count)
83 goto fail_page; 83 goto fail_page;
84 if ((id == HFS_EXT_CNID) && (tree->max_key_len != HFS_MAX_EXT_KEYLEN)) {
85 printk(KERN_ERR "hfs: invalid extent max_key_len %d\n",
86 tree->max_key_len);
87 goto fail_page;
88 }
89 if ((id == HFS_CAT_CNID) && (tree->max_key_len != HFS_MAX_CAT_KEYLEN)) {
90 printk(KERN_ERR "hfs: invalid catalog max_key_len %d\n",
91 tree->max_key_len);
92 goto fail_page;
93 }
94
84 tree->node_size_shift = ffs(size) - 1; 95 tree->node_size_shift = ffs(size) - 1;
85 tree->pages_per_bnode = (tree->node_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 96 tree->pages_per_bnode = (tree->node_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
86 97
@@ -89,9 +100,9 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke
89 return tree; 100 return tree;
90 101
91 fail_page: 102 fail_page:
92 tree->inode->i_mapping->a_ops = &hfs_aops;
93 page_cache_release(page); 103 page_cache_release(page);
94 free_tree: 104 free_tree:
105 tree->inode->i_mapping->a_ops = &hfs_aops;
95 iput(tree->inode); 106 iput(tree->inode);
96 kfree(tree); 107 kfree(tree);
97 return NULL; 108 return NULL;