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=1796381986; b=3nA5llUDwGzYqzpG5z8GOzbtG6ia1op1pI4u21yiUofpfcI70Nr4GO9NBk0h9gnoU8aZ ctRQ6v+2O9KYeMUAE31axYOPy8bDSCplIvYNe/ldJOPln+a5acQgkHKIPisDTyOhp6dtx Bdt5MusIm2Yk/TQjl5ep7Y923NLVU8LYjkRI3Mgr01xjhjQspN6/FVTkOVghuZDrHktOL q85GIvkYnyfYTvV3z+Q/qdWFsJqjXu0oyUs171X7JgvG88PfHbm9pMdqx0fojJaeFdS5R ekV0hGUwGZINdoYDq/8Q1PhFCr+LfA/GbfDKrPkzp+FDb92x9cj1Ph3Vjbnumtj8K1w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381986; 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=2kuSzmllz1pujEuNepMrBflbYRSDLu2gRc9SwNwkzv8=; b=j/HIbh7WmnD4y8zyGaTIfAYuvN+ahTMTXH+MUhdHOEzg6YMtehyrwkHYNZH2oZ7tKPrH Mcgddgu/9mL5qVZ3uqP8CYkH1a06rstoZdCboNPPEWRU7/XBN7Fkg5LAzp2IS7pXe0xZn Qq+wIX4AYqDc9L9SA0TMt/jV+6Vn0Yfswfcedogc6H2h+9e+tPtmY7Jc3SoaVelDRamQh ijRCtWgmlYbCu48S3GKTL0IHcBuexodggtr/Hk717swvWdzv3n5a1UTzwBJNQiiAs9HGL 43PfPaVFc6BjDLjkr7y3qVjIDTH4NhbCbGPsKCTsfsEPCxGuyIDAcfXY/653BK8JRTg== 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="fwl+/KEO"; 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 8887C606A322; Fri, 4 Dec 2026 10:59:46 +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=fwl+/KEO Received: by smtp.kernel.org (Postfix) with ESMTPSA id F17341F000C2; Fri, 4 Dec 2026 10:59:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381986; bh=2kuSzmllz1pujEuNepMrBflbYRSDLu2gRc9SwNwkzv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fwl+/KEOlA8MjLHcod4/NcOUhrwqgg60gGRToo4kzE/sixppVLgwt5YR0OX5DabS3 MV8LiFqQ/xSYCvCay2hs2aURSjGVne6kcDWeIyILv4gA3ltdVNaoa5AwqZvckCAfvn cRUZQX4jf2vtd3suQ/P+qkStkiqJZcj371dnY6tE= 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 6.18 258/703] btrfs: fix double release of space when cloning compressed inline extent Date: Fri, 4 Dec 2026 19:02:37 +0900 Message-ID: <20261204100634.656070913@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: 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 c7e16785462d3..e451d768fca1a 100644 --- a/fs/btrfs/reflink.c +++ b/fs/btrfs/reflink.c @@ -117,8 +117,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