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=1796380333; b=osvDQq0ul7n6XR2Dbj/m5KYeOzmv/OylxbeBBNsDSabXN/Ng2RlNDZrFGDoaMFPMiFL9 ae5t6HI/IJzOp4Xvna9GJkAQBPwypdbjdABQU3rSg6GJEFehP7FUiijuX0cQDPjPn9Yjf SHfnqp+RBMCkL9diLl5njRo3J3hVIxGzDLMpaywGXI02DDsziUn84FYdwtpyxZ8sMPIWf pWeGEjJlsVY9Pl0p9B941jk684MwU54N2XGVIbDYVHyA3ABlxWJ/cvxW4LOYbdGTLgidk da91fiR8+5zl4kLHtmnRaAeqFqx0w/P27nEyMP9gnmre3SBMwfc+zEQC0NxRqXqOiTA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380333; 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=hi2QVHf0CuMRl905/s/6uHzc9B0O3qWFvC3TAv9aOoA=; b=p7WsvyGZ7nsi5K0HZKlBjFeEvQPO+DvFYZSXKJ8jMs39iQgoYDz8/f4NM9mv/TqGe7P+ vo/ehCZMKIvOudeQv6KGQ2/4uoCxmk/W/1Jao4m84BIs5HVZx56RK5gkvYJ/KkKH1mLWM LTGehil1iwscR4TVO/aMOdbZo4OAM7spWBx/gv4I2g86jWP7zby5ioinkdKcEFB5/h3LP vtUzq1qcIBpiW0xgyMGOotoWnDNU+NOOXXzrqdW17WPuVUgYEHoYWhOp1rkikW7kU6+Cb cvEC3klsDiP6/R6RYUBM61qXfcNAZvrQtc4ly1wiRDaxCzmaaHg5nsC2K0TvxCCXKBA== 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="jO/FzY49"; 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 594DD606A322; Fri, 4 Dec 2026 10:32:13 +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=jO/FzY49 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B3521F000CE; Fri, 4 Dec 2026 10:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380333; bh=hi2QVHf0CuMRl905/s/6uHzc9B0O3qWFvC3TAv9aOoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jO/FzY49E97A8wyKKvpYsdyitSklqq3IKLdMnjU+dGjF89cscXRkVOwn48hFf+Z/e Z7DMUIwsS1FavNE6+IYw75RkpdHoWk5iHO/1rwJvf4ToF0Kst03NtppDShjJ2oS1bS 8H1Mx90jq1jCXGQ9jdVEZ95/UqDvHV+c0T1Vvf30= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Qu Wenruo , Filipe Manana , David Sterba , Sasha Levin Subject: [PATCH 7.3 221/742] btrfs: fix double release of space when cloning compressed inline extent Date: Fri, 4 Dec 2026 19:01:25 +0900 Message-ID: <20261204100640.945981365@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Filipe Manana [ Upstream commit ee020b5f0eb81a86533a16dcaafcee2b97a0f74d ] In copy_inline_to_page(), if we fail to decompress the inline extent, we jump to the out_unlock label and release the reserved data and metadata space with a call to btrfs_delalloc_release_space(). However we leave the range in the inode's io_tree marked as delalloc, which was set by btrfs_reset_extent_delalloc(), and that means when someone later clears the delalloc range, using EXTENT_DO_ACCOUNTING (like btrfs_reset_extent_delalloc() does), it will release again the space. This does not happen for uncompressed inline extents, because after the call to btrfs_reset_extent_delalloc() we can't get any other errors. Link: https://sashiko.dev/#/bug/linux-52478dd4-bd10-48de-baba-a527b38b64aa Fixes: 05a5a7621ce6 ("Btrfs: implement full reflink support for inline extents") Reviewed-by: Qu Wenruo Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/reflink.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/reflink.c b/fs/btrfs/reflink.c index ac8dfd6fa8140..d2567ee6e5fa3 100644 --- a/fs/btrfs/reflink.c +++ b/fs/btrfs/reflink.c @@ -120,8 +120,21 @@ static int copy_inline_to_page(struct btrfs_inode *inode, ret = btrfs_decompress(comp_type, data_start, folio, offset_in_folio(folio, file_offset), inline_size, datal); - if (ret) + if (ret) { + /* + * btrfs_reset_extent_delalloc() set the range as + * delalloc, so clear it, otherwise we will free the + * reserved data and metadata space twice, once below by + * btrfs_delalloc_release_space() and once again when + * someone else clears the delalloc range with + * EXTENT_DO_ACCOUNTING (like + * btrfs_reset_extent_delalloc() does). + */ + btrfs_clear_extent_bit(&inode->io_tree, file_offset, + range_end, EXTENT_DELALLOC | + EXTENT_DELALLOC_NEW, NULL); goto out_unlock; + } flush_dcache_folio(folio); } -- 2.53.0