From: Dongliang Mu Date: Tue, 22 Mar 2022 21:38:39 +0000 (-0700) Subject: ntfs: add sanity check on allocation size X-Git-Tag: v6.6.17~7963^2~224 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=714fbf2647b1a33d914edd695d4da92029c7e7c0;p=platform%2Fkernel%2Flinux-rpi.git ntfs: add sanity check on allocation size ntfs_read_inode_mount invokes ntfs_malloc_nofs with zero allocation size. It triggers one BUG in the __ntfs_malloc function. Fix this by adding sanity check on ni->attr_list_size. Link: https://lkml.kernel.org/r/20220120094914.47736-1-dzm91@hust.edu.cn Reported-by: syzbot+3c765c5248797356edaa@syzkaller.appspotmail.com Signed-off-by: Dongliang Mu Acked-by: Anton Altaparmakov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index 4474adb..517b71c7 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -1881,6 +1881,10 @@ int ntfs_read_inode_mount(struct inode *vi) } /* Now allocate memory for the attribute list. */ ni->attr_list_size = (u32)ntfs_attr_size(a); + if (!ni->attr_list_size) { + ntfs_error(sb, "Attr_list_size is zero"); + goto put_err_out; + } ni->attr_list = ntfs_malloc_nofs(ni->attr_list_size); if (!ni->attr_list) { ntfs_error(sb, "Not enough memory to allocate buffer "