Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp478717iog; Wed, 29 Jun 2022 04:18:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ttdaNULAVeau86JROr15Y+pSS3cQLW7OEmNyIsSf8NYWaaWv4GMA72Y4tpi3IIhUwbZwNL X-Received: by 2002:aa7:842b:0:b0:525:1e94:4de1 with SMTP id q11-20020aa7842b000000b005251e944de1mr9808603pfn.36.1656501506782; Wed, 29 Jun 2022 04:18:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656501506; cv=none; d=google.com; s=arc-20160816; b=khCcTAnFhYOMtBNDk87TdcWBKNVXUp7C+bfLQLpQLfqlcH4G1cix4nPP6ohYJm9xDA +YA80qR91JJCLaBNd6jjGPoSd5H8LOdcVWj1mrFNDGjPYlFO3MhVsttTTjvVeNR5Jslz CxXKvNN8pEW5+h72AG68WrAktV5WdGIpELV7Kt/pwNdoNCPiP4twlii3stNZYrZxN2qf 9EMGc6ieCTx61EvJhfPOWtZREKjIhb9JS0fijLwhd5lj58Nj297s4kWs5Hj7m7l02l9M CiGBdZY7u+Ldt2IsJeAWi7qZ0PCS/oAdhYy+k1yAh7zW+KL2TLwfIATlMJeeARwcKYCU NDig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=2bPJa5ptMLJreejutAQ8opgsYq9O+ug9p2nrEF6Kv1E=; b=hZKVRfUPsMQ1Scr7KTXXqsLdE3tKHuLIonUbllVTw945Z1RFShdUAE/XMTUEcT+ss2 qLHHrlkrRFCQ/Y8daofP7ECgt/83lAp8auVt1VHjc+N523LnfsIYKqn8ZC/grD0/trqu Kodc8lRF+r7fqXqmJ6hN+MmTssvHPCsJo6acZNLZsEy9UqJ6Y+Sl1h5YiZkbW4Wn6rsy QUiCMQZoNgg+QytdeWzqwH2QFnnzW147jzV+JveH3jFpujHV++QQM/ydu4ry7ghvTn80 IB2HCCKOtv7SJMIaHI8Zhu9BWqhADx9lgqe2wFJ8w6P0GHo6qugc635oGgsjDZbdT3gu HyNQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t1-20020a637801000000b003fde8b80069si1872040pgc.372.2022.06.29.04.18.02; Wed, 29 Jun 2022 04:18:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231489AbiF2LOK (ORCPT + 99 others); Wed, 29 Jun 2022 07:14:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231640AbiF2LOJ (ORCPT ); Wed, 29 Jun 2022 07:14:09 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8C7C3B56D for ; Wed, 29 Jun 2022 04:14:08 -0700 (PDT) Received: from canpemm500005.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LXzK84G0QzTgDh; Wed, 29 Jun 2022 19:10:36 +0800 (CST) Received: from huawei.com (10.175.127.227) by canpemm500005.china.huawei.com (7.192.104.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 29 Jun 2022 19:14:06 +0800 From: Zhang Yi To: CC: , , , , Subject: [PATCH v3 2/2] ext4: check and assert if marking an no_delete evicting inode dirty Date: Wed, 29 Jun 2022 19:26:47 +0800 Message-ID: <20220629112647.4141034-2-yi.zhang@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220629112647.4141034-1-yi.zhang@huawei.com> References: <20220629112647.4141034-1-yi.zhang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500005.china.huawei.com (7.192.104.229) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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-ext4@vger.kernel.org In ext4_evict_inode(), if we evicting an inode in the 'no_delete' path, it cannot be raced by another mark_inode_dirty(). If it happens, someone else may accidentally dirty it without holding inode refcount and probably cause use-after-free issues in the writeback procedure. It's indiscoverable and hard to debug, so add an WARN_ON_ONCE() to check and detect this issue in advance. Suggested-by: Jan Kara Signed-off-by: Zhang Yi --- v2->v3: - Switch to use WARN_ON_ONCE instead of ASSERT. fs/ext4/inode.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 702cc208689a..902393373152 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -333,6 +333,12 @@ void ext4_evict_inode(struct inode *inode) ext4_xattr_inode_array_free(ea_inode_array); return; no_delete: + /* + * Check out some where else accidentally dirty the evicting inode, + * which may probably cause inode use-after-free issues later. + */ + WARN_ON_ONCE(!list_empty_careful(&inode->i_io_list)); + if (!list_empty(&EXT4_I(inode)->i_fc_list)) ext4_fc_mark_ineligible(inode->i_sb, EXT4_FC_REASON_NOMEM, NULL); ext4_clear_inode(inode); /* We must guarantee clearing of inode... */ -- 2.31.1