From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C275C43381 for ; Tue, 26 Mar 2019 06:39:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CDDF12070B for ; Tue, 26 Mar 2019 06:39:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553582376; bh=T86PFvMYQVesU7a6Buf1NB66gK9mn5hbum6JriE/aZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=MQffr8OOPKFJbzPBXCBCrFrLf3tqL792Df0LjD0aXy3VwQMf1VG8tOTEVruNLzOBs vF2DZOkrDv72dhhfXzEmaklEM1fj/Hn7UIx/UXuKv6FdwXPCMSgBWDWfCF4NUerZnO 7ZI20CiDPzEMkDpsa/TrNpauuV2xHsQ7Tp1TzsqM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732721AbfCZGjf (ORCPT ); Tue, 26 Mar 2019 02:39:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:55070 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731504AbfCZGjd (ORCPT ); Tue, 26 Mar 2019 02:39:33 -0400 Received: from localhost (unknown [104.132.152.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B173B2070B; Tue, 26 Mar 2019 06:39:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553582372; bh=T86PFvMYQVesU7a6Buf1NB66gK9mn5hbum6JriE/aZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P3M3PccetMpyH4ruCGsTLUtOBOJHBqhiBrh9a6XSVfQWvxfOqd+mUhT22bZbu/atp jzMdroyTNHnp+G1kTgitWvxgVv2iS3cKVv6rAc8kx4uSiAp9LTJb1NJzRSi+Khx5ny TIXHvmZrQOQUP9NTGO4gSveKVTWwLTEzDnIypA+I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , "zhangyi (F)" , Theodore Tso , Jan Kara , stable@kernel.org Subject: [PATCH 5.0 35/52] ext4: brelse all indirect buffer in ext4_ind_remove_space() Date: Tue, 26 Mar 2019 15:30:22 +0900 Message-Id: <20190326042702.862229496@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190326042700.963224437@linuxfoundation.org> References: <20190326042700.963224437@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: zhangyi (F) commit 674a2b27234d1b7afcb0a9162e81b2e53aeef217 upstream. All indirect buffers get by ext4_find_shared() should be released no mater the branch should be freed or not. But now, we forget to release the lower depth indirect buffers when removing space from the same higher depth indirect block. It will lead to buffer leak and futher more, it may lead to quota information corruption when using old quota, consider the following case. - Create and mount an empty ext4 filesystem without extent and quota features, - quotacheck and enable the user & group quota, - Create some files and write some data to them, and then punch hole to some files of them, it may trigger the buffer leak problem mentioned above. - Disable quota and run quotacheck again, it will create two new aquota files and write the checked quota information to them, which probably may reuse the freed indirect block(the buffer and page cache was not freed) as data block. - Enable quota again, it will invoke vfs_load_quota_inode()->invalidate_bdev() to try to clean unused buffers and pagecache. Unfortunately, because of the buffer of quota data block is still referenced, quota code cannot read the up to date quota info from the device and lead to quota information corruption. This problem can be reproduced by xfstests generic/231 on ext3 file system or ext4 file system without extent and quota features. This patch fix this problem by releasing the missing indirect buffers, in ext4_ind_remove_space(). Reported-by: Hulk Robot Signed-off-by: zhangyi (F) Signed-off-by: Theodore Ts'o Reviewed-by: Jan Kara Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/indirect.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) --- a/fs/ext4/indirect.c +++ b/fs/ext4/indirect.c @@ -1387,10 +1387,14 @@ end_range: partial->p + 1, partial2->p, (chain+n-1) - partial); - BUFFER_TRACE(partial->bh, "call brelse"); - brelse(partial->bh); - BUFFER_TRACE(partial2->bh, "call brelse"); - brelse(partial2->bh); + while (partial > chain) { + BUFFER_TRACE(partial->bh, "call brelse"); + brelse(partial->bh); + } + while (partial2 > chain2) { + BUFFER_TRACE(partial2->bh, "call brelse"); + brelse(partial2->bh); + } return 0; }