Forwarded: [PATCH] hfsplus: initialize subfolders field when HAS_FOLDER_COUNT is
From: syzbot
Date: Fri Apr 17 2026 - 06:16:21 EST
For archival purposes, forwarding an incoming command email to
linux-kernel@xxxxxxxxxxxxxxx, syzkaller-bugs@xxxxxxxxxxxxxxxx.
***
Subject: [PATCH] hfsplus: initialize subfolders field when HAS_FOLDER_COUNT is
Author: tristmd@xxxxxxxxx
From: Tristan Madani <tristan@xxxxxxxxxxxxxxxxxxx>
#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
not set
When reading a folder inode from disk, the subfolders field is only
initialized if the on-disk entry has the HFSPLUS_HAS_FOLDER_COUNT flag
set:
if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
HFSPLUS_I(inode)->subfolders =
be32_to_cpu(folder->subfolders);
}
If the flag is not set, subfolders is left with stale data from the
slab allocator. The slab constructor (hfsplus_init_once) does set
subfolders = 0, but slab constructors only run on first allocation from
a fresh page -- they do not run on slab object reuse.
This uninitialized field is later read by hfsplus_subfolders_inc() and
hfsplus_subfolders_dec() during directory operations, which KMSAN flags
as a use of uninitialized memory.
Fix this by explicitly setting subfolders to 0 when the folder count
flag is not present on the on-disk entry.
Reported-by: syzbot+93f4402297a457fc6895@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=93f4402297a457fc6895
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Tristan Madani <tristan@xxxxxxxxxxxxxxxxxxx>
---
fs/hfsplus/inode.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
index XXXXXXX..XXXXXXX 100644
--- a/fs/hfsplus/inode.c
+++ b/fs/hfsplus/inode.c
@@ -530,6 +530,8 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
HFSPLUS_I(inode)->subfolders =
be32_to_cpu(folder->subfolders);
+ } else {
+ HFSPLUS_I(inode)->subfolders = 0;
}
inode->i_op = &hfsplus_dir_inode_operations;
inode->i_fop = &hfsplus_dir_operations;
--
2.43.0