Re: [PATCH v2] fs/ntfs: fix BUG_ON of ntfs_read_block()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2022-06-24 21:19 GMT+09:00, Anton Altaparmakov <anton@xxxxxxxxxx>:
> Hi,
>
> On 24 Jun 2022, at 03:33, Namjae Jeon
> <linkinjeon@xxxxxxxxxx<mailto:linkinjeon@xxxxxxxxxx>> wrote:
>
> 2022-06-24 2:08 GMT+09:00, Eric Biggers
> <ebiggers@xxxxxxxxxx<mailto:ebiggers@xxxxxxxxxx>>:
> On Thu, Jun 23, 2022 at 09:49:56AM +0000,
> cgel.zte@xxxxxxxxx<mailto:cgel.zte@xxxxxxxxx> wrote:
> From: xu xin <xu.xin16@xxxxxxxxxx<mailto:xu.xin16@xxxxxxxxxx>>
>
> As the bug description at
> https://lore.kernel.org/lkml/20220623033635.973929-1-xu.xin16@xxxxxxxxxx/
> attckers can use this bug to crash the system.
>
> So to avoid panic, remove the BUG_ON, and use ntfs_warning to output a
> warning to the syslog and return instead until someone really solve
> the problem.
>
> Cc: stable@xxxxxxxxxxxxxxx
> Reported-by: Zeal Robot <zealci@xxxxxxxxxx>
> Reported-by: syzbot+6a5a7672f663cce8b156@xxxxxxxxxxxxxxxxxxxxxxxxx
> Reviewed-by: Songyi Zhang <zhang.songyi@xxxxxxxxxx>
> Reviewed-by: Yang Yang <yang.yang29@xxxxxxxxxx>
> Reviewed-by: Jiang Xuexin<jiang.xuexin@xxxxxxxxxx>
> Reviewed-by: Zhang wenya<zhang.wenya1@xxxxxxxxxx>
> Signed-off-by: xu xin <xu.xin16@xxxxxxxxxx>
> ---
>
> Change for v2:
> - Use ntfs_warning instead of WARN().
> - Add the tag Cc: stable@xxxxxxxxxxxxxxx.
> ---
> fs/ntfs/aops.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/fs/ntfs/aops.c b/fs/ntfs/aops.c
> index 5f4fb6ca6f2e..84d68efb4ace 100644
> --- a/fs/ntfs/aops.c
> +++ b/fs/ntfs/aops.c
> @@ -183,7 +183,12 @@ static int ntfs_read_block(struct page *page)
> vol = ni->vol;
>
> /* $MFT/$DATA must have its complete runlist in memory at all times. */
> - BUG_ON(!ni->runlist.rl && !ni->mft_no && !NInoAttr(ni));
> + if (unlikely(!ni->runlist.rl && !ni->mft_no && !NInoAttr(ni))) {
> + ntfs_warning(vi->i_sb, "Error because ni->runlist.rl, ni->mft_no, "
> + "and NInoAttr(ni) is null.");
> + unlock_page(page);
> + return -EINVAL;
> + }
>
> A better warning message that doesn't rely on implementation details
> (struct
> field and macro names) would be "Runlist of $MFT/$DATA is not cached".
> Also,
> why does this situation happen in the first place? Is there a way to
> prevent
> this situation in the first place?
>
> ntfs_mapping_pairs_decompress() should return error pointer instead of
> NULL.
>
> Callers is checking error value using IS_ERR(). and the mapping pairs
> array of @MFT entry is empty, I think it's corrupted, it should cause
> mount failure.
>
> NAK
>
> Sorry but this patch is incorrect.  It is perfectly valid to have an empty
> non-resident attribute.  E.g. if you truncate a file to zero size this is
> exactly what you will get on-disk and when you then unmount and mount next
> time and try to access that file with your patch you will now get an -EIO
> error trying to access the file and you will not be able to write to the
> file nor truncate it as you will keep getting the i/o error.
Sorry, I can't reproduce the issue you described?

root@linkinjeon-Z10PA-D8-Series:/mnt/test# ls -al
total 5928
drwx------ 1 root root    4096  6월 24 23:01  .
drwxr-xr-x 7 root root    4096  5월 29 12:47  ..
-rw------- 1 root root 6059409  9월 22  2020  foo
drwx------ 1 root root       0  6월 24 22:30 'System Volume Information'
root@linkinjeon-Z10PA-D8-Series:/mnt/test# truncate -s 0 foo
root@linkinjeon-Z10PA-D8-Series:/mnt/test# ls -al
total 8
drwx------ 1 root root 4096  6월 24 23:01  .
drwxr-xr-x 7 root root 4096  5월 29 12:47  ..
-rw------- 1 root root    0  6월 24 23:11  foo
drwx------ 1 root root    0  6월 24 22:30 'System Volume Information'
root@linkinjeon-Z10PA-D8-Series:/mnt/test# cd ..
root@linkinjeon-Z10PA-D8-Series:/mnt# sudo umount /mnt/test
root@linkinjeon-Z10PA-D8-Series:/mnt# sudo mount -t ntfs /dev/sde2 /mnt/test/
root@linkinjeon-Z10PA-D8-Series:/mnt# cd /mnt/test/
root@linkinjeon-Z10PA-D8-Series:/mnt/test# cat foo
root@linkinjeon-Z10PA-D8-Series:/mnt/test# truncate -s 1048576 foo
root@linkinjeon-Z10PA-D8-Series:/mnt/test# ls -al
total 1032
drwx------ 1 root root    4096  6월 24 23:01  .
drwxr-xr-x 7 root root    4096  5월 29 12:47  ..
-rw------- 1 root root 1048576  6월 24 23:12  foo
drwx------ 1 root root       0  6월 24 22:30 'System Volume Information'
root@linkinjeon-Z10PA-D8-Series:/mnt/test# echo "hello world" > foo
root@linkinjeon-Z10PA-D8-Series:/mnt/test# cat foo
hello world

>
> The correct solution is to use IS_ERR_OR_NULL() in places where an empty
> attribute is not acceptable.  Such a case is for example when mounting the
> $MFT::$DATA::unnamed attribute cannot be empty which should then be
> addressed inside in fs/ntfs/inode.c::ntfs_read_inode_mount().  There may be
> more call sites to ntfs_mapping_pairs_decompress() which require similar
> treatment.  Need to go through the code to see...
I think that it is needed everywhere that calls it. Am I missing something ?

I can not understand why the below code is needed in
ntfs_mapping_pairs_decompress().

/* If the mapping pairs array is valid but empty, nothing to do. */
        if (!vcn && !*buf) {
                return old_rl;
        }

There is no description in patch. and this code is not in
ntfs_mapping_pairs_decompress() in ntfs-3g. Is there any case the
caller get NULL runlist pointer from ntfs_mapping_pairs_decompress()
in current ntfs code?

NTFS: Fix handling of valid but empty mapping pairs array in
      fs/ntfs/runlist.c::ntfs_mapping_pairs_decompress().

Signed-off-by: Anton Altaparmakov <aia21@xxxxxxxxxx>

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/fs/ntfs/runlist.c?h=v5.19-rc3&id=2b0ada2b8e086c267dd116a39ad41ff0a717b665
>
> Best regards,
>
> Anton
>
>
> I haven't checked if this patch fix the problem. Xu, Can you check it ?
>
> diff --git a/fs/ntfs/runlist.c b/fs/ntfs/runlist.c
> index 97932fb5179c..31263fe0772f 100644
> --- a/fs/ntfs/runlist.c
> +++ b/fs/ntfs/runlist.c
> @@ -766,8 +766,11 @@ runlist_element
> *ntfs_mapping_pairs_decompress(const ntfs_volume *vol,
> return ERR_PTR(-EIO);
> }
> /* If the mapping pairs array is valid but empty, nothing to do. */
> - if (!vcn && !*buf)
> + if (!vcn && !*buf) {
> + if (!old_rl)
> + return ERR_PTR(-EIO);
> return old_rl;
> + }
> /* Current position in runlist array. */
> rlpos = 0;
> /* Allocate first page and set current runlist size to one page. */
>
>
> - Eric
>
>




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux