mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <slava@dubeyko.com>
To: Mahmut Emin Kurhan <guvenlik@noroxi.com>, linux-fsdevel@vger.kernel.org
Cc: glaubitz@physik.fu-berlin.de, frank.li@vivo.com,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] hfs: free cached B-tree nodes on hfs_btree_open() error path
Date: Thu, 01 Oct 2026 13:03:52 -0700	[thread overview]
Message-ID: <d71d72862f33fd3f10c1808121eae2654250817d.camel@dubeyko.com> (raw)
In-Reply-To: <20260930232312.1405042-3-guvenlik@noroxi.com>

On Thu, 2026-10-01 at 01:23 +0200, Mahmut Emin Kurhan wrote:
> The classic HFS driver has the same B-tree node leak as hfsplus: on
> the
> hfs_btree_open() error path after hfs_bnode_find(tree,
> HFS_TREE_HEAD), an
> errored head node left in tree->node_hash is not freed because
> free_tree:
> does a bare kfree(tree) instead of walking the hash.
> 
> Apply the same fix: factor the node-hash freeing into
> hfs_bnode_hash_free()
> and call it from hfs_btree_close() and the hfs_btree_open() error
> path.
> 
> Found via coverage-guided fuzzing (syzkaller + kmemleak) by Noroxi.
> 
> Signed-off-by: Mahmut Emin Kurhan <guvenlik@noroxi.com>
> ---
>  fs/hfs/btree.c | 34 ++++++++++++++++++++--------------
>  1 file changed, 20 insertions(+), 14 deletions(-)
> 
> diff --git a/fs/hfs/btree.c b/fs/hfs/btree.c
> index 41b4e8fc9..51d1e19a4 100644
> --- a/fs/hfs/btree.c
> +++ b/fs/hfs/btree.c
> @@ -131,6 +131,24 @@ static int hfs_bmap_clear_bit(struct hfs_bnode
> *node, u32 node_bit_idx)
>  }
>  
>  /* Get a reference to a B*Tree and do some initial checks */
> +static void hfs_bnode_hash_free(struct hfs_btree *tree)
> +{
> +	struct hfs_bnode *node;
> +	int i;
> +
> +	for (i = 0; i < NODE_HASH_SIZE; i++) {
> +		while ((node = tree->node_hash[i])) {
> +			tree->node_hash[i] = node->next_hash;
> +			if (atomic_read(&node->refcnt))
> +				pr_err("node %d:%d still has %d
> user(s)!\n",
> +				       node->tree->cnid, node->this,
> +				       atomic_read(&node->refcnt));
> +			hfs_bnode_free(node);
> +			tree->node_hash_cnt--;
> +		}
> +	}
> +}
> +
>  struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id,
> btree_keycmp keycmp)
>  {
>  	struct hfs_btree *tree;
> @@ -296,6 +314,7 @@ struct hfs_btree *hfs_btree_open(struct
> super_block *sb, u32 id, btree_keycmp ke
>  	tree->inode->i_mapping->a_ops = &hfs_aops;
>  	iput(tree->inode);
>  free_tree:
> +	hfs_bnode_hash_free(tree);
>  	kfree(tree);
>  	return NULL;
>  }
> @@ -303,23 +322,10 @@ struct hfs_btree *hfs_btree_open(struct
> super_block *sb, u32 id, btree_keycmp ke
>  /* Release resources used by a btree */
>  void hfs_btree_close(struct hfs_btree *tree)
>  {
> -	struct hfs_bnode *node;
> -	int i;
> -
>  	if (!tree)
>  		return;
>  
> -	for (i = 0; i < NODE_HASH_SIZE; i++) {
> -		while ((node = tree->node_hash[i])) {
> -			tree->node_hash[i] = node->next_hash;
> -			if (atomic_read(&node->refcnt))
> -				pr_err("node %d:%d still has %d
> user(s)!\n",
> -				       node->tree->cnid, node->this,
> -				       atomic_read(&node->refcnt));
> -			hfs_bnode_free(node);
> -			tree->node_hash_cnt--;
> -		}
> -	}
> +	hfs_bnode_hash_free(tree);
>  	iput(tree->inode);
>  	kfree(tree);
>  }

Ditto. Now your patch conflicts with [1]. Please, base your patch on
for-next branch of HFS/HFS+ git tree [2].

Thanks,
Slava.

[1]
https://lore.kernel.org/r/20260921153729.600313-1-bruno.produit@trailofbits.com
[2]
https://git.kernel.org/pub/scm/linux/kernel/git/vdubeyko/hfs.git/log/?h=for-next

      reply	other threads:[~2026-10-01 20:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 18:50 [PATCH] hfsplus: " Mahmut Emin Kurhan
2026-09-30 23:04 ` Viacheslav Dubeyko
2026-09-30 23:23   ` [PATCH v2 0/2] hfsplus, hfs: fix B-tree node leak " Mahmut Emin Kurhan
2026-09-30 23:23     ` [PATCH v2 1/2] hfsplus: free cached B-tree nodes " Mahmut Emin Kurhan
2026-10-01 20:03       ` Viacheslav Dubeyko
2026-10-01 21:38         ` [PATCH v3 0/2] hfsplus, hfs: fix B-tree node leak " Mahmut Emin Kurhan
2026-10-01 21:38           ` [PATCH v3 1/2] hfsplus: free cached B-tree nodes " Mahmut Emin Kurhan
2026-10-01 21:38           ` [PATCH v3 2/2] hfs: " Mahmut Emin Kurhan
2026-09-30 23:23     ` [PATCH v2 " Mahmut Emin Kurhan
2026-10-01 20:03       ` Viacheslav Dubeyko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d71d72862f33fd3f10c1808121eae2654250817d.camel@dubeyko.com \
    --to=slava@dubeyko.com \
    --cc=frank.li@vivo.com \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=guvenlik@noroxi.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®