public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [PATCH linux-next] fs/ntfs3: Initialize allocated memory before use
@ 2025-11-05 21:18 Bartlomiej Kubik
  2025-11-06 18:33 ` Khalid Aziz
  2025-11-20  9:07 ` Konstantin Komarov
  0 siblings, 2 replies; 3+ messages in thread
From: Bartlomiej Kubik @ 2025-11-05 21:18 UTC (permalink / raw)
  To: almaz.alexandrovich
  Cc: ntfs3, linux-kernel, david.hunter.linux, skhan, khalid,
	linux-kernel-mentees, Bartlomiej Kubik,
	syzbot+332bd4e9d148f11a87dc, syzbot+0399100e525dd9696764

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: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")
Fixes: 78ab59fee07f ("fs/ntfs3: Rework file operations")
Tested-by: syzbot+332bd4e9d148f11a87dc@syzkaller.appspotmail.com
Reported-by: syzbot+332bd4e9d148f11a87dc@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=332bd4e9d148f11a87dc

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

Signed-off-by: Bartlomiej Kubik <kubik.bartlomiej@gmail.com>
---
 fs/ntfs3/inode.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c
index ab61388f819c..13720baf079d 100644
--- a/fs/ntfs3/inode.c
+++ b/fs/ntfs3/inode.c
@@ -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;

--
2.39.5


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

* Re: [PATCH linux-next] fs/ntfs3: Initialize allocated memory before use
  2025-11-05 21:18 [PATCH linux-next] fs/ntfs3: Initialize allocated memory before use Bartlomiej Kubik
@ 2025-11-06 18:33 ` Khalid Aziz
  2025-11-20  9:07 ` Konstantin Komarov
  1 sibling, 0 replies; 3+ messages in thread
From: Khalid Aziz @ 2025-11-06 18:33 UTC (permalink / raw)
  To: Bartlomiej Kubik, almaz.alexandrovich
  Cc: ntfs3, linux-kernel, david.hunter.linux, skhan,
	linux-kernel-mentees, syzbot+332bd4e9d148f11a87dc,
	syzbot+0399100e525dd9696764

On 11/5/25 2:18 PM, Bartlomiej Kubik wrote:
> 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: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")
> Fixes: 78ab59fee07f ("fs/ntfs3: Rework file operations")
> Tested-by: syzbot+332bd4e9d148f11a87dc@syzkaller.appspotmail.com
> Reported-by: syzbot+332bd4e9d148f11a87dc@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=332bd4e9d148f11a87dc
> 
> Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")
> Fixes: 78ab59fee07f ("fs/ntfs3: Rework file operations")
> Tested-by: syzbot+0399100e525dd9696764@syzkaller.appspotmail.com
> Reported-by: syzbot+0399100e525dd9696764@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=0399100e525dd9696764
> 
> Signed-off-by: Bartlomiej Kubik <kubik.bartlomiej@gmail.com>
> ---

Looks good to me.

Reviewed-by: Khalid Aziz <khalid@kernel.org>

--
Khalid

>   fs/ntfs3/inode.c | 7 +++----
>   1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c
> index ab61388f819c..13720baf079d 100644
> --- a/fs/ntfs3/inode.c
> +++ b/fs/ntfs3/inode.c
> @@ -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;
> 
> --
> 2.39.5
> 


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

* Re: [PATCH linux-next] fs/ntfs3: Initialize allocated memory before use
  2025-11-05 21:18 [PATCH linux-next] fs/ntfs3: Initialize allocated memory before use Bartlomiej Kubik
  2025-11-06 18:33 ` Khalid Aziz
@ 2025-11-20  9:07 ` Konstantin Komarov
  1 sibling, 0 replies; 3+ messages in thread
From: Konstantin Komarov @ 2025-11-20  9:07 UTC (permalink / raw)
  To: Bartlomiej Kubik
  Cc: ntfs3, linux-kernel, david.hunter.linux, skhan, khalid,
	linux-kernel-mentees, syzbot+332bd4e9d148f11a87dc,
	syzbot+0399100e525dd9696764

On 11/5/25 22:18, Bartlomiej Kubik wrote:

> 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: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")
> Fixes: 78ab59fee07f ("fs/ntfs3: Rework file operations")
> Tested-by: syzbot+332bd4e9d148f11a87dc@syzkaller.appspotmail.com
> Reported-by: syzbot+332bd4e9d148f11a87dc@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=332bd4e9d148f11a87dc
>
> Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")
> Fixes: 78ab59fee07f ("fs/ntfs3: Rework file operations")
> Tested-by: syzbot+0399100e525dd9696764@syzkaller.appspotmail.com
> Reported-by: syzbot+0399100e525dd9696764@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=0399100e525dd9696764
>
> Signed-off-by: Bartlomiej Kubik <kubik.bartlomiej@gmail.com>
> ---
>   fs/ntfs3/inode.c | 7 +++----
>   1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c
> index ab61388f819c..13720baf079d 100644
> --- a/fs/ntfs3/inode.c
> +++ b/fs/ntfs3/inode.c
> @@ -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;
>
> --
> 2.39.5

The patch has been applied. Thanks for your work.

Regards,
Konstantin


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

end of thread, other threads:[~2025-11-20  9:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-05 21:18 [PATCH linux-next] fs/ntfs3: Initialize allocated memory before use Bartlomiej Kubik
2025-11-06 18:33 ` Khalid Aziz
2025-11-20  9:07 ` Konstantin Komarov

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