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=1796381948; b=GjK9GSTcAMKA+dbyG54+gVCRAd0IUnJV08lEa4R5iFs5YDppjAiaOy82Zt2I6sqAk0JH 4k73yUJ8oZGxXnjFUqUgGIxPR8kft3MKb64DGtVA1Mem9NrBZoiCodjz4W2TMwBWKzw4Z CeChEXganIgGwRespBcJ4LywgdoRaaaYFq58vaUAcwnmeJlOvhLcGPaZD3Q2RgcoR5gmT yhSn2IOy2ljmEMSPvhtbPncmbrOo76SZBHrI/d6SZTWkikKgo3kvM0LBEFPyPeBZf//Pp bBuXwGwWk14WvKp9WwssCKCbtaJ3X4e5YmxpA6qhleT4v/JBzB1mjm5bocLFgpIIj4Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381948; 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=kZBBSSlsGohVwAFVCsBubkuHqLJucSv9vundlF+H7mM=; b=ixJnSgeWBzcpaApJwhenIjYzFvt9h+Xu6kbpFngwHz5v+XaoR4M2HySJmarLdMCH2JAV tzFOKm6ewPp8HWebNLD+ixwvmbbr2WxBW0Cf8VNTpMYfhhjUvroLHTyak7Tib4aj7hodH oKMyb6kJ1uraIhLuwaz1gQXT6z/oTSPLx7FgC6KL54fh7LbtxQB2AUvbNY0IFYBZvL+EA MKWNcK89/C68v/uOUZIc6+S711WaakJPeAkdX/1RXo+zVS+RdRpitU/Onl6LNC2iqXldt WNTruJ7Z2zh5UmkftNDsHGUuIwLBFsK7nZjqvNBeriFMjNn1apCdc2e3vEn2ZLFz6jQ== 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=KyPOG5er; 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 C2078606A330; Fri, 4 Dec 2026 10:59:08 +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=KyPOG5er Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0163B1F000CE; Fri, 4 Dec 2026 10:59:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381948; bh=kZBBSSlsGohVwAFVCsBubkuHqLJucSv9vundlF+H7mM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KyPOG5eryn/jkCy30QRJVU2h3fZ0foFu28QEYYkk0hqITCaETbAYtuv+Hqy8ooK88 RBW5QmAolJD3AlONisyo5525KQnXu9965LuMEaLUHLZsl1/JizbsOewoe+foCb/TMC HsGDUF9i+QGqhlPvkHujCmTmvkwe3O44+MVmxnb4= 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 243/703] btrfs: send: fix invalid access to inline extents in clone_range() Date: Fri, 4 Dec 2026 19:02:22 +0900 Message-ID: <20261204100634.266194615@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 beed53bd3cb5f0b0a0aad453aa6f0b49060ff2dc ] We can't access the disk_bytenr and offset fields of a file extent item that represents an inline extent, since the extent's data starts at the offset of the disk_bytenr field and the offset field is after that, so both fields point either to inline data or beyond the file extent item in case the data is too small. Fix this by not reading the disk_bytenr and offset fields if we are dealing with an inline extent. Link: https://sashiko.dev/#/bug/linux-b662b951-0491-465b-a262-f01a108d8146 Fixes: 040ee6120cb6 ("Btrfs: send, improve clone range") Fixes: d906d49fc5f4 ("Btrfs: send, fix file corruption due to incorrect cloning operations") Reviewed-by: Qu Wenruo Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/send.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 718c6c2f23877..b91c1d856e96c 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -5872,7 +5872,7 @@ static int clone_range(struct send_ctx *sctx, struct btrfs_path *dst_path, u8 type; u64 ext_len; u64 clone_len; - u64 clone_data_offset; + u64 clone_data_offset = 0; bool crossed_src_i_size = false; if (slot >= btrfs_header_nritems(leaf)) { @@ -5936,23 +5936,26 @@ static int clone_range(struct send_ctx *sctx, struct btrfs_path *dst_path, crossed_src_i_size = true; } - clone_data_offset = btrfs_file_extent_offset(leaf, ei); - if (btrfs_file_extent_disk_bytenr(leaf, ei) == disk_byte) { - clone_root->offset = key.offset; - if (clone_data_offset < data_offset && - clone_data_offset + ext_len > data_offset) { - u64 extent_offset; - - extent_offset = data_offset - clone_data_offset; - ext_len -= extent_offset; - clone_data_offset += extent_offset; - clone_root->offset += extent_offset; + if (type != BTRFS_FILE_EXTENT_INLINE) { + clone_data_offset = btrfs_file_extent_offset(leaf, ei); + if (btrfs_file_extent_disk_bytenr(leaf, ei) == disk_byte) { + clone_root->offset = key.offset; + if (clone_data_offset < data_offset && + clone_data_offset + ext_len > data_offset) { + u64 extent_offset; + + extent_offset = data_offset - clone_data_offset; + ext_len -= extent_offset; + clone_data_offset += extent_offset; + clone_root->offset += extent_offset; + } } } clone_len = min_t(u64, ext_len, len); - if (btrfs_file_extent_disk_bytenr(leaf, ei) == disk_byte && + if (type != BTRFS_FILE_EXTENT_INLINE && + btrfs_file_extent_disk_bytenr(leaf, ei) == disk_byte && clone_data_offset == data_offset) { const u64 src_end = clone_root->offset + clone_len; const u64 sectorsize = SZ_64K; -- 2.53.0