public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] hfsplus: fix memory leak on mount failure
  2025-12-05  5:38 syzbot
@ 2025-12-06  0:09 Swaraj Gaikwad
  2025-12-05 19:06 ` [syzbot] [hfs?] memory leak in hfsplus_init_fs_context syzbot
  -1 siblings, 1 reply; 6+ messages in thread
From: Swaraj Gaikwad @ 2025-12-06  0:09 UTC (permalink / raw)
  To: syzbot+99f6ed51479b86ac4c41
  Cc: frank.li, glaubitz, linux-fsdevel, linux-kernel, slava, skhan,
	david.hunter.linux, syzkaller-bugs, Swaraj Gaikwad

syzbot reported a memory leak in the hfsplus mount path when the mount
fails, which occurs because the fs_context API moves ownership of
fc->s_fs_info to sb->s_fs_info early in sget_fc().

When filesystems are mounted using the new API, the VFS (specifically
sget_fc) transfers the ownership of the context's s_fs_info (the 'sbi'
struct) to the superblock (sb->s_fs_info) and clears the context
pointer.

If the mount fails after this transfer the VFS calls
deactivate_locked_super, which invokes the filesystem's kill_sb
callback. Previously, hfsplus used the generic kill_block_super, which
does not free sb->s_fs_info, resulting in the 'sbi' structure and its
loaded NLS tables being leaked.

Fix this by implementing a filesystem-specific ->kill_sb() that frees
sb->s_fs_info and its NLS resources before calling kill_block_super().
Also remove the early kfree(sbi) from hfsplus_fill_super()’s error path,
because the superblock unconditionally owns s_fs_info when using the
fs_context API.

Testing:
This fix was verified by building the kernel with the .config provided
by the syzkaller reporter and running the reproducer. The reproducer
now runs successfully without triggering any memory leaks or kernel errors.

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git e69c7c175115

Reported-by: syzbot+99f6ed51479b86ac4c41@syzkaller.appspotmail.com
Signed-off-by: Swaraj Gaikwad <swarajgaikwad1925@gmail.com>
---
 fs/hfsplus/super.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
index 16bc4abc67e0..fa7420d08da1 100644
--- a/fs/hfsplus/super.c
+++ b/fs/hfsplus/super.c
@@ -629,7 +629,6 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
 out_unload_nls:
 	unload_nls(sbi->nls);
 	unload_nls(nls);
-	kfree(sbi);
 	return err;
 }

@@ -688,10 +687,23 @@ static int hfsplus_init_fs_context(struct fs_context *fc)
 	return 0;
 }

+static void hfsplus_kill_sb(struct super_block *sb)
+{
+    struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
+
+    if (sbi) {
+        unload_nls(sbi->nls);
+        kfree(sbi);
+        sb->s_fs_info = NULL;
+    }
+
+    kill_block_super(sb);
+}
+
 static struct file_system_type hfsplus_fs_type = {
 	.owner		= THIS_MODULE,
 	.name		= "hfsplus",
-	.kill_sb	= kill_block_super,
+	.kill_sb	= hfsplus_kill_sb,
 	.fs_flags	= FS_REQUIRES_DEV,
 	.init_fs_context = hfsplus_init_fs_context,
 };

base-commit: 6bda50f4333fa61c07f04f790fdd4e2c9f4ca610
--
2.52.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread
[parent not found: <20251205144843.1757055-1-kartikey406@gmail.com>]
[parent not found: <20251205124309.1754872-1-kartikey406@gmail.com>]
[parent not found: <20251205062813.1398599-1-kartikey406@gmail.com>]
* [syzbot] [hfs?] memory leak in hfsplus_init_fs_context
@ 2025-12-05  5:38 syzbot
  0 siblings, 0 replies; 6+ messages in thread
From: syzbot @ 2025-12-05  5:38 UTC (permalink / raw)
  To: frank.li, glaubitz, linux-fsdevel, linux-kernel, slava,
	syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    e69c7c175115 Merge tag 'timers_urgent_for_v6.18_rc8' of gi..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=116ffcb4580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=f30cc590c4f6da44
dashboard link: https://syzkaller.appspot.com/bug?extid=99f6ed51479b86ac4c41
compiler:       gcc (Debian 12.2.0-14+deb12u1) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=10eef912580000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=1534c192580000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/e1758d9b5b79/disk-e69c7c17.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/772ec0d0a545/vmlinux-e69c7c17.xz
kernel image: https://storage.googleapis.com/syzbot-assets/d905337ef02b/bzImage-e69c7c17.xz
mounted in repro: https://storage.googleapis.com/syzbot-assets/65bc76439748/mount_4.gz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+99f6ed51479b86ac4c41@syzkaller.appspotmail.com

BUG: memory leak
unreferenced object 0xffff8881287f8a00 (size 512):
  comm "syz.0.17", pid 6072, jiffies 4294944858
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace (crc aaf4239b):
    kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
    slab_post_alloc_hook mm/slub.c:4983 [inline]
    slab_alloc_node mm/slub.c:5288 [inline]
    __kmalloc_cache_noprof+0x3a6/0x5b0 mm/slub.c:5766
    kmalloc_noprof include/linux/slab.h:957 [inline]
    kzalloc_noprof include/linux/slab.h:1094 [inline]
    hfsplus_init_fs_context+0x26/0x90 fs/hfsplus/super.c:678
    alloc_fs_context+0x214/0x430 fs/fs_context.c:315
    do_new_mount fs/namespace.c:3698 [inline]
    path_mount+0x93c/0x12e0 fs/namespace.c:4028
    do_mount fs/namespace.c:4041 [inline]
    __do_sys_mount fs/namespace.c:4229 [inline]
    __se_sys_mount fs/namespace.c:4206 [inline]
    __x64_sys_mount+0x1a2/0x1e0 fs/namespace.c:4206
    do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
    do_syscall_64+0xa4/0xfa0 arch/x86/entry/syscall_64.c:94
    entry_SYSCALL_64_after_hwframe+0x77/0x7f

BUG: memory leak
unreferenced object 0xffff8881287f9a00 (size 512):
  comm "syz.0.18", pid 6078, jiffies 4294944862
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace (crc aaf4239b):
    kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
    slab_post_alloc_hook mm/slub.c:4983 [inline]
    slab_alloc_node mm/slub.c:5288 [inline]
    __kmalloc_cache_noprof+0x3a6/0x5b0 mm/slub.c:5766
    kmalloc_noprof include/linux/slab.h:957 [inline]
    kzalloc_noprof include/linux/slab.h:1094 [inline]
    hfsplus_init_fs_context+0x26/0x90 fs/hfsplus/super.c:678
    alloc_fs_context+0x214/0x430 fs/fs_context.c:315
    do_new_mount fs/namespace.c:3698 [inline]
    path_mount+0x93c/0x12e0 fs/namespace.c:4028
    do_mount fs/namespace.c:4041 [inline]
    __do_sys_mount fs/namespace.c:4229 [inline]
    __se_sys_mount fs/namespace.c:4206 [inline]
    __x64_sys_mount+0x1a2/0x1e0 fs/namespace.c:4206
    do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
    do_syscall_64+0xa4/0xfa0 arch/x86/entry/syscall_64.c:94
    entry_SYSCALL_64_after_hwframe+0x77/0x7f

BUG: memory leak
unreferenced object 0xffff8881287f9c00 (size 512):
  comm "syz.0.19", pid 6079, jiffies 4294944864
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace (crc aaf4239b):
    kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
    slab_post_alloc_hook mm/slub.c:4983 [inline]
    slab_alloc_node mm/slub.c:5288 [inline]
    __kmalloc_cache_noprof+0x3a6/0x5b0 mm/slub.c:5766
    kmalloc_noprof include/linux/slab.h:957 [inline]
    kzalloc_noprof include/linux/slab.h:1094 [inline]
    hfsplus_init_fs_context+0x26/0x90 fs/hfsplus/super.c:678
    alloc_fs_context+0x214/0x430 fs/fs_context.c:315
    do_new_mount fs/namespace.c:3698 [inline]
    path_mount+0x93c/0x12e0 fs/namespace.c:4028
    do_mount fs/namespace.c:4041 [inline]
    __do_sys_mount fs/namespace.c:4229 [inline]
    __se_sys_mount fs/namespace.c:4206 [inline]
    __x64_sys_mount+0x1a2/0x1e0 fs/namespace.c:4206
    do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
    do_syscall_64+0xa4/0xfa0 arch/x86/entry/syscall_64.c:94
    entry_SYSCALL_64_after_hwframe+0x77/0x7f

connection 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 syzkaller@googlegroups.com.

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-12-05 19:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20251205075055.1400638-1-kartikey406@gmail.com>
2025-12-05  8:41 ` [syzbot] [hfs?] memory leak in hfsplus_init_fs_context syzbot
2025-12-06  0:09 [PATCH v1] hfsplus: fix memory leak on mount failure Swaraj Gaikwad
2025-12-05 19:06 ` [syzbot] [hfs?] memory leak in hfsplus_init_fs_context syzbot
     [not found] <20251205144843.1757055-1-kartikey406@gmail.com>
2025-12-05 15:04 ` syzbot
     [not found] <20251205124309.1754872-1-kartikey406@gmail.com>
2025-12-05 13:43 ` syzbot
     [not found] <20251205062813.1398599-1-kartikey406@gmail.com>
2025-12-05  7:44 ` syzbot
  -- strict thread matches above, loose matches on Subject: below --
2025-12-05  5:38 syzbot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox