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=1796383501; b=Ft2udFAJVgdqnp6r+FeP+8R1tn0pYyUck2p4zmKSHs+O4Oe+Lyvlze2ZG4a4XMpFUaI0 zgu+ZNFROgP/rtXpkkZkzR0CA8cn6JsR/OKIDpKCw1Gw9GBS6arC/0X1rBLVWh5xXs1/K KQEzgm1L/jf8FxQ9ipig51JC4+q9//HtReQZZ4gRjZSKi9jWsIgeeelzdYGvFa1RjAP2e f4yA60F+F8MWWD8xfSbTPUTz5L/ydn3h6wfhS18nm6rb0524YkHiem+zqZpDiitV8Z4ri OZRz5NFI4thgmPqxx0SsekyfWCOdqGyVfszvkGfFoagANzy0MNqcI3Avhf5I/SDLsiw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383501; 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=OGXMjyApbxCQyTfqrftvDVzJf++rCTeJdGXfNG3VVnU=; b=uTpKo8J+wq136siaep9+1zaGdcVStY7XIDBILhjzqffVUViRUca7HQWj75ONG1/3tr0j sTNi6tc7AnqOHqAv20yzPF78mtlGMtGGMeFVXRbFHoM4Y3kP5UZk/t65nPS02XFs/L+jj yR5a+OR2wRgm+/lcXM0qkqGw9LA8ihfSU9xgyU/PiC2nNDJHKU+t47E4MDeT+NKXvV6za srpMHuvLBs9P2A6SjjQkwCBRAD5ybVtFQykf/LLAsOLz6osGHbhD5T34lpk2Jeln2LoGo dy7i3Nog93Xsxp1TkADbKXjEqiSU5kFnzdEXI/ggaCdBE+pFXTmWPDFDQ0cnUp1Rf1Q== 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=06fx+uyI; 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 998F5606A322; Fri, 4 Dec 2026 11:25:01 +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=06fx+uyI Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1D9A1F000C2; Fri, 4 Dec 2026 11:25:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383501; bh=OGXMjyApbxCQyTfqrftvDVzJf++rCTeJdGXfNG3VVnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=06fx+uyIr2c3TXLhD9lPCM6t4717fu168T4/euMqPwyBDdM3cj+R4b05YwXxFmavD 7FQ4cVBhTvWs+lLNvkGMzbyKH1m1AA39GtHeEdJEW8Uq33uHuwgYI/jcvwf3h5TfMt pRHR9ATwA2Mgd7qPhhFtl2iTTymtZA3WE1MV8RAg= 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.12 249/555] btrfs: send: fix invalid access to inline extents in clone_range() Date: Fri, 4 Dec 2026 19:04:52 +0900 Message-ID: <20261204100618.648296391@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-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 8bb1031afbc8f..f80f9ea317829 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -6015,7 +6015,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)) { @@ -6079,23 +6079,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