Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp477190iog; Fri, 24 Jun 2022 07:41:39 -0700 (PDT) X-Google-Smtp-Source: AGRyM1upoesj7UmVsUxyFTUPho52OSqNAHF/dZTK2YEBy/WXF78mrpXMlmGf93d1dHHmLUUYTEXs X-Received: by 2002:a17:907:6e9f:b0:711:d2cb:63d8 with SMTP id sh31-20020a1709076e9f00b00711d2cb63d8mr13765797ejc.232.1656081699672; Fri, 24 Jun 2022 07:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656081699; cv=none; d=google.com; s=arc-20160816; b=Pb1boUcpHlMGBf8Axwl8Aes+OmqyAhAJAkdnkfPbHU0KIQWvIoQhrnZyAPZzspAQzM kSYMu34z3t3lu1sLPFwO+lN5G5J5o25SxqKQbaERSSzhWCE5wXmASXL2B0PcdvGy3iSU ly7BjIZP/2bWtfzf4txBUET2icpmImLC9i7YJu0nhXVyet2He0gYUNYyGtDqVkUbbWXR kNl8us4P0xEzCgtLgv8r3eD4d/g0Qsx2PKgYStx1zQKgZwWeTDLfUQbSrRo3FKeQHCuN k21zB9RQXJxH7Xg+FA2fYvw5Gjcm33XIWgz4ImJQ0CwVWPZ9i4AV3oWeaVqssQ9V4lwT tnFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature; bh=H4KHMUtwf1zNMRz8/ixThRzVygNtE2nEsO8vadnApUQ=; b=yKyhX3PFhQILzwhgpydSNraMjd6eBKAZNjr3iEca3PvNqDJ+kQGDZDfcg6jD5f6g9g ZdTTxXA0pEm10rCRL1uDYYqoT8tpJfddWTWTVenRu/KeVj+EKGoQXZeeniJha+taFVlA uxDw/eWiTXYQTEoXvZTLR4JpooSKbrKEX3yRo5J4Q/Sj9FJsoyht6hvclLXtVZKaCW8H cDvr1rx7rUEez1Gj8RtvYVK+E4yU+HY1MW+lmseejCscXjPWAyTK8Lyg1zDrEbVaHcXo ywmiTc6T/9zVbSwqMqhgnAbqfL6pRnbgbE9c93RQ8urkqcsUx5UwxOdZclR8Ik8yQxSN ff9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u1hxhEbO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dm17-20020a170907949100b00711d5bc0024si3008440ejc.170.2022.06.24.07.41.14; Fri, 24 Jun 2022 07:41:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u1hxhEbO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232861AbiFXOiN (ORCPT + 99 others); Fri, 24 Jun 2022 10:38:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232866AbiFXOht (ORCPT ); Fri, 24 Jun 2022 10:37:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0FB64FC7D; Fri, 24 Jun 2022 07:37:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4EF4262081; Fri, 24 Jun 2022 14:37:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0E64C385A5; Fri, 24 Jun 2022 14:37:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656081448; bh=CNBkSrLCaZGfawQUgSak+d02ko5fad5AVz/rJLSEs3U=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=u1hxhEbObejGel9t79BV/XwqoWz5imnrFY0iPN//c9MgONvFIMic89mLI2bdGFDcT FTMlW0y1eJFjPyNvQYvgHcz8+jAW+nf1zLoUP8x3afs6//woYRkXofQq2aaUabp2Nd ZPlIgDiNAc83gK3srvt+LEUSRvMbK1Lprsk/dr+uxFVok+GpQ0XZXSz6SuLNGMj0UP S48581ihx8iZeGuWVEvhHstN1tS2hIkTwAAB1IzViYHqD5R0EARapGuQh3pXChAyDb ED8nBsoY8f8x0X46cTzCxEuKv4qAxcyW+V+/WNk7LYhAdNfqofEyHuMrjmRr2K3y4O jGwRfq9yOTpbA== Received: by mail-wm1-f49.google.com with SMTP id o16-20020a05600c379000b003a02eaea815so2415202wmr.0; Fri, 24 Jun 2022 07:37:28 -0700 (PDT) X-Gm-Message-State: AJIora8xU/FbnJkE48PoeRZnFzkzXuqNIvlyu9lQdl1K1yD3ns4mmrlo 33o3j3MCvEJh8hSudskpnUPtpu5N26kB+AHLyhU= X-Received: by 2002:a05:600c:4e0c:b0:39c:519f:9f35 with SMTP id b12-20020a05600c4e0c00b0039c519f9f35mr4276665wmq.153.1656081446878; Fri, 24 Jun 2022 07:37:26 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:adf:f805:0:0:0:0:0 with HTTP; Fri, 24 Jun 2022 07:37:26 -0700 (PDT) In-Reply-To: <7FBC6FD2-5D60-4EB8-96D5-A6014D271950@tuxera.com> References: <20220623033635.973929-1-xu.xin16@zte.com.cn> <20220623094956.977053-1-xu.xin16@zte.com.cn> <7FBC6FD2-5D60-4EB8-96D5-A6014D271950@tuxera.com> From: Namjae Jeon Date: Fri, 24 Jun 2022 23:37:26 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] fs/ntfs: fix BUG_ON of ntfs_read_block() To: Anton Altaparmakov Cc: Eric Biggers , "xu.xin16@zte.com.cn" , "cgel.zte@gmail.com" , "linux-ntfs-dev@lists.sourceforge.net" , "stable@vger.kernel.org" , Linux Kernel Mailing List , "linux-fsdevel@vger.kernel.org" , Zeal Robot , "syzbot+6a5a7672f663cce8b156@syzkaller.appspotmail.com" , Songyi Zhang , Yang Yang , Jiang Xuexin , Zhang wenya Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2022-06-24 21:19 GMT+09:00, Anton Altaparmakov : > Hi, > > On 24 Jun 2022, at 03:33, Namjae Jeon > > wrote: > > 2022-06-24 2:08 GMT+09:00, Eric Biggers > >: > On Thu, Jun 23, 2022 at 09:49:56AM +0000, > cgel.zte@gmail.com wrote: > From: xu xin > > > 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@vger.kernel.org > Reported-by: Zeal Robot > Reported-by: syzbot+6a5a7672f663cce8b156@syzkaller.appspotmail.com > Reviewed-by: Songyi Zhang > Reviewed-by: Yang Yang > Reviewed-by: Jiang Xuexin > Reviewed-by: Zhang wenya > Signed-off-by: xu xin > --- > > Change for v2: > - Use ntfs_warning instead of WARN(). > - Add the tag Cc: stable@vger.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 =3D 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 empt= y > 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 nex= t > 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=EC=9B=94 24 23:01 . drwxr-xr-x 7 root root 4096 5=EC=9B=94 29 12:47 .. -rw------- 1 root root 6059409 9=EC=9B=94 22 2020 foo drwx------ 1 root root 0 6=EC=9B=94 24 22:30 'System Volume Informat= ion' 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=EC=9B=94 24 23:01 . drwxr-xr-x 7 root root 4096 5=EC=9B=94 29 12:47 .. -rw------- 1 root root 0 6=EC=9B=94 24 23:11 foo drwx------ 1 root root 0 6=EC=9B=94 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/tes= t/ 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=EC=9B=94 24 23:01 . drwxr-xr-x 7 root root 4096 5=EC=9B=94 29 12:47 .. -rw------- 1 root root 1048576 6=EC=9B=94 24 23:12 foo drwx------ 1 root root 0 6=EC=9B=94 24 22:30 'System Volume Informat= ion' 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 th= e > $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 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/f= s/ntfs/runlist.c?h=3Dv5.19-rc3&id=3D2b0ada2b8e086c267dd116a39ad41ff0a717b66= 5 > > 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 =3D 0; > /* Allocate first page and set current runlist size to one page. */ > > > - Eric > >