* [PATCH] HFS: btree: fix missing error check after hfs_bnode_find()
@ 2025-12-09 2:14 Haotian Zhang
2025-12-10 17:09 ` Markus Elfring
2025-12-11 23:13 ` Viacheslav Dubeyko
0 siblings, 2 replies; 3+ messages in thread
From: Haotian Zhang @ 2025-12-09 2:14 UTC (permalink / raw)
To: slava, glaubitz, frank.li; +Cc: linux-fsdevel, linux-kernel, Haotian Zhang
In hfs_brec_insert() and hfs_brec_update_parent(), hfs_bnode_find()
may return ERR_PTR() on failure, but the result was used without
checking, risking NULL pointer dereference or invalid pointer usage.
Add IS_ERR() checks after these calls and return PTR_ERR()
on error.
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
fs/hfs/brec.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/hfs/brec.c b/fs/hfs/brec.c
index e49a141c87e5..afa1840a4847 100644
--- a/fs/hfs/brec.c
+++ b/fs/hfs/brec.c
@@ -149,6 +149,8 @@ int hfs_brec_insert(struct hfs_find_data *fd, void *entry, int entry_len)
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 data entry */
cnid = cpu_to_be32(new_node->this);
@@ -449,6 +451,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);
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] HFS: btree: fix missing error check after hfs_bnode_find()
2025-12-09 2:14 [PATCH] HFS: btree: fix missing error check after hfs_bnode_find() Haotian Zhang
@ 2025-12-10 17:09 ` Markus Elfring
2025-12-11 23:13 ` Viacheslav Dubeyko
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-12-10 17:09 UTC (permalink / raw)
To: vulab, linux-fsdevel, John Paul Adrian Glaubitz,
Viacheslav Dubeyko, Yangtao Li
Cc: LKML
> In hfs_brec_insert() and hfs_brec_update_parent(), hfs_bnode_find()
> may return ERR_PTR() on failure, but the result was used without
> checking, risking NULL pointer dereference or invalid pointer usage.
>
> Add IS_ERR() checks after these calls and return PTR_ERR()
> on error.
* Can an other word wrapping look eventually a bit nicer here?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18#n658
* How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18#n145
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] HFS: btree: fix missing error check after hfs_bnode_find()
2025-12-09 2:14 [PATCH] HFS: btree: fix missing error check after hfs_bnode_find() Haotian Zhang
2025-12-10 17:09 ` Markus Elfring
@ 2025-12-11 23:13 ` Viacheslav Dubeyko
1 sibling, 0 replies; 3+ messages in thread
From: Viacheslav Dubeyko @ 2025-12-11 23:13 UTC (permalink / raw)
To: Haotian Zhang, glaubitz, frank.li; +Cc: linux-fsdevel, linux-kernel
On Tue, 2025-12-09 at 10:14 +0800, Haotian Zhang wrote:
> In hfs_brec_insert() and hfs_brec_update_parent(), hfs_bnode_find()
> may return ERR_PTR() on failure, but the result was used without
> checking, risking NULL pointer dereference or invalid pointer usage.
>
> Add IS_ERR() checks after these calls and return PTR_ERR()
> on error.
>
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
> ---
> fs/hfs/brec.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/fs/hfs/brec.c b/fs/hfs/brec.c
> index e49a141c87e5..afa1840a4847 100644
> --- a/fs/hfs/brec.c
> +++ b/fs/hfs/brec.c
> @@ -149,6 +149,8 @@ int hfs_brec_insert(struct hfs_find_data *fd,
> void *entry, int entry_len)
> 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 data entry */
> cnid = cpu_to_be32(new_node->this);
> @@ -449,6 +451,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);
Frankly speaking, I am not sure that we need to add this check.
Because, we are trying to find the parent node that already has been
found in above logic of the method. So, we should have the parent node
available. Potentially, logic could work in wrong way, but we should
already have a reported bug already.
Even if this check makes sense, then we cannot simply return the error
code here. If you check the following logic, then you can see that we
call hfs_bnode_put() for the new node. So, if this check doesn't do
this in the case of error, then we create the leak here.
Have you ever reproduced the issue that you are trying to fix?
Thanks,
Slava.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-11 23:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-09 2:14 [PATCH] HFS: btree: fix missing error check after hfs_bnode_find() Haotian Zhang
2025-12-10 17:09 ` Markus Elfring
2025-12-11 23:13 ` Viacheslav Dubeyko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®