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=1796386471; b=04+g280HaJgq++pAd7O2/Bu1/cqpQr3N5DgsGyjvOhi6P61gpplVMaNXfqRJ0dph4BhM p4C8F84S7/SXDxiP7Oq+y1T6vdLu2wW/RQ8LLll/kn4zR6Io30R0bAN/6dbs46YbMux91 20Iu5aD6yoRyMLawG1TNIhYDQSK9eYhOO4OckphAZRi1DcTPsfBtgyisc53YtrzzFfP/s iqAbnwCcCYHMRI33rePh0d5gf5ts/SQdSOtG5RJGIXsJ99KLCkp1epKOR005QNtlQTr5/ dfqyOHRC2ag0Fph41vtWcRN6c1QO5vLnqvRvOJxc0tvj2+i397cUB9P4cHRjhuDTaFQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386471; 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=CTVRd+vJvYCtfaRYuYgJdml3wRBZvklMePnj92OJOy0=; b=zSgGYe0vL2hZs/Rq9vLKWpXh9uf1Ijk5ZUTuzrbUm+Y/WVtm0f1O3rtnAppSSPH399d3 gOFCp0Bcec10jOQJxiQZ9d2esk05dE+vOnHc9O6hv7U2YHcZUzLtgiNY0HJQCMmWi6t7q cXE/CQ7Ofq28FFSTjELIKbaFSwYsfA8lX5QdYGe/8bjGdvHT08+SY/N2l5WncurTp9YlS nNvSYYUcEeItAtd+2ZBPLV+Z+4zOlFjx00ER9kT3mNwQfvxuOPjIu1/2XoUOG8eaoxKlS LbCwZ8bbprrnK1EdsxAXBFPJHo3Oxzlu0LlpQhNBB8iEzrgcEWW1hyS2w6rU50tSArw== 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="kcA/RLo6"; 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 B1ED3606A322; Fri, 4 Dec 2026 12:14:31 +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=kcA/RLo6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28CB01F00935; Fri, 4 Dec 2026 12:14:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386471; bh=CTVRd+vJvYCtfaRYuYgJdml3wRBZvklMePnj92OJOy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kcA/RLo6KZ2FlnA4caGE08acNjBOEvUeD8ZM554gkYbOC7vcJDlocwlYVsacoG2Ei Hm0zh6zca1pLJEjv2s5b6wNF2g81SEBoQNr08qRul5QgStPzAcQMcje1CjcDxxfyI4 9m3z8705V29S9VPZZ48IgZ2hsWjR2HvxPl/kpjxs= 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.6 0940/1167] btrfs: send: fix invalid access to inline extents in clone_range() Date: Fri, 4 Dec 2026 19:06:07 +0900 Message-ID: <20261204100726.678485206@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-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 099b5a2e11566..1532683b493a3 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -6011,7 +6011,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)) { @@ -6075,23 +6075,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