Commit 3d10a15d authored by Al Viro's avatar Al Viro Committed by Linus Torvalds

hfs_bnode_find() can fail, resulting in hfs_bnode_split() breakage

oops and fs corruption; the latter can happen even on valid fs in case of oom.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a978b30a
...@@ -229,7 +229,7 @@ int hfs_brec_remove(struct hfs_find_data *fd) ...@@ -229,7 +229,7 @@ int hfs_brec_remove(struct hfs_find_data *fd)
static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd) static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd)
{ {
struct hfs_btree *tree; struct hfs_btree *tree;
struct hfs_bnode *node, *new_node; struct hfs_bnode *node, *new_node, *next_node;
struct hfs_bnode_desc node_desc; struct hfs_bnode_desc node_desc;
int num_recs, new_rec_off, new_off, old_rec_off; int num_recs, new_rec_off, new_off, old_rec_off;
int data_start, data_end, size; int data_start, data_end, size;
...@@ -248,6 +248,17 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd) ...@@ -248,6 +248,17 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd)
new_node->type = node->type; new_node->type = node->type;
new_node->height = node->height; new_node->height = node->height;
if (node->next)
next_node = hfs_bnode_find(tree, node->next);
else
next_node = NULL;
if (IS_ERR(next_node)) {
hfs_bnode_put(node);
hfs_bnode_put(new_node);
return next_node;
}
size = tree->node_size / 2 - node->num_recs * 2 - 14; size = tree->node_size / 2 - node->num_recs * 2 - 14;
old_rec_off = tree->node_size - 4; old_rec_off = tree->node_size - 4;
num_recs = 1; num_recs = 1;
...@@ -261,6 +272,8 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd) ...@@ -261,6 +272,8 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd)
/* panic? */ /* panic? */
hfs_bnode_put(node); hfs_bnode_put(node);
hfs_bnode_put(new_node); hfs_bnode_put(new_node);
if (next_node)
hfs_bnode_put(next_node);
return ERR_PTR(-ENOSPC); return ERR_PTR(-ENOSPC);
} }
...@@ -315,8 +328,7 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd) ...@@ -315,8 +328,7 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd)
hfs_bnode_write(node, &node_desc, 0, sizeof(node_desc)); hfs_bnode_write(node, &node_desc, 0, sizeof(node_desc));
/* update next bnode header */ /* update next bnode header */
if (new_node->next) { if (next_node) {
struct hfs_bnode *next_node = hfs_bnode_find(tree, new_node->next);
next_node->prev = new_node->this; next_node->prev = new_node->this;
hfs_bnode_read(next_node, &node_desc, 0, sizeof(node_desc)); hfs_bnode_read(next_node, &node_desc, 0, sizeof(node_desc));
node_desc.prev = cpu_to_be32(next_node->prev); node_desc.prev = cpu_to_be32(next_node->prev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment