[PATCH] fs/ntfs3: fix uninitialized memory in ni_create_attr_list()

Swaraj Gaikwad posted 1 patch 4 months ago
fs/ntfs3/frecord.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] fs/ntfs3: fix uninitialized memory in ni_create_attr_list()
Posted by Swaraj Gaikwad 4 months ago
KMSAN reported an "uninit-value" warning in attr_set_size(), which
occurs when the NTFS attribute list buffer contains uninitialized
trailing bytes.

In ni_create_attr_list(q), kmalloc() is used to allocate a buffer of
size al_aligned(rs). However, the amount of data actually written into
this buffer can be smaller than the allocated size, leaving the
remaining bytes uninitialized. If those bytes are later accessed,
KMSAN reports a read of uninitialized memory.

Replace kmalloc() with kzalloc() to ensure the entire buffer is
zero-initialized, preventing future uninitialized memory accesses.

This issue was reproduced and verified using the syzkaller-provided
reproducer. The patch was tested by:
  - Building the kernel to ensure the change does not affect the build
    process.
  - Running the provided repro to confirm that the
    uninit-value warning no longer appears.

Based on commit: 9b0d551bcc05
Reported-by: syzbot+83c9dd5c0dcf6184fdbf@syzkaller.appspotmail.com
Tested-by: Swaraj Gaikwad <swarajgaikwad1925@gmail.com>

Signed-off-by: Swaraj Gaikwad <swarajgaikwad1925@gmail.com>
---
 fs/ntfs3/frecord.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c
index 8f9fe1d7a690..4fe8da7fc034 100644
--- a/fs/ntfs3/frecord.c
+++ b/fs/ntfs3/frecord.c
@@ -767,7 +767,7 @@ int ni_create_attr_list(struct ntfs_inode *ni)
 	 * Skip estimating exact memory requirement.
 	 * Looks like one record_size is always enough.
 	 */
-	le = kmalloc(al_aligned(rs), GFP_NOFS);
+	le = kzalloc(al_aligned(rs), GFP_NOFS);
 	if (!le)
 		return -ENOMEM;
 
-- 
2.51.0