Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3993610pxb; Mon, 4 Oct 2021 14:42:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTapDm6nn20p8iaL6kH4AN66abH61CJLtYz5PemogzxuREODO9fpR5CuhhXX3o6cxO7x/X X-Received: by 2002:a17:902:ab4b:b0:13e:932e:f65 with SMTP id ij11-20020a170902ab4b00b0013e932e0f65mr1767534plb.58.1633383722582; Mon, 04 Oct 2021 14:42:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633383722; cv=none; d=google.com; s=arc-20160816; b=Dayu7fn69oGCVwC0j7EE9U2NDTeqjIKc5ZSqj+D+33oXQlta1Zq4L3I5+Sxmuifte3 wTvjsl6ZE49bPtOlEl8aB+CaJu4c2s2bDpEz+JnRswaegsYmLRfwf6LTL92TKBjU+xHu qqwIR/wThrdVgh7hmCJxpTB3TREY3tOho7DhD2zuGXKqRQhkjWBI659J6C6DO8JUI8Lm rALYC7ZQGhCKnnkYj3LFqy/amC94AkrOpmmQKqhQS8NEq4xXksvz9OktE+E4frEz/MJW Nu9zkICn9usKmHkxXzqjPTHgX7uZjP7J88x5W4HUoA3C4hJeztB0NUN/38WuwlEa/OR6 KTxw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mNHlVfwo4dDlobU11jQI/ik/IfcoJcQhsv81vz8PzjE=; b=OdmXVa6sE3XrrGHsspdisYkyMCNZrJTkcbPWj61zbsGaNXI/7wU9IgPkdoqd0q+Ve1 UeDoFSYBcgC3CArENsQzC/MtH4avx5C4raKPM8xJO2Yfxcp9J7Vv1Df1+XjSNVeVbkll g1QoOXxr0SB+7xd+Q8osf3vh7d+d2f6oIEQJQFazySxh1kM6+/gw1iFmr8JJ3NCKIOSz fFwStsEbfHSW3MT17zNfi5/KcMHb4I4Pzk+6jEOVUaeZ1zQSyXEBNGxNIpFztswblAPj qTe9wzHx0kYzXiwP7qCQ8XKgWaB7JqGW2WyvE5vbGMegsxTD3breOY0rnXqBkFFTLfjP LBIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mCYmsewH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u1si21350475pls.99.2021.10.04.14.41.49; Mon, 04 Oct 2021 14:42:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mCYmsewH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238392AbhJDNmF (ORCPT + 99 others); Mon, 4 Oct 2021 09:42:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:51976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238364AbhJDNkV (ORCPT ); Mon, 4 Oct 2021 09:40:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4512363242; Mon, 4 Oct 2021 13:18:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353506; bh=D09irdrxtdPodoeP43k512tk67bMsz+r/9cUiYRIAjY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mCYmsewHW7fhvYNjd341ummuS22+rU1N9P3dTfj5xYJ2nZYlrZv+DvHKfphEL6DcH 1EjfaGmqfSHevc38Bmmq8nhDiMoZrer1QfWbAyujkQ+1D4MbEdhCDFmfyIZ+7RG+91 2BxIwpKx6cbEz7MxqlubK2TOQcR6RMyO+a7sMxSU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Gao Xiang , Jeffle Xu , Eric Whitney , Theodore Tso Subject: [PATCH 5.14 155/172] ext4: fix reserved space counter leakage Date: Mon, 4 Oct 2021 14:53:25 +0200 Message-Id: <20211004125049.975194364@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jeffle Xu commit 6fed83957f21eff11c8496e9f24253b03d2bc1dc upstream. When ext4_insert_delayed block receives and recovers from an error from ext4_es_insert_delayed_block(), e.g., ENOMEM, it does not release the space it has reserved for that block insertion as it should. One effect of this bug is that s_dirtyclusters_counter is not decremented and remains incorrectly elevated until the file system has been unmounted. This can result in premature ENOSPC returns and apparent loss of free space. Another effect of this bug is that /sys/fs/ext4//delayed_allocation_blocks can remain non-zero even after syncfs has been executed on the filesystem. Besides, add check for s_dirtyclusters_counter when inode is going to be evicted and freed. s_dirtyclusters_counter can still keep non-zero until inode is written back in .evict_inode(), and thus the check is delayed to .destroy_inode(). Fixes: 51865fda28e5 ("ext4: let ext4 maintain extent status tree") Cc: stable@kernel.org Suggested-by: Gao Xiang Signed-off-by: Jeffle Xu Reviewed-by: Eric Whitney Signed-off-by: Theodore Ts'o Link: https://lore.kernel.org/r/20210823061358.84473-1-jefflexu@linux.alibaba.com Signed-off-by: Greg Kroah-Hartman --- fs/ext4/inode.c | 5 +++++ fs/ext4/super.c | 6 ++++++ 2 files changed, 11 insertions(+) --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1640,6 +1640,7 @@ static int ext4_insert_delayed_block(str struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); int ret; bool allocated = false; + bool reserved = false; /* * If the cluster containing lblk is shared with a delayed, @@ -1656,6 +1657,7 @@ static int ext4_insert_delayed_block(str ret = ext4_da_reserve_space(inode); if (ret != 0) /* ENOSPC */ goto errout; + reserved = true; } else { /* bigalloc */ if (!ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk)) { if (!ext4_es_scan_clu(inode, @@ -1668,6 +1670,7 @@ static int ext4_insert_delayed_block(str ret = ext4_da_reserve_space(inode); if (ret != 0) /* ENOSPC */ goto errout; + reserved = true; } else { allocated = true; } @@ -1678,6 +1681,8 @@ static int ext4_insert_delayed_block(str } ret = ext4_es_insert_delayed_block(inode, lblk, allocated); + if (ret && reserved) + ext4_da_release_space(inode, 1); errout: return ret; --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1351,6 +1351,12 @@ static void ext4_destroy_inode(struct in true); dump_stack(); } + + if (EXT4_I(inode)->i_reserved_data_blocks) + ext4_msg(inode->i_sb, KERN_ERR, + "Inode %lu (%p): i_reserved_data_blocks (%u) not cleared!", + inode->i_ino, EXT4_I(inode), + EXT4_I(inode)->i_reserved_data_blocks); } static void init_once(void *foo)