Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1495190pxf; Fri, 9 Apr 2021 09:44:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpM2LdF60/OLeLuEbVRJbGinFGxcXP64MbBV8CH/n3q7wy4pWL8IlTtNSsXi1HxThQlXVY X-Received: by 2002:a17:906:77c5:: with SMTP id m5mr16082227ejn.201.1617986693948; Fri, 09 Apr 2021 09:44:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617986693; cv=none; d=google.com; s=arc-20160816; b=wcEHk5wWXIMp7ihiHkpufyjWV78gK/P3xSwhzobXDRFO5PnjBZEtwtVvM+56KVO9PU GDjNufJIui8VslmG/Lb3sxvyvLM8OQIFJYSkvPrbNGYQOinioWxH4+i5kwmWZi1fJgGX pBnTkRi1P/kHWoOx07fdbbW8qJRkE538/skLr78737RomimxoQ8A1vNm/l34coczj5NV hdSKqvNWYT1sFeDsajUmpFH4phUZnz1gzqgGIfdFvLpWKPoC6v3GgupkVWw92c9lfL+S 9uBMtweN67aFVrJcFd+Q8vsUCUqqHM1c5/ALBjOdtYyyq6fP5vVkb5YnDhy2PtDvCfIb wGhQ== 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; bh=D/F8kaWe6lMLVrWGoVcEINvnlKs51LNflKms10rEP/Y=; b=IxWtu4OmTGbhaNDzOAwPfoZXDdzzoG12b4lxi+pxf+SThT6vXEA1P8CfU5ojtyzIVt 5SclMMdtOC7ZRQoSiHF1lbQsDSXrkEgVK+9engyZpTHqWu5mINFdiO7yL4SLqBzFfsh2 wS0WYRFMAdlFT4v+JF1iSzLEePbw0kmHZ33Nq2+FuoY4mHzUcKE32pA3Jje8cuvBXxy5 qRvPnTYAEwh4JTqslRNYR5zyj/q+TNVixXyF/U3u/rgKGE4LgxTm20LDapXraSS+y7vx SgjDXhg99vMhmQ6C12J1RCHlpdAB9fk2Ww3LndsTSdergIxySApAXKAFbf7dyeRFsIVJ tzww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w16si2470075edd.471.2021.04.09.09.44.29; Fri, 09 Apr 2021 09:44:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233977AbhDIQog (ORCPT + 99 others); Fri, 9 Apr 2021 12:44:36 -0400 Received: from outgoing-auth-1.mit.edu ([18.9.28.11]:54432 "EHLO outgoing.mit.edu" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229665AbhDIQof (ORCPT ); Fri, 9 Apr 2021 12:44:35 -0400 Received: from cwcc.thunk.org (pool-72-74-133-215.bstnma.fios.verizon.net [72.74.133.215]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 139Gi0DU016716 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 9 Apr 2021 12:44:00 -0400 Received: by cwcc.thunk.org (Postfix, from userid 15806) id F0DF715C3B12; Fri, 9 Apr 2021 12:43:59 -0400 (EDT) Date: Fri, 9 Apr 2021 12:43:59 -0400 From: "Theodore Ts'o" To: Jan Kara Cc: Zhang Yi , linux-ext4@vger.kernel.org, adilger.kernel@dilger.ca Subject: Re: [PATCH] ext4: do not set SB_ACTIVE in ext4_orphan_cleanup() Message-ID: References: <20210331033138.918975-1-yi.zhang@huawei.com> <20210331095920.GF30749@quack2.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210331095920.GF30749@quack2.suse.cz> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Wed, Mar 31, 2021 at 11:59:20AM +0200, Jan Kara wrote: > On Wed 31-03-21 11:31:38, Zhang Yi wrote: > > When CONFIG_QUOTA is enabled, if we failed to mount the filesystem due > > to some error happens behind ext4_orphan_cleanup(), it will end up > > triggering a after free issue of super_block. The problem is that > > ext4_orphan_cleanup() will set SB_ACTIVE flag if CONFIG_QUOTA is > > enabled, after we cleanup the truncated inodes, the last iput() will put > > them into the lru list, and these inodes' pages may probably dirty and > > will be write back by the writeback thread, so it could be raced by > > freeing super_block in the error path of mount_bdev(). > > > > After check the setting of SB_ACTIVE flag in ext4_orphan_cleanup(), it > > was used to ensure updating the quota file properly, but evict inode and > > trash data immediately in the last iput does not affect the quotafile, > > so setting the SB_ACTIVE flag seems not required[1]. Fix this issue by > > just remove the SB_ACTIVE setting. > > Thanks for the patch. Let me rephrase the changelog a little: > > When CONFIG_QUOTA is enabled and if we later fail to finish mounting the > filesystem due to some error after ext4_orphan_cleanup(), we may hit use > after free issues. The problem is that ext4_orphan_cleanup() sets SB_ACTIVE > flag and so inodes processed during the orphan cleanup are put to the > superblock's LRU list instead of being immediately destroyed. However the > path handling error recovery after failed ->fill_super() call does not > destroy inodes attached to the superblock and so they are left active in > memory while the superblock is freed. > > Originally, SB_ACTIVE setting was added so that updated quota information > is not destroyed when we drop quota inode references after orphan cleanup. > However VFS does not purge dirty inode pages without SB_ACTIVE flag for many > years already. So just remove the hack with setting SB_ACTIVE flag from > ext4_orphan_cleanup(). > > Also feel free to add: > > Reviewed-by: Jan Kara > > Honza Applied, thanks. - Ted