lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 24 Jun 2022 23:37:26 +0900
From:   Namjae Jeon <linkinjeon@...nel.org>
To:     Anton Altaparmakov <anton@...era.com>
Cc:     Eric Biggers <ebiggers@...nel.org>,
        "xu.xin16@....com.cn" <xu.xin16@....com.cn>,
        "cgel.zte@...il.com" <cgel.zte@...il.com>,
        "linux-ntfs-dev@...ts.sourceforge.net" 
        <linux-ntfs-dev@...ts.sourceforge.net>,
        "stable@...r.kernel.org" <stable@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        "linux-fsdevel@...r.kernel.org" <linux-fsdevel@...r.kernel.org>,
        Zeal Robot <zealci@....com.cn>,
        "syzbot+6a5a7672f663cce8b156@...kaller.appspotmail.com" 
        <syzbot+6a5a7672f663cce8b156@...kaller.appspotmail.com>,
        Songyi Zhang <zhang.songyi@....com.cn>,
        Yang Yang <yang.yang29@....com.cn>,
        Jiang Xuexin <jiang.xuexin@....com.cn>,
        Zhang wenya <zhang.wenya1@....com.cn>
Subject: Re: [PATCH v2] fs/ntfs: fix BUG_ON of ntfs_read_block()

2022-06-24 21:19 GMT+09:00, Anton Altaparmakov <anton@...era.com>:
> Hi,
>
> On 24 Jun 2022, at 03:33, Namjae Jeon
> <linkinjeon@...nel.org<mailto:linkinjeon@...nel.org>> wrote:
>
> 2022-06-24 2:08 GMT+09:00, Eric Biggers
> <ebiggers@...nel.org<mailto:ebiggers@...nel.org>>:
> On Thu, Jun 23, 2022 at 09:49:56AM +0000,
> cgel.zte@...il.com<mailto:cgel.zte@...il.com> wrote:
> From: xu xin <xu.xin16@....com.cn<mailto:xu.xin16@....com.cn>>
>
> As the bug description at
> https://lore.kernel.org/lkml/20220623033635.973929-1-xu.xin16@zte.com.cn/
> 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@...r.kernel.org
> Reported-by: Zeal Robot <zealci@....com.cn>
> Reported-by: syzbot+6a5a7672f663cce8b156@...kaller.appspotmail.com
> Reviewed-by: Songyi Zhang <zhang.songyi@....com.cn>
> Reviewed-by: Yang Yang <yang.yang29@....com.cn>
> Reviewed-by: Jiang Xuexin<jiang.xuexin@....com.cn>
> Reviewed-by: Zhang wenya<zhang.wenya1@....com.cn>
> Signed-off-by: xu xin <xu.xin16@....com.cn>
> ---
>
> Change for v2:
> - Use ntfs_warning instead of WARN().
> - Add the tag Cc: stable@...r.kernel.org.
> ---
> 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@...kinjeon-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@...kinjeon-Z10PA-D8-Series:/mnt/test# truncate -s 0 foo
root@...kinjeon-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@...kinjeon-Z10PA-D8-Series:/mnt/test# cd ..
root@...kinjeon-Z10PA-D8-Series:/mnt# sudo umount /mnt/test
root@...kinjeon-Z10PA-D8-Series:/mnt# sudo mount -t ntfs /dev/sde2 /mnt/test/
root@...kinjeon-Z10PA-D8-Series:/mnt# cd /mnt/test/
root@...kinjeon-Z10PA-D8-Series:/mnt/test# cat foo
root@...kinjeon-Z10PA-D8-Series:/mnt/test# truncate -s 1048576 foo
root@...kinjeon-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@...kinjeon-Z10PA-D8-Series:/mnt/test# echo "hello world" > foo
root@...kinjeon-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@...tab.net>

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
>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ