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 cf05946250
from hfs]
[hch: added the fixes from 5581d018ed3493d226e7a4d645d9c8a5af6c36b]
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Christoph Hellwig <hch@tuxera.com>
Cette révision appartient à :

révisé par
Christoph Hellwig

Parent
b6b41424f0
révision
9250f92597
@@ -52,6 +52,10 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
|
||||
rec = (e + b) / 2;
|
||||
len = hfs_brec_lenoff(bnode, rec, &off);
|
||||
keylen = hfs_brec_keylen(bnode, rec);
|
||||
if (keylen == 0) {
|
||||
res = -EINVAL;
|
||||
goto fail;
|
||||
}
|
||||
hfs_bnode_read(bnode, fd->key, off, keylen);
|
||||
cmpval = bnode->tree->keycmp(fd->key, fd->search_key);
|
||||
if (!cmpval) {
|
||||
@@ -67,6 +71,10 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
|
||||
if (rec != e && e >= 0) {
|
||||
len = hfs_brec_lenoff(bnode, e, &off);
|
||||
keylen = hfs_brec_keylen(bnode, e);
|
||||
if (keylen == 0) {
|
||||
res = -EINVAL;
|
||||
goto fail;
|
||||
}
|
||||
hfs_bnode_read(bnode, fd->key, off, keylen);
|
||||
}
|
||||
done:
|
||||
@@ -75,6 +83,7 @@ done:
|
||||
fd->keylength = keylen;
|
||||
fd->entryoffset = off + keylen;
|
||||
fd->entrylength = len - keylen;
|
||||
fail:
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -198,6 +207,10 @@ int hfs_brec_goto(struct hfs_find_data *fd, int cnt)
|
||||
|
||||
len = hfs_brec_lenoff(bnode, fd->record, &off);
|
||||
keylen = hfs_brec_keylen(bnode, fd->record);
|
||||
if (keylen == 0) {
|
||||
res = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
fd->keyoffset = off;
|
||||
fd->keylength = keylen;
|
||||
fd->entryoffset = off + keylen;
|
||||
|
Référencer dans un nouveau ticket
Bloquer un utilisateur