Re: [syzbot] [hfs?] possible deadlock in hfsplus_file_extend (2)

From: Edward Adam Davis
Date: Tue Nov 12 2024 - 00:45:20 EST


AA lock, unlock for hfs_bmap_reserve.

#syz test

diff --git a/fs/hfsplus/extents.c b/fs/hfsplus/extents.c
index a6d61685ae79..90366e2da3c7 100644
--- a/fs/hfsplus/extents.c
+++ b/fs/hfsplus/extents.c
@@ -101,7 +101,12 @@ static int __hfsplus_ext_write_extent(struct inode *inode,
if (res != -ENOENT)
return res;
/* Fail early and avoid ENOSPC during the btree operation */
+ mutex_unlock(&hip->extents_lock);
+ mutex_unlock(&fd->tree->tree_lock);
res = hfs_bmap_reserve(fd->tree, fd->tree->depth + 1);
+ mutex_lock(&hip->extents_lock);
+ mutex_lock_nested(&fd->tree->tree_lock,
+ hfsplus_btree_lock_class(fd->tree));
if (res)
return res;
hfs_brec_insert(fd, hip->cached_extents,