memory leak in __hfs_bnode_create
Subsystems (2)
syzbot
syzbotHello,
syzbot found the following issue on:
HEAD commit: 508fed679541 Merge tag 'ras_core_for_v7.1_rc1' of git://gi.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=1481bb16580000 kernel config: https://syzkaller.appspot.com/x/.config?x=c7349847759051f dashboard link: https://syzkaller.appspot.com/bug?extid=98547b0428b6a6a3467c compiler: gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1281bb16580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=107938ce580000
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/36836f0baa65/disk-508fed67.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/ab35bf742ab5/vmlinux-508fed67.xz
kernel image: https://storage.googleapis.com/syzbot-assets/5fbf86a0b4d3/bzImage-508fed67.xz
mounted in repro: https://storage.googleapis.com/syzbot-assets/d2ddc5d747a0/mount_4.gz
IMPORTANT: if you fix the issue, please add the following tag to the commit:
BUG: memory leak
unreferenced object 0xffff88811cabc840 (size 96):
comm "syz.0.18", pid 6071, jiffies 4294943951
hex dump (first 32 bytes):
00 f0 54 15 81 88 ff ff 00 00 00 00 00 00 00 00 ..T.............
00 00 00 00 00 00 00 00 03 00 7f 00 00 00 00 00 ................
backtrace (crc 3e2dadb7):
kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
slab_post_alloc_hook mm/slub.c:4543 [inline]
slab_alloc_node mm/slub.c:4866 [inline]
__do_kmalloc_node mm/slub.c:5259 [inline]
__kmalloc_noprof+0x3b7/0x550 mm/slub.c:5272
kmalloc_noprof include/linux/slab.h:954 [inline]
kzalloc_noprof include/linux/slab.h:1188 [inline]
__hfs_bnode_create+0x59/0x310 fs/hfsplus/bnode.c:469
hfsplus_bnode_find+0x13e/0x580 fs/hfsplus/bnode.c:547
hfsplus_btree_open+0x2fa/0x6d0 fs/hfsplus/btree.c:382
hfsplus_fill_super+0x272/0x880 fs/hfsplus/super.c:548
get_tree_bdev_flags+0x1c0/0x290 fs/super.c:1694
vfs_get_tree+0x30/0x120 fs/super.c:1754
fc_mount fs/namespace.c:1193 [inline]
do_new_mount_fc fs/namespace.c:3763 [inline]
do_new_mount fs/namespace.c:3839 [inline]
path_mount+0x5a9/0x1360 fs/namespace.c:4159
do_mount fs/namespace.c:4172 [inline]
__do_sys_mount fs/namespace.c:4361 [inline]
__se_sys_mount fs/namespace.c:4338 [inline]
__x64_sys_mount+0x1a3/0x1e0 fs/namespace.c:4338
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xee/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
BUG: memory leak
unreferenced object 0xffff88812c724d80 (size 96):
comm "syz.0.19", pid 6082, jiffies 4294943963
hex dump (first 32 bytes):
00 90 e5 13 81 88 ff ff 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 03 00 7f 00 00 00 00 00 ................
backtrace (crc 289d56ee):
kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
slab_post_alloc_hook mm/slub.c:4543 [inline]
slab_alloc_node mm/slub.c:4866 [inline]
__do_kmalloc_node mm/slub.c:5259 [inline]
__kmalloc_noprof+0x3b7/0x550 mm/slub.c:5272
kmalloc_noprof include/linux/slab.h:954 [inline]
kzalloc_noprof include/linux/slab.h:1188 [inline]
__hfs_bnode_create+0x59/0x310 fs/hfsplus/bnode.c:469
hfsplus_bnode_find+0x13e/0x580 fs/hfsplus/bnode.c:547
hfsplus_btree_open+0x2fa/0x6d0 fs/hfsplus/btree.c:382
hfsplus_fill_super+0x272/0x880 fs/hfsplus/super.c:548
get_tree_bdev_flags+0x1c0/0x290 fs/super.c:1694
vfs_get_tree+0x30/0x120 fs/super.c:1754
fc_mount fs/namespace.c:1193 [inline]
do_new_mount_fc fs/namespace.c:3763 [inline]
do_new_mount fs/namespace.c:3839 [inline]
path_mount+0x5a9/0x1360 fs/namespace.c:4159
do_mount fs/namespace.c:4172 [inline]
__do_sys_mount fs/namespace.c:4361 [inline]
__se_sys_mount fs/namespace.c:4338 [inline]
__x64_sys_mount+0x1a3/0x1e0 fs/namespace.c:4338
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xee/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7fconnection error: failed to recv *flatrpc.ExecutorMessageRawT: EOF
---
This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at [email protected].
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title
If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.
If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)
If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report
If you want to undo deduplication, reply with:
#syz undup
#syz test
fs/hfsplus/btree.c +3 -1
@@ -270,7 +270,7 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)struct hfs_btree *tree;struct hfs_btree_header_rec *head;struct address_space *mapping; -struct hfs_bnode *node; +struct hfs_bnode *node =NULL ;struct inode *inode;struct page *page;unsigned int size;
@@ -401,6 +401,8 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)put_page (page); free_inode: tree->inode->i_mapping->a_ops = &hfsplus_aops; +if (!IS_ERR_OR_NULL (node)) +hfs_bnode_put (node);iput (tree->inode); free_tree:kfree (tree);
#syz test
fs/hfsplus/bnode.c +4 -1
@@ -604,7 +604,10 @@ struct hfs_bnode *hfs_bnode_find(struct hfs_btree *tree, u32 num) node_error:set_bit (HFS_BNODE_ERROR , &node->flags); -clear_bit (HFS_BNODE_NEW , &node->flags); +if (test_bit (HFS_BNODE_NEW , &node->flags)) { +hfs_bnode_free (node); +return ERR_PTR (-EIO ); + }wake_up (&node->lock_wq);hfs_bnode_put (node);return ERR_PTR (-EIO );
#syz test
fs/hfsplus/bnode.c +7 -0
@@ -604,6 +604,13 @@ struct hfs_bnode *hfs_bnode_find(struct hfs_btree *tree, u32 num) node_error:set_bit (HFS_BNODE_ERROR , &node->flags); +if (test_bit (HFS_BNODE_NEW , &node->flags)) { +if (num ==HFSPLUS_TREE_HEAD ) { +hfs_bnode_unhash (node); +hfs_bnode_free (node); +return ERR_PTR (-EIO ); + } + }clear_bit (HFS_BNODE_NEW , &node->flags);wake_up (&node->lock_wq);hfs_bnode_put (node);
syzbot
syzbotsyzbot has tested the proposed patch but the reproducer is still triggering an issue: memory leak in __hfs_bnode_create
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
memory leak in __hfs_bnode_create
BUG: memory leak
unreferenced object 0xffff88811d782480 (size 96):
comm "syz.0.17", pid 6738, jiffies 4294945815
hex dump (first 32 bytes):
00 a0 6b 13 81 88 ff ff 00 00 00 00 00 00 00 00 ..k.............
00 00 00 00 00 00 00 00 03 00 7f 00 00 00 00 00 ................
backtrace (crc e40892e2):
kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
slab_post_alloc_hook mm/slub.c:4574 [inline]
slab_alloc_node mm/slub.c:4898 [inline]
__do_kmalloc_node mm/slub.c:5294 [inline]
__kmalloc_noprof+0x3b7/0x550 mm/slub.c:5307
kmalloc_noprof include/linux/slab.h:954 [inline]
kzalloc_noprof include/linux/slab.h:1188 [inline]
__hfs_bnode_create+0x59/0x310 fs/hfsplus/bnode.c:469
hfsplus_bnode_find+0x13e/0x580 fs/hfsplus/bnode.c:547
hfsplus_btree_open+0x2e1/0x5a0 fs/hfsplus/btree.c:382
hfsplus_fill_super+0x272/0x880 fs/hfsplus/super.c:548
get_tree_bdev_flags+0x1c0/0x290 fs/super.c:1694
vfs_get_tree+0x30/0x120 fs/super.c:1754
fc_mount fs/namespace.c:1193 [inline]
do_new_mount_fc fs/namespace.c:3758 [inline]
do_new_mount fs/namespace.c:3834 [inline]
path_mount+0x5a9/0x1370 fs/namespace.c:4154
do_mount fs/namespace.c:4167 [inline]
__do_sys_mount fs/namespace.c:4383 [inline]
__se_sys_mount fs/namespace.c:4360 [inline]
__x64_sys_mount+0x1a3/0x1e0 fs/namespace.c:4360
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xee/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
BUG: memory leak
unreferenced object 0xffff88811d780780 (size 96):
comm "syz.0.18", pid 6747, jiffies 4294945821
hex dump (first 32 bytes):
00 80 31 14 81 88 ff ff 00 00 00 00 00 00 00 00 ..1.............
00 00 00 00 00 00 00 00 03 00 7f 00 00 00 00 00 ................
backtrace (crc daa1adcb):
kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
slab_post_alloc_hook mm/slub.c:4574 [inline]
slab_alloc_node mm/slub.c:4898 [inline]
__do_kmalloc_node mm/slub.c:5294 [inline]
__kmalloc_noprof+0x3b7/0x550 mm/slub.c:5307
kmalloc_noprof include/linux/slab.h:954 [inline]
kzalloc_noprof include/linux/slab.h:1188 [inline]
__hfs_bnode_create+0x59/0x310 fs/hfsplus/bnode.c:469
hfsplus_bnode_find+0x13e/0x580 fs/hfsplus/bnode.c:547
hfsplus_btree_open+0x2e1/0x5a0 fs/hfsplus/btree.c:382
hfsplus_fill_super+0x272/0x880 fs/hfsplus/super.c:548
get_tree_bdev_flags+0x1c0/0x290 fs/super.c:1694
vfs_get_tree+0x30/0x120 fs/super.c:1754
fc_mount fs/namespace.c:1193 [inline]
do_new_mount_fc fs/namespace.c:3758 [inline]
do_new_mount fs/namespace.c:3834 [inline]
path_mount+0x5a9/0x1370 fs/namespace.c:4154
do_mount fs/namespace.c:4167 [inline]
__do_sys_mount fs/namespace.c:4383 [inline]
__se_sys_mount fs/namespace.c:4360 [inline]
__x64_sys_mount+0x1a3/0x1e0 fs/namespace.c:4360
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xee/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
BUG: memory leak
unreferenced object 0xffff888113764300 (size 96):
comm "syz.0.19", pid 6759, jiffies 4294945830
hex dump (first 32 bytes):
00 f0 31 14 81 88 ff ff 00 00 00 00 00 00 00 00 ..1.............
00 00 00 00 00 00 00 00 03 00 7f 00 00 00 00 00 ................
backtrace (crc 1420922e):
kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
slab_post_alloc_hook mm/slub.c:4574 [inline]
slab_alloc_node mm/slub.c:4898 [inline]
__do_kmalloc_node mm/slub.c:5294 [inline]
__kmalloc_noprof+0x3b7/0x550 mm/slub.c:5307
kmalloc_noprof include/linux/slab.h:954 [inline]
kzalloc_noprof include/linux/slab.h:1188 [inline]
__hfs_bnode_create+0x59/0x310 fs/hfsplus/bnode.c:469
hfsplus_bnode_find+0x13e/0x580 fs/hfsplus/bnode.c:547
hfsplus_btree_open+0x2e1/0x5a0 fs/hfsplus/btree.c:382
hfsplus_fill_super+0x272/0x880 fs/hfsplus/super.c:548
get_tree_bdev_flags+0x1c0/0x290 fs/super.c:1694
vfs_get_tree+0x30/0x120 fs/super.c:1754
fc_mount fs/namespace.c:1193 [inline]
do_new_mount_fc fs/namespace.c:3758 [inline]
do_new_mount fs/namespace.c:3834 [inline]
path_mount+0x5a9/0x1370 fs/namespace.c:4154
do_mount fs/namespace.c:4167 [inline]
__do_sys_mount fs/namespace.c:4383 [inline]
__se_sys_mount fs/namespace.c:4360 [inline]
__x64_sys_mount+0x1a3/0x1e0 fs/namespace.c:4360
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xee/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7fconnection error: failed to recv *flatrpc.ExecutorMessageRawT: EOF
Tested on:
commit: 43cfbdda Merge tag 'for-linus-iommufd' of git://git.ke.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=116024ce580000 kernel config: https://syzkaller.appspot.com/x/.config?x=208b81ceb4623b6b dashboard link: https://syzkaller.appspot.com/bug?extid=98547b0428b6a6a3467c compiler: gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44 patch: https://syzkaller.appspot.com/x/patch.diff?x=1077c4ce580000
#syz test
fs/hfsplus/bnode.c +13 -2
@@ -598,12 +598,23 @@ struct hfs_bnode *hfs_bnode_find(struct hfs_btree *tree, u32 num)if (key_size >= entry_size || key_size &1 ) goto node_error; } -clear_bit (HFS_BNODE_NEW , &node->flags); -wake_up (&node->lock_wq); +if (num !=HFSPLUS_TREE_HEAD ) { +clear_bit (HFS_BNODE_NEW , &node->flags); +wake_up (&node->lock_wq); + }return node; node_error:set_bit (HFS_BNODE_ERROR , &node->flags); +if (test_bit (HFS_BNODE_NEW , &node->flags)) { +if (num ==HFSPLUS_TREE_HEAD ) { +spin_lock (&tree->hash_lock); +hfs_bnode_unhash (node); +hfs_bnode_free (node); +spin_unlock (&tree->hash_lock); +return ERR_PTR (-EIO ); + } + }clear_bit (HFS_BNODE_NEW , &node->flags);wake_up (&node->lock_wq);hfs_bnode_put (node);
fs/hfsplus/btree.c +8 -1
@@ -392,7 +392,14 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id) sb->s_flags |=SB_RDONLY ; } -hfs_bnode_put (node); +if (test_bit (HFS_BNODE_NEW , &node->flags)) { +spin_lock (&tree->hash_lock); +hfs_bnode_unhash (node); +hfs_bnode_free (node); +spin_unlock (&tree->hash_lock); + } +else +hfs_bnode_put (node);return tree;
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 43cfbdda Merge tag 'for-linus-iommufd' of git://git.ke.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=15d441ba580000 kernel config: https://syzkaller.appspot.com/x/.config?x=208b81ceb4623b6b dashboard link: https://syzkaller.appspot.com/bug?extid=98547b0428b6a6a3467c compiler: gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44 patch: https://syzkaller.appspot.com/x/patch.diff?x=173fc4ce580000
Note: testing is done by a robot and is best-effort only.
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 43cfbdda Merge tag 'for-linus-iommufd' of git://git.ke.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=144f58ce580000 kernel config: https://syzkaller.appspot.com/x/.config?x=208b81ceb4623b6b dashboard link: https://syzkaller.appspot.com/bug?extid=98547b0428b6a6a3467c compiler: gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44 patch: https://syzkaller.appspot.com/x/patch.diff?x=15d81906580000
Note: testing is done by a robot and is best-effort only.
#syz test
fs/hfsplus/bnode.c +12 -4
@@ -598,14 +598,18 @@ struct hfs_bnode *hfs_bnode_find(struct hfs_btree *tree, u32 num)if (key_size >= entry_size || key_size &1 ) goto node_error; } -clear_bit (HFS_BNODE_NEW , &node->flags); -wake_up (&node->lock_wq); +if (num !=HFSPLUS_TREE_HEAD ) { +clear_bit (HFS_BNODE_NEW , &node->flags); +wake_up (&node->lock_wq); + }return node; node_error:set_bit (HFS_BNODE_ERROR , &node->flags); -clear_bit (HFS_BNODE_NEW , &node->flags); -wake_up (&node->lock_wq); +if (num !=HFSPLUS_TREE_HEAD ) { +clear_bit (HFS_BNODE_NEW , &node->flags); +wake_up (&node->lock_wq); + }hfs_bnode_put (node);return ERR_PTR (-EIO ); }
@@ -694,6 +698,10 @@ void hfs_bnode_put(struct hfs_bnode *node)hfs_bnode_free (node);return ; } +if (test_bit (HFS_BNODE_NEW , &node->flags)) { +hfs_bnode_unhash (node); +hfs_bnode_free (node); + }spin_unlock (&tree->hash_lock); } }
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 43cfbdda Merge tag 'for-linus-iommufd' of git://git.ke.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=154682d2580000 kernel config: https://syzkaller.appspot.com/x/.config?x=208b81ceb4623b6b dashboard link: https://syzkaller.appspot.com/bug?extid=98547b0428b6a6a3467c compiler: gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44 patch: https://syzkaller.appspot.com/x/patch.diff?x=14441906580000
Note: testing is done by a robot and is best-effort only.
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 43cfbdda Merge tag 'for-linus-iommufd' of git://git.ke.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=15df58ce580000 kernel config: https://syzkaller.appspot.com/x/.config?x=208b81ceb4623b6b dashboard link: https://syzkaller.appspot.com/bug?extid=98547b0428b6a6a3467c compiler: gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44 patch: https://syzkaller.appspot.com/x/patch.diff?x=10d49a6a580000
Note: testing is done by a robot and is best-effort only.
PATCH 1/1 hfsplus: Supports freeing newly created tree head
In reply to syzbothfs_bnode_put() does not support deallocating a newly created btree head node; therefore, regardless of whether hfsplus_bnode_find() succeeds or fails, it cannot effectively reclaim the memory allocated for a newly created head node.
When finding a head node, if the node is a newly created one, we can use hfs_bnode_free() to reclaim its memory.
[1]
BUG: memory leak
unreferenced object 0xffff88811cabc840 (size 96):
backtrace (crc 3e2dadb7):
__hfs_bnode_create+0x59/0x310 fs/hfsplus/bnode.c:469
hfsplus_bnode_find+0x13e/0x580 fs/hfsplus/bnode.c:547
hfsplus_btree_open+0x2fa/0x6d0 fs/hfsplus/btree.c:382
hfsplus_fill_super+0x272/0x880 fs/hfsplus/super.c:548--- fs/hfsplus/bnode.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
fs/hfsplus/bnode.c +12 -4
@@ -598,14 +598,18 @@ struct hfs_bnode *hfs_bnode_find(struct hfs_btree *tree, u32 num)if (key_size >= entry_size || key_size &1 ) goto node_error; } -clear_bit (HFS_BNODE_NEW , &node->flags); -wake_up (&node->lock_wq); +if (num !=HFSPLUS_TREE_HEAD ) { +clear_bit (HFS_BNODE_NEW , &node->flags); +wake_up (&node->lock_wq); + }return node; node_error:set_bit (HFS_BNODE_ERROR , &node->flags); -clear_bit (HFS_BNODE_NEW , &node->flags); -wake_up (&node->lock_wq); +if (num !=HFSPLUS_TREE_HEAD ) { +clear_bit (HFS_BNODE_NEW , &node->flags); +wake_up (&node->lock_wq); + }hfs_bnode_put (node);return ERR_PTR (-EIO ); }
@@ -694,6 +698,10 @@ void hfs_bnode_put(struct hfs_bnode *node)hfs_bnode_free (node);return ; } +if (test_bit (HFS_BNODE_NEW , &node->flags)) { +hfs_bnode_unhash (node); +hfs_bnode_free (node); + }spin_unlock (&tree->hash_lock); } }
Signature · 1 line
2.43.0
Re: [PATCH] hfsplus: Supports freeing newly created tree head
Quoted 8 lines · Edward Adam Davis
hfs_bnode_put()does not support deallocating a newly created btree head node; therefore, regardless of whetherhfsplus_bnode_find()succeeds or fails, it cannot effectively reclaim the memory allocated for a newly created head node.When finding a head node, if the node is a newly created one, we can use
hfs_bnode_free()to reclaim its memory.
Quoted 8 lines
[1]
BUG: memory leak unreferenced object 0xffff88811cabc840 (size 96): backtrace (crc 3e2dadb7): __hfs_bnode_create+0x59/0x310 fs/hfsplus/bnode.c:469 hfsplus_bnode_find+0x13e/0x580 fs/hfsplus/bnode.c:547 hfsplus_btree_open+0x2fa/0x6d0 fs/hfsplus/btree.c:382 hfsplus_fill_super+0x272/0x880 fs/hfsplus/super.c:548
I need slightly more detailed and clear explanation how the issue has been happened and why we need to fix it in a such way. Currently, I don't have the complete picture how this happened. I am sure that you have the complete picture. :) Could you please share what you have in your mind? :) Don't hide the wisdom. ;)
Thanks,
Slava.
Quoted 48 lines
Fixes 8ad2c6a36ac4 ("hfsplus: validate b-tree node 0 bitmap at mount time")Reported-by [email protected]Tested-by [email protected]Signed-off-by Edward Adam Davis <[email protected]>--- fs/hfsplus/bnode.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)fs/hfsplus/bnode.c +12
-4@@ -598,14 +598,18 @@ struct hfs_bnode *hfs_bnode_find(struct hfs_btree *tree, u32 num)if (key_size >= entry_size || key_size &1 ) goto node_error; } -clear_bit (HFS_BNODE_NEW , &node->flags); -wake_up (&node->lock_wq); +if (num !=HFSPLUS_TREE_HEAD ) { +clear_bit (HFS_BNODE_NEW , &node->flags); +wake_up (&node->lock_wq); + }return node; node_error:set_bit (HFS_BNODE_ERROR , &node->flags); -clear_bit (HFS_BNODE_NEW , &node->flags); -wake_up (&node->lock_wq); +if (num !=HFSPLUS_TREE_HEAD ) { +clear_bit (HFS_BNODE_NEW , &node->flags); +wake_up (&node->lock_wq); + }hfs_bnode_put (node);return ERR_PTR (-EIO ); }@@ -694,6 +698,10 @@ void hfs_bnode_put(struct hfs_bnode *node)hfs_bnode_free (node);return ; } +if (test_bit (HFS_BNODE_NEW , &node->flags)) { +hfs_bnode_unhash (node); +hfs_bnode_free (node); + }spin_unlock (&tree->hash_lock); } }
PATCH 1/1 hfsplus: Supports freeing newly created tree head
Quoted 17 lines · Viacheslav Dubeyko
Quoted 8 lines
hfs_bnode_put()does not support deallocating a newly created btree head node; therefore, regardless of whetherhfsplus_bnode_find()succeeds or fails, it cannot effectively reclaim the memory allocated for a newly created head node.When finding a head node, if the node is a newly created one, we can use
hfs_bnode_free()to reclaim its memory.Quoted 8 lines
[1]
BUG: memory leak unreferenced object 0xffff88811cabc840 (size 96): backtrace (crc 3e2dadb7): __hfs_bnode_create+0x59/0x310 fs/hfsplus/bnode.c:469 hfsplus_bnode_find+0x13e/0x580 fs/hfsplus/bnode.c:547 hfsplus_btree_open+0x2fa/0x6d0 fs/hfsplus/btree.c:382 hfsplus_fill_super+0x272/0x880 fs/hfsplus/super.c:548
Quoted 5 lines
I need slightly more detailed and clear explanation how the issue has been happened and why we need to fix it in a such way. Currently, I don't have the complete picture how this happened. I am sure that you have the complete picture. :) Could you please share what you have in your mind? :) Don't hide the wisdom. ;)
fc_mount()
vfs_get_tree()
get_tree_bdev_flags()
hfsplus_fill_super()
hfsplus_btree_open()
hfsplus_bnode_find(tree, HFSPLUS_TREE_HEAD)
__hfs_bnode_create()
...
node->this = cnid; // cnid is HFSPLUS_TREE_HEAD, it is 0
...
...
desc = (struct hfs_bnode_desc *)(kmap_local_page(node->page[0])
node->type = desc->type;
switch (node->type) {
...
default: // because node->type is 127, so run here
goto node_error;
...
hfs_bnode_put()
...
if (test_bit(HFS_BNODE_DELETED, &node->flags)) { /* head node not set HFS_BNODE_DELETED flag
* so, the node will never be freed.
* Furthermore, even if the node were marked
* with the HFS_BNODE_DELETED flag, hfs_bmap_free()
* would still trigger BUG_ON(!node->this).
*/Edward
BR
Re: [PATCH] hfsplus: Supports freeing newly created tree head
Quoted 23 lines · Edward Adam Davis
Quoted 17 lines · Viacheslav Dubeyko
Quoted 8 lines
hfs_bnode_put()does not support deallocating a newly created btree head node; therefore, regardless of whetherhfsplus_bnode_find()succeeds or fails, it cannot effectively reclaim the memory allocated for a newly created head node.When finding a head node, if the node is a newly created one, we can use
hfs_bnode_free()to reclaim its memory.Quoted 8 lines
[1]
BUG: memory leak unreferenced object 0xffff88811cabc840 (size 96): backtrace (crc 3e2dadb7): __hfs_bnode_create+0x59/0x310 fs/hfsplus/bnode.c:469 hfsplus_bnode_find+0x13e/0x580 fs/hfsplus/bnode.c:547 hfsplus_btree_open+0x2fa/0x6d0 fs/hfsplus/btree.c:382 hfsplus_fill_super+0x272/0x880 fs/hfsplus/super.c:548Quoted 5 lines
I need slightly more detailed and clear explanation how the issue has been happened and why we need to fix it in a such way. Currently, I don't have the complete picture how this happened. I am sure that you have the complete picture. :) Could you please share what you have in your mind? :) Don't hide the wisdom. ;)
Quoted 4 lines
fc_mount()
vfs_get_tree()
get_tree_bdev_flags()
hfsplus_fill_super() We have multiple calls of hfsplus_btree_open(). Which particular b-tree do you mean here?
Quoted 1 line
hfsplus_btree_open()
I assume that you mean hfs_btree_open().
Quoted 2 lines
hfsplus_bnode_find(tree, HFSPLUS_TREE_HEAD)
We call hfs_bnode_find() here.
Quoted 12 lines
__hfs_bnode_create()
...
node->this = cnid; // cnid is HFSPLUS_TREE_HEAD, it is 0
...
...
desc = (struct hfs_bnode_desc *)(kmap_local_page(node->page[0])
node->type = desc->type;
switch (node->type) {
...
default: // because node->type is 127, so run here
goto node_error;I think, maybe, we need to add some error message(s) when some error is happened. What do you think?
Quoted 9 lines
...
hfs_bnode_put()
...
if (test_bit(HFS_BNODE_DELETED, &node->flags)) { /* head node not set HFS_BNODE_DELETED flag
* so, the node will never be freed.
* Furthermore, even if the node were marked
* with the HFS_BNODE_DELETED flag, hfs_bmap_free()
* would still trigger BUG_ON(!node->this).
*/ node_error:
set_bit(HFS_BNODE_ERROR, &node->flags);
- clear_bit(HFS_BNODE_NEW, &node->flags);
- wake_up(&node->lock_wq);
+ if (num != HFSPLUS_TREE_HEAD) {
Why do we need to distinguish is it HFSPLUS_TREE_HEAD or not? I don't see any difference in node processing.
+ clear_bit(HFS_BNODE_NEW, &node->flags);
I think that we don't need to clear the HFS_BNODE_NEW. Because, we need to analyze HFS_BNODE_ERROR in hfs_bnode_put().
+ wake_up(&node->lock_wq);
I assume that wake_up() should be called anyway. Why have you removed this call for HFSPLUS_TREE_HEAD case?
+ }
hfs_bnode_put(node);
return ERR_PTR(-EIO);
@@ -694,6 +698,10 @@ void hfs_bnode_put(struct hfs_bnode *node)
hfs_bnode_free(node);
return;
}
+ if (test_bit(HFS_BNODE_NEW, &node->flags)) {
I suggest to analyze HFS_BNODE_ERROR here.
+ hfs_bnode_unhash(node);
+ hfs_bnode_free(node);
+ }
@@ -598,14 +598,18 @@ struct hfs_bnode *hfs_bnode_find(struct hfs_btree *tree, u32 num)
if (key_size >= entry_size || key_size & 1)
goto node_error;
}
- clear_bit(HFS_BNODE_NEW, &node->flags);
- wake_up(&node->lock_wq);
+ if (num != HFSPLUS_TREE_HEAD) {
+ clear_bit(HFS_BNODE_NEW, &node->flags);
+ wake_up(&node->lock_wq);
What the point in this code? Why have you change the logic here?
+ }
return node;
And, could you please add these new details into the commit message?
Thanks,
Slava.
Re: [PATCH] hfsplus: Supports freeing newly created tree head
Hi Viacheslav Dubeyko,
Apologies for the late reply.
Quoted 32 lines · Viacheslav Dubeyko
Quoted 23 lines · Edward Adam Davis
Quoted 17 lines · Viacheslav Dubeyko
Quoted 8 lines
hfs_bnode_put()does not support deallocating a newly created btree head node; therefore, regardless of whetherhfsplus_bnode_find()succeeds or fails, it cannot effectively reclaim the memory allocated for a newly created head node.When finding a head node, if the node is a newly created one, we can use
hfs_bnode_free()to reclaim its memory.Quoted 8 lines
[1]
BUG: memory leak unreferenced object 0xffff88811cabc840 (size 96): backtrace (crc 3e2dadb7): __hfs_bnode_create+0x59/0x310 fs/hfsplus/bnode.c:469 hfsplus_bnode_find+0x13e/0x580 fs/hfsplus/bnode.c:547 hfsplus_btree_open+0x2fa/0x6d0 fs/hfsplus/btree.c:382 hfsplus_fill_super+0x272/0x880 fs/hfsplus/super.c:548Quoted 5 lines
I need slightly more detailed and clear explanation how the issue has been happened and why we need to fix it in a such way. Currently, I don't have the complete picture how this happened. I am sure that you have the complete picture. :) Could you please share what you have in your mind? :) Don't hide the wisdom. ;)
Quoted 4 lines
fc_mount() vfs_get_tree() get_tree_bdev_flags() hfsplus_fill_super()We have multiple calls of
hfsplus_btree_open(). Which particular b-tree do you mean here?
Quoted 20 lines
Quoted 1 line
hfsplus_btree_open()I assume that you mean
hfs_btree_open().Quoted 2 lines
hfsplus_bnode_find(tree, HFSPLUS_TREE_HEAD)We call
hfs_bnode_find()here.Quoted 11 lines
__hfs_bnode_create() ... node->this = cnid; // cnid is HFSPLUS_TREE_HEAD, it is 0 ... ... desc = (struct hfs_bnode_desc *)(kmap_local_page(node->page[0]) node->type = desc->type; switch (node->type) { ... default: // because node->type is 127, so run here
Following "default," the comment I added clearly indicates that the issue stems from the type value being 127.
Quoted 13 lines
Quoted 1 line
goto node_error;I think, maybe, we need to add some error message(s) when some error is happened. What do you think?
Quoted 8 lines
... hfs_bnode_put() ... if (test_bit(HFS_BNODE_DELETED, &node->flags)) { /* head node not set HFS_BNODE_DELETED flag * so, the node will never be freed. * Furthermore, even if the node were marked * with the HFS_BNODE_DELETED flag, hfs_bmap_free() * would still trigger BUG_ON(!node->this).
Please note the comments I added above.
Quoted 18 lines
Quoted 1 line
*/
node_error:fs/hfsplus/bnode.c +1
-2set_bit (HFS_BNODE_ERROR , &node->flags); -clear_bit (HFS_BNODE_NEW , &node->flags); -wake_up (&node->lock_wq); +if (num !=HFSPLUS_TREE_HEAD ) {Why do we need to distinguish is it
HFSPLUS_TREE_HEADor not? I don't see any difference in node processing.(quoted diff) +1
-0+ clear_bit(HFS_BNODE_NEW, &node->flags);I think that we don't need to clear the
HFS_BNODE_NEW. Because, we need to analyzeHFS_BNODE_ERRORinhfs_bnode_put().(quoted diff) +1
-0+ wake_up(&node->lock_wq);
Quoted 2 lines
I assume that
wake_up()should be called anyway. Why have you removed this call forHFSPLUS_TREE_HEADcase?
Based on my analysis, hfs_bnode_find() does not support searching for HFSPLUS_TREE_HEAD.
Quoted 11 lines
fs/hfsplus/bnode.c +2
-0+ }hfs_bnode_put (node);return ERR_PTR (-EIO );@@ -694,6 +698,10 @@ void hfs_bnode_put(struct hfs_bnode *node)hfs_bnode_free (node);return ; } +if (test_bit (HFS_BNODE_NEW , &node->flags)) {
Quoted 1 line
I suggest to analyze
HFS_BNODE_ERRORhere.
Only the new head node will reach this point, no further analysis is required.
Quoted 16 lines
fs/hfsplus/bnode.c +6
-2+hfs_bnode_unhash (node); +hfs_bnode_free (node); + }@@ -598,14 +598,18 @@ struct hfs_bnode *hfs_bnode_find(struct hfs_btree *tree, u32 num)if (key_size >= entry_size || key_size &1 ) goto node_error; } -clear_bit (HFS_BNODE_NEW , &node->flags); -wake_up (&node->lock_wq); +if (num !=HFSPLUS_TREE_HEAD ) { +clear_bit (HFS_BNODE_NEW , &node->flags); +wake_up (&node->lock_wq);
Quoted 1 line
What the point in this code? Why have you change the logic here?
To support tree head.
Quoted 5 lines
fs/hfsplus/bnode.c +1
-0+ }return node;And, could you please add these new details into the commit message?
OK.
Edward
BR