Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp557394iog; Wed, 29 Jun 2022 05:54:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sgNTPTqO3+a35oov8XZWTsilD6IL6JXGLF/TWRWq76waNxvceLPxxLz3xDDmLcO7nJEYkW X-Received: by 2002:a05:6402:3514:b0:435:f24a:fbad with SMTP id b20-20020a056402351400b00435f24afbadmr3905908edd.311.1656507246690; Wed, 29 Jun 2022 05:54:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656507246; cv=none; d=google.com; s=arc-20160816; b=UUKdSRKY3W2ebGzbbgKuyQ+N7cV/9j69oCgsZfSxZP9w2J/pwNO59hr8D/e4pnf1Bg 2dsftYGwBEMJHCV69ufvOLkRg7MYA1CBw4QzWH4LgPjaNbh7Zh5HMqCQVg4q1taMv2jr ftrqxsjfZbe06f0QXD4Pd6gtwrM84o3k3rm1qIp6UM5iqyO3dm5kG6fkV7WCytk50vJw z5e+9x0HVyJfS2TR2lLtaE0ehWIs/nF3MM94XuMHUeTZHmS6JO1s3GzrOmNXg+Ec9T4P lfJHJhIy1QZAjWcX2H35vpV5RnPTKaY9/N4cUHMiZkJYtJWyEHClPJQK6m/9ViTQ2eJn 9J0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=1o69SsiRwr4iph4t5IfeSWdyIv9lAvX0szOXrf0Mg/Q=; b=AvOhccC3FoXStZZiOsjb2Aux69x/MkDBsSw/ogzrsAaR8mrwHp2jCF4tgPkdW30rvx xdNPCgEtZ/BzbgdxwGyEgxgFt+8VM9VHpJ3LVlRAVcBUL8VrZaZoRzriBnt5mfeP1Nt1 qLUIlZiK9OQXZxT/UrQUkFLa6iselKK/UfOTTKCHIEEEaO8rggMHWJPN7NyeisjTXs2V wf49MyTFYIph3qwwWaInjCxIDfQTZVyTqWLsO4r8ohI8CsT9wwcmVtGZODScZFdSRJCn uhwodKx701yEb5oScu/bF1xH2sThGaobyrR9EjjZWwxAsfovabcwy/h0FIgOw5tYolVa RlmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=nFrOXIo4; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=kywNiBEz; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb32-20020a1709077ea000b00703953c1631si866270ejc.151.2022.06.29.05.53.31; Wed, 29 Jun 2022 05:54:06 -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; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=nFrOXIo4; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=kywNiBEz; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229778AbiF2Mk5 (ORCPT + 99 others); Wed, 29 Jun 2022 08:40:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231316AbiF2Mk4 (ORCPT ); Wed, 29 Jun 2022 08:40:56 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F7EF32062 for ; Wed, 29 Jun 2022 05:40:55 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 366D821FAE; Wed, 29 Jun 2022 12:40:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1656506454; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1o69SsiRwr4iph4t5IfeSWdyIv9lAvX0szOXrf0Mg/Q=; b=nFrOXIo4siWSLjiaSXhI8BSfPVKluvjsMy1BTnwNtlq8MuuX4POCUNrVbvfbeobFkeN/MR yCOLPe3gTfpRO1lwusrehqGiELJK7kmOC4zN/TLWbKdt+8Ak9+QZfsJ6+Lj1c5GD9PYFet cc8b8K0Osg5GSpg9GO1KFEKYp6TBSvI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1656506454; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1o69SsiRwr4iph4t5IfeSWdyIv9lAvX0szOXrf0Mg/Q=; b=kywNiBEz08+9PAJ0ZO+X7G7sreLJjnyXYELJyWhOzkTIoura8UqI2vphZAECZvpOfqk3xP AktCm/pfeO+XNGBQ== Received: from quack3.suse.cz (unknown [10.100.224.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id E51132C141; Wed, 29 Jun 2022 12:40:53 +0000 (UTC) Received: by quack3.suse.cz (Postfix, from userid 1000) id 2133FA062F; Wed, 29 Jun 2022 14:40:51 +0200 (CEST) Date: Wed, 29 Jun 2022 14:40:51 +0200 From: Jan Kara To: Zhang Yi Cc: linux-ext4@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, yukuai3@huawei.com Subject: Re: [PATCH v3 2/2] ext4: check and assert if marking an no_delete evicting inode dirty Message-ID: <20220629124051.qpc2voxvzbyhir3y@quack3.lan> References: <20220629112647.4141034-1-yi.zhang@huawei.com> <20220629112647.4141034-2-yi.zhang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220629112647.4141034-2-yi.zhang@huawei.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 On Wed 29-06-22 19:26:47, Zhang Yi wrote: > 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. Thanks! Feel free to add: Reviewed-by: Jan Kara Honza > > 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 > -- Jan Kara SUSE Labs, CR