diff options
author | Eric Sandeen <sandeen@redhat.com> | 2010-10-14 09:53:48 -0400 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2010-10-14 09:53:48 -0400 |
commit | 9250f925972d03ccc0c0a4dd4e9b794d2ef6d52b (patch) | |
tree | f8a93ca47166f79cfa90e3dbc3c4f403686e2fbb /fs/hfsplus/brec.c | |
parent | b6b41424f0ec28e9a167fa29b003327860b4b71b (diff) |
hfsplus: 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.
[hch: ported of commit cf0594625083111ae522496dc1c256f7476939c2 from hfs]
[hch: added the fixes from 5581d018ed3493d226e7a4d645d9c8a5af6c36b]
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Christoph Hellwig <hch@tuxera.com>
Diffstat (limited to 'fs/hfsplus/brec.c')
-rw-r--r-- | fs/hfsplus/brec.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/fs/hfsplus/brec.c b/fs/hfsplus/brec.c index fa903641992f..790cd6a8605d 100644 --- a/fs/hfsplus/brec.c +++ b/fs/hfsplus/brec.c | |||
@@ -42,10 +42,21 @@ u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec) | |||
42 | recoff = hfs_bnode_read_u16(node, node->tree->node_size - (rec + 1) * 2); | 42 | recoff = hfs_bnode_read_u16(node, node->tree->node_size - (rec + 1) * 2); |
43 | if (!recoff) | 43 | if (!recoff) |
44 | return 0; | 44 | return 0; |
45 | if (node->tree->attributes & HFS_TREE_BIGKEYS) | 45 | if (node->tree->attributes & HFS_TREE_BIGKEYS) { |
46 | retval = hfs_bnode_read_u16(node, recoff) + 2; | 46 | retval = hfs_bnode_read_u16(node, recoff) + 2; |
47 | else | 47 | if (retval > node->tree->max_key_len + 2) { |
48 | printk(KERN_ERR "hfs: keylen %d too large\n", | ||
49 | retval); | ||
50 | retval = 0; | ||
51 | } | ||
52 | } else { | ||
48 | retval = (hfs_bnode_read_u8(node, recoff) | 1) + 1; | 53 | retval = (hfs_bnode_read_u8(node, recoff) | 1) + 1; |
54 | if (retval > node->tree->max_key_len + 1) { | ||
55 | printk(KERN_ERR "hfs: keylen %d too large\n", | ||
56 | retval); | ||
57 | retval = 0; | ||
58 | } | ||
59 | } | ||
49 | } | 60 | } |
50 | return retval; | 61 | return retval; |
51 | } | 62 | } |