hfsplus: add a check for hfs_bnode_find
Subsystems (2)
PATCH 2/2 hfsplus: add a check for hfs_bnode_find
hfs_brec_update_parent misses a check for hfs_bnode_find and may miss the failure.
Add a check for it like what is done in again.
--- fs/hfsplus/brec.c | 2 ++ 1 file changed, 2 insertions(+)
fs/hfsplus/brec.c +2 -0
@@ -434,6 +434,8 @@ static int hfs_brec_update_parent(struct hfs_find_data *fd) new_node->parent = tree->root; } fd->bnode =hfs_bnode_find (tree, new_node->parent); +if (IS_ERR (fd->bnode)) +return PTR_ERR (fd->bnode);/* create index key and entry */ hfs_bnode_read_key (new_node, fd->search_key,14 ); cnid =cpu_to_be32 (new_node->this);
Signature · 1 line
2.20.1
Hi,
Quoted 14 lines · Chuhong Yuan
hfs_brec_update_parentmisses a check forhfs_bnode_findand may miss the failure.
Add a check for it like what is done in again.Signed-off-by Chuhong Yuan <[email protected]>--- fs/hfsplus/brec.c | 2 ++ 1 file changed, 2 insertions(+)fs/hfsplus/brec.c +0
-0
fs/hfsplus/brec.c static int hfs_brec_update_parent(struct hfs_find_data *fd) · line 438
Quoted 5 lines
fs/hfsplus/brec.c +2
-0@@ -434,6 +434,8 @@ static int hfs_brec_update_parent(struct hfs_find_data *fd) new_node->parent = tree->root; } fd->bnode =hfs_bnode_find (tree, new_node->parent); +if (IS_ERR (fd->bnode)) +return PTR_ERR (fd->bnode);
You shouldn't just return here, you still hold a reference to new_node. The call to hfs_bnode_find() after the again label seems to be making a similar mistake.
I don't think either one can actually fail though, because the parent nodes have all been read and hashed before, haven't they?
Quoted 6 lines
fs/hfsplus/brec.c +0
-0/* create index key and entry */ hfs_bnode_read_key (new_node, fd->search_key,14 ); cnid =cpu_to_be32 (new_node->this);Signature · 1 line
2.20.1
Quoted 28 lines · Ernesto A. Fernández
Hi,
Quoted 14 lines · Chuhong Yuan
hfs_brec_update_parentmisses a check forhfs_bnode_findand may miss the failure.
Add a check for it like what is done in again.Signed-off-by Chuhong Yuan <[email protected]>--- fs/hfsplus/brec.c | 2 ++ 1 file changed, 2 insertions(+)fs/hfsplus/brec.c +0
-0fs/hfsplus/brec.c static int hfs_brec_update_parent(struct hfs_find_data *fd) · line 438
Quoted 5 lines
fs/hfsplus/brec.c +2
-0@@ -434,6 +434,8 @@ static int hfs_brec_update_parent(struct hfs_find_data *fd) new_node->parent = tree->root; } fd->bnode =hfs_bnode_find (tree, new_node->parent); +if (IS_ERR (fd->bnode)) +return PTR_ERR (fd->bnode);You shouldn't just return here, you still hold a reference to
new_node. The call tohfs_bnode_find()after the again label seems to be making a similar mistake.
Quoted 3 lines
I don't think either one can actually fail though, because the parent nodes have all been read and hashed before, haven't they?
I find that after hfs_bnode_findhash in hfs_bnode_find, there is a test for HFS_BNODE_ERROR and may return an error. I'm not sure whether it can happen here.
Quoted 6 lines
Quoted 6 lines
fs/hfsplus/brec.c +0
-1/* create index key and entry */ hfs_bnode_read_key (new_node, fd->search_key,14 ); cnid =cpu_to_be32 (new_node->this); --2.20.1
Quoted 30 lines · Chuhong Yuan
Quoted 28 lines · Ernesto A. Fernández
Hi,
Quoted 14 lines · Chuhong Yuan
hfs_brec_update_parentmisses a check forhfs_bnode_findand may miss the failure.
Add a check for it like what is done in again.Signed-off-by Chuhong Yuan <[email protected]>--- fs/hfsplus/brec.c | 2 ++ 1 file changed, 2 insertions(+)fs/hfsplus/brec.c +0
-0fs/hfsplus/brec.c static int hfs_brec_update_parent(struct hfs_find_data *fd) · line 438
Quoted 5 lines
fs/hfsplus/brec.c +2
-0@@ -434,6 +434,8 @@ static int hfs_brec_update_parent(struct hfs_find_data *fd) new_node->parent = tree->root; } fd->bnode =hfs_bnode_find (tree, new_node->parent); +if (IS_ERR (fd->bnode)) +return PTR_ERR (fd->bnode);You shouldn't just return here, you still hold a reference to
new_node. The call tohfs_bnode_find()after the again label seems to be making a similar mistake.
Quoted 7 lines
Quoted 3 lines
I don't think either one can actually fail though, because the parent nodes have all been read and hashed before, haven't they?
I find that after
hfs_bnode_findhashinhfs_bnode_find, there is a test forHFS_BNODE_ERRORand may return an error. I'm not sure whether it can happen here.
That would require a race between hfs_bnode_find() and hfs_bnode_create(), but the node has already been created.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
fs/hfsplus/brec.c +0
-1/* create index key and entry */ hfs_bnode_read_key (new_node, fd->search_key,14 ); cnid =cpu_to_be32 (new_node->this); --2.20.1
Viacheslav Dubeyko
maintainerSorry, I had some glitch during message sending. I am repeating the message sending.
Quoted 37 lines · Ernesto A. Fernández
Quoted 34 lines · Chuhong Yuan
Quoted 31 lines · Ernesto A. Fernández
Hi,
Quoted 14 lines · Chuhong Yuan
hfs_brec_update_parentmisses a check forhfs_bnode_findand may miss the failure.
Add a check for it like what is done in again.Signed-off-by Chuhong Yuan <[email protected]>---
fs/hfsplus/brec.c| 2 ++1 file changed, 2 insertions(+)fs/hfsplus/brec.c +0
-0fs/hfsplus/brec.c static int hfs_brec_update_parent(struct hfs_find_data *fd) · line 438
Quoted 5 lines
fs/hfsplus/brec.c +2
-0@@ -434,6 +434,8 @@ static int hfs_brec_update_parent(struct hfs_find_data *fd) new_node->parent = tree->root; } fd->bnode =hfs_bnode_find (tree, new_node->parent); +if (IS_ERR (fd->bnode)) +return PTR_ERR (fd->bnode);You shouldn't just return here, you still hold a reference to
new_node. The call tohfs_bnode_find()after the again label seems to be making a similar mistake.I don't think either one can actually fail though, because the parent nodes have all been read and hashed before, haven't they?
Quoted 7 lines
Quoted 3 lines
I find that after
hfs_bnode_findhashinhfs_bnode_find, there is a test forHFS_BNODE_ERRORand may return an error. I'm not sure whether it can happen here.That would require a race between
hfs_bnode_find()andhfs_bnode_create(), but the node has already been created.
The whole function hfs_brec_update_parent() looks like the cycle. And there are several places where PTR_ERR(node) is returned with error ([1] - [2]). So, it sounds that it needs to follow this pattern or to rework these cases too. And, by the way, what if the node pointer will be NULL?
Thanks,
Viacheslav Dubeyko.
[1] https://elixir.bootlin.com/linux/latest/source/fs/hfsplus/brec.c#L371
[2] https://elixir.bootlin.com/linux/latest/source/fs/hfsplus/brec.c#L402
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
fs/hfsplus/brec.c +0
-1/* create index key and entry */ hfs_bnode_read_key (new_node, fd->search_key,14 ); cnid =cpu_to_be32 (new_node->this); --2.20.1