Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6425779iog; Thu, 23 Jun 2022 19:46:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tgWdAhe+1XsBy2nIE0fq7zPqONEfV5lqdkyrnuWHUlkLFXwOVt9Z6Ztm9VO2j9+iIbDkkm X-Received: by 2002:a05:6402:3587:b0:435:b9a1:d5c5 with SMTP id y7-20020a056402358700b00435b9a1d5c5mr12606078edc.219.1656038797630; Thu, 23 Jun 2022 19:46:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656038797; cv=none; d=google.com; s=arc-20160816; b=K4KEZZGfLj7D7wGxrmJNC64mPJLOr6GirE1PMi9jHBBnVPMifqauD+UhP3CLEZwqVE A+NgwQtUC4UgS7SOHJH329f2jXZ2P5pq/DMv33PT3M8F1SVz9v3NTVz6NxQpTQpQAGy+ XihN6rrJzBib9pfgFtoIpL+2ym8auorRbqR5zCX9F+l0bxDKHY1yzmP2ET0MnzOZTOiF jVtM4wiU6pvES2rfvdn6bKpC3RYi8ESaGVKuKEHVQ+S83jkhogI8/W7RnkLUDrkrYCrq fTctqrCjqBbKBL7xOBw0uYQY3dgJPZYQbGMxohF2uBXrX+iIvDYUFHcXISIkd0ofZEBQ UXrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:references :in-reply-to:mime-version:dkim-signature; bh=pxcUM2HfROI/W9qrBs8nNqY0vSWAWcWxlOv2+v90onw=; b=yVdj/VTSVFcEYVOVMxLIrm0P+bSwyKNi0ib0zlxfrrl/U6Cq/Hm3Q2Dk/ls/7du1l5 0zyRYseV1Mx7JCIAHg+YbIi0ae/9rdeBe2rvcv9th63CvN6Uk2dQUUcY6Vq4z3thsSzC oJu0A+DK+BlMVH2X2er4njph/9pj5X4r0HbgF/xNgSyvts9TKfkuCTtYjdzUCzyzhGyf 8R8wo3W7QHEJVVTRtzpEj7f8/dh+D21vEPrHmWIJA1Zj0QElfID4mh7lkc3G4wG8fZUO vDTjjhf8uj479sHi3hRWwe9TUo4CFMJZiQR0VG5vtetybiD1V9sLi9QZ8PutYz8k+66p //dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QfGE9onB; 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 v4-20020a056402348400b00435ba2f2402si2027131edc.19.2022.06.23.19.46.12; Thu, 23 Jun 2022 19:46:37 -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=QfGE9onB; 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 S230264AbiFXCdi (ORCPT + 99 others); Thu, 23 Jun 2022 22:33:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229499AbiFXCdh (ORCPT ); Thu, 23 Jun 2022 22:33:37 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8BCB5000D; Thu, 23 Jun 2022 19:33:32 -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 ams.source.kernel.org (Postfix) with ESMTPS id 72066B825F6; Fri, 24 Jun 2022 02:33:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F4C3C385A2; Fri, 24 Jun 2022 02:33:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656038010; bh=a4iNX4jJ+gnqj1zIP5Wj5jnZb07NsrcpoyCEobpZ5Yo=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=QfGE9onBynAV5WJCdKW0ZlWgQ80YMC52LULQ97xE//WWZo6QwcmuJqlkH4tEuTc3M nsom2WtlMWAC/HeruQEgj/mPiVNpRzy3j47ZGbj4YsHROf4iPsefb8eFOVgJBGvXAN h+LTRBYRPcbR/g4J4ertVwXtmcrqpxsnGj811zg00Hjw/+GnfoCkvhAbEZmwRHhyKx 6iL1wm75mi0PBIipCwsZY6N/2NEFNL7APn/Ni5MZSg3iyBd7PHXho0UTNTc9vwanFK dz5N9yLow9VNSqhpYoog9UHX5P//5jPEe327D/gl3ApN3+5/5lXH8Easc1xJgsrzEq khPYJ9cP65xXg== Received: by mail-qv1-f54.google.com with SMTP id cu16so2776950qvb.7; Thu, 23 Jun 2022 19:33:30 -0700 (PDT) X-Gm-Message-State: AJIora+XIlYnuOa49SwcEBBHGj7GJwSMZ329/4UIG2NdLOnAwvyilrBG xWjx1b3k0LeI8MvQfRawLz9vQCvJe5KPGm+UtYc= X-Received: by 2002:ad4:5dc5:0:b0:470:93c8:e908 with SMTP id m5-20020ad45dc5000000b0047093c8e908mr1548301qvh.115.1656038009063; Thu, 23 Jun 2022 19:33:29 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:6214:2a86:0:0:0:0 with HTTP; Thu, 23 Jun 2022 19:33:28 -0700 (PDT) In-Reply-To: References: <20220623033635.973929-1-xu.xin16@zte.com.cn> <20220623094956.977053-1-xu.xin16@zte.com.cn> From: Namjae Jeon Date: Fri, 24 Jun 2022 11:33:28 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] fs/ntfs: fix BUG_ON of ntfs_read_block() To: Eric Biggers , xu.xin16@zte.com.cn Cc: cgel.zte@gmail.com, anton@tuxera.com, linux-ntfs-dev@lists.sourceforge.net, stable@vger.kernel.org, linux-kernel@vger.kernel.org, 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" 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 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 = 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. 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 >