Unverified Commit a8a3ca23 authored by Bartlomiej Kubik's avatar Bartlomiej Kubik Committed by Konstantin Komarov
Browse files

fs/ntfs3: Initialize allocated memory before use



KMSAN reports: Multiple uninitialized values detected:

- KMSAN: uninit-value in ntfs_read_hdr (3)
- KMSAN: uninit-value in bcmp (3)

Memory is allocated by __getname(), which is a wrapper for
kmem_cache_alloc(). This memory is used before being properly
cleared. Change kmem_cache_alloc() to kmem_cache_zalloc() to
properly allocate and clear memory before use.

Fixes: 82cae269 ("fs/ntfs3: Add initialization of super block")
Fixes: 78ab59fe ("fs/ntfs3: Rework file operations")
Tested-by: default avatar <syzbot+332bd4e9d148f11a87dc@syzkaller.appspotmail.com>
Reported-by: default avatar <syzbot+332bd4e9d148f11a87dc@syzkaller.appspotmail.com>
Closes: https://syzkaller.appspot.com/bug?extid=332bd4e9d148f11a87dc



Fixes: 82cae269 ("fs/ntfs3: Add initialization of super block")
Fixes: 78ab59fe ("fs/ntfs3: Rework file operations")
Tested-by: default avatar <syzbot+0399100e525dd9696764@syzkaller.appspotmail.com>
Reported-by: default avatar <syzbot+0399100e525dd9696764@syzkaller.appspotmail.com>
Closes: https://syzkaller.appspot.com/bug?extid=0399100e525dd9696764



Reviewed-by: default avatarKhalid Aziz <khalid@kernel.org>
Signed-off-by: default avatarBartlomiej Kubik <kubik.bartlomiej@gmail.com>
Signed-off-by: default avatarKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
parent f35590ee
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -1281,7 +1281,7 @@ int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
		fa |= FILE_ATTRIBUTE_READONLY;

	/* Allocate PATH_MAX bytes. */
	new_de = __getname();
	new_de = kmem_cache_zalloc(names_cachep, GFP_KERNEL);
	if (!new_de) {
		err = -ENOMEM;
		goto out1;
@@ -1723,10 +1723,9 @@ int ntfs_link_inode(struct inode *inode, struct dentry *dentry)
	struct NTFS_DE *de;

	/* Allocate PATH_MAX bytes. */
	de = __getname();
	de = kmem_cache_zalloc(names_cachep, GFP_KERNEL);
	if (!de)
		return -ENOMEM;
	memset(de, 0, PATH_MAX);

	/* Mark rw ntfs as dirty. It will be cleared at umount. */
	ntfs_set_state(sbi, NTFS_DIRTY_DIRTY);
@@ -1762,7 +1761,7 @@ int ntfs_unlink_inode(struct inode *dir, const struct dentry *dentry)
		return -EINVAL;

	/* Allocate PATH_MAX bytes. */
	de = __getname();
	de = kmem_cache_zalloc(names_cachep, GFP_KERNEL);
	if (!de)
		return -ENOMEM;