]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
hfs/hfsplus: zero-initialize buffer in hfs_bnode_read
authorTristan Madani <tristan@talencesecurity.com>
Tue, 5 May 2026 11:12:59 +0000 (11:12 +0000)
committerViacheslav Dubeyko <slava@dubeyko.com>
Thu, 7 May 2026 22:07:20 +0000 (15:07 -0700)
hfs_bnode_read() can return early without writing to the output buffer
when is_bnode_offset_valid() fails or when check_and_correct_requested_
length() corrects the length to zero.  Callers such as hfs_bnode_read_
u16() and hfs_bnode_read_u8() pass stack-allocated buffers and use the
result unconditionally, leading to KMSAN uninit-value reports.

Rather than initializing at each individual call site, zero the buffer
at the start of hfs_bnode_read() before any validation checks.  This
ensures all callers in both hfs and hfsplus get a deterministic zero
value regardless of which early-return path is taken.

Reported-by: syzbot+217eb327242d08197efb@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=217eb327242d08197efb
Tested-by: syzbot+217eb327242d08197efb@syzkaller.appspotmail.com
Fixes: a431930c9bac ("hfs: fix slab-out-of-bounds in hfs_bnode_read()")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
Reviewed-by: Viacheslav Dubeyko <slava@dubeyko.com>
Signed-off-by: Viacheslav Dubeyko <slava@dubeyko.com>
Link: https://lore.kernel.org/r/20260505111300.3592757-3-tristmd@gmail.com
Signed-off-by: Viacheslav Dubeyko <slava@dubeyko.com>
fs/hfs/bnode.c
fs/hfsplus/bnode.c

index 3a8a3878d7b089b8707c4234b5e93b1498ba3d99..da8e5342c91cc2752f8d5a619a9ba8ebd7f3bbbc 100644 (file)
@@ -64,6 +64,8 @@ void hfs_bnode_read(struct hfs_bnode *node, void *buf, u32 off, u32 len)
        u32 bytes_read;
        u32 bytes_to_read;
 
+       memset(buf, 0, len);
+
        if (!is_bnode_offset_valid(node, off))
                return;
 
index a717fa008ddd1a4c5a6b38b52ae72b66020b1a41..d088fb7eb0dfa3e77a3bcaee3914bd3523aef3b5 100644 (file)
@@ -25,6 +25,8 @@ void hfs_bnode_read(struct hfs_bnode *node, void *buf, u32 off, u32 len)
        struct page **pagep;
        u32 l;
 
+       memset(buf, 0, len);
+
        if (!is_bnode_offset_valid(node, off))
                return;