From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382748; b=vMSzEqAGNdlx8i9tgcYLTnVcUjnvhNb24wB9QlRb6or4V4R69ZhPGb42QgAMInf1MncG OYaM89cZFCcVU5QzE8lfMergtCFNiHUHtDZr5R+oxJRcgS2T/YdP8fwi5Vqlu58sTQAqH 8v2f0ABk7w+kjNsJyXj0H/y7oY0xMhTepxLPq8iPZ7zRffd6o8imm5CZB3ngjcdLhF2UW jvEqE1hAlF8Wb36fTQSqWPqpuOaHLNX8sWP9eOYLGoZleWkq05JH3atw595HX1jyn8Bo0 I/VvwbGAy+c0mZF0O2blkvuebd1v+pEkWwJymMl5PPJqSvdF9HiPcJnDpXe1EZ3ezkQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382748; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=u1/6Ca5RgAMGGWdUZ1/4ndp0aQq4Xu37lgtMSaNk40g=; b=Mr21ZPQro85x8odP1BKDE95fByegcknnHDFj5pBqt7d25vTKVO1Rir4ZUcIm4eLQH7bU Tl9uRNl+P50GfEqA990nhplKKvjqr4Lh3RK4bHO1k/V0espmVYZOZSpi4fK2iRdODHgfE DNJmCz94S7Yssa9MWavx0Q1IgOdsQJpW1Rln9a4mefvNRpbIUvCSbTevN01/StO9m0hrN 9kubSi9lvD6FJzQ8SF8i1tvBpLFBKa4ZsYb+iBzNaR2Z+QUgnuMZG5rI1c27JN8GkwrZB rn3WIw8KAHgtGkuFwiu8FVN/ll3UkQsKdQjmrm+K1Km1djy4z/ffYIIPUaGQ+j4Ezjg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=s7Jolb8Y; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BF3E606A337; Fri, 4 Dec 2026 11:12:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=s7Jolb8Y Received: by smtp.kernel.org (Postfix) with ESMTPSA id 234B11F00937; Fri, 4 Dec 2026 11:12:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382747; bh=u1/6Ca5RgAMGGWdUZ1/4ndp0aQq4Xu37lgtMSaNk40g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=s7Jolb8Y947vpXw3JJuPj/EIybeVmK5lOR2vhS/ojzlUo1S2l5/hfWqPHTR6djk4L g51FlK+wRRKQFe9y6VccLr34xe9jIbCIU0qgisPk2SE15G+ELQLu8PgMNtBZbKTU11 eHB5gIb94RmDXxiQ1u8ZiGhBprRU9NXRhoIKVE0o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hengyu Liang , Christoph Hellwig , Carlos Maiolino Subject: [PATCH 6.18 546/703] xfs: fix f_bfree underflow in statfs() Date: Fri, 4 Dec 2026 19:07:25 +0900 Message-ID: <20261204100642.303536879@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hengyu Liang commit f0b9e58eee233547e5d77e467ccee89d7a59dd63 upstream. Commit dd324cb79e54 ("xfs: refactor xfs_fs_statfs") made xfs_statfs_data() limit f_bfree with max(0LL, ...) instead of max_t(int64_t, 0, ...). However, the value is an unsigned difference, so max() never picks 0. As of now, when the free block counter is below the count of unavailable blocks, statfs() reports f_bfree and f_bavail close to 2^64 instead of 0, and df prints negative sizes. A similar issue happened before and was fixed by commit 237aac4624aa ("xfs: ensure f_bfree returned by statfs() is non-negative"). Perhaps the refactored code needs that fix as well. The issue can be reproduced on a new 2 GiB filesystem mounted on /mnt: for i in $(seq 3000); do head -c 65536 /dev/zero > /mnt/s$i; done dd if=/dev/zero of=/mnt/big bs=1M xfs_io -x -c 'resblks 100000000' /mnt for i in $(seq 1 2 3000); do rm /mnt/s$i; done sync df -h /mnt Before commit dd324cb79e54 ("xfs: refactor xfs_fs_statfs"), the result is: Filesystem Size Used Avail Use% Mounted on /dev/vda 2.0G 2.0G 0 100% /mnt After that commit, the result is: Filesystem Size Used Avail Use% Mounted on /dev/vda 2.0G -64Z -24K 100% /mnt This patch will compare the difference as a signed value again. Fixes: dd324cb79e54 ("xfs: refactor xfs_fs_statfs") Cc: stable@vger.kernel.org # v6.14 Signed-off-by: Hengyu Liang Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -895,7 +895,7 @@ xfs_statfs_data( xfs_sum_freecounter(mp, XC_FREE_BLOCKS); /* make sure st->f_bfree does not underflow */ - st->f_bfree = max(0LL, + st->f_bfree = max_t(int64_t, 0, fdblocks - xfs_freecounter_unavailable(mp, XC_FREE_BLOCKS)); /*