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=1796389064; b=z1wkvw4ELZJyub9/qxc2J1V/Gg5nHl54z6xSi4ftYWyRz00LjOgc1qzLVVxWSJEXHLmU yTp+mBBc7ybytYje5UCp7/Vr6MB320a0cAKblyB9EuKwR+6MOkJHfBP5W0vHn7KuLZPN0 Hv812VpCI1Mrg1wuP3L/JzfLQrbcaCb63oVbeZWVCjh2tgAY43fKp5iA4lyRtl7dkPdLT dnI46RWE2Bfuv+g0jR/N20iECF18z6IatsyL4tPXY/K3eLTIabgwndHc86y+IMD/34pMz D5S9ocZvDyV8WTOiQ1ddfbzj4JQOv9+yBdOav1rd8aMolNufc0KTIbL+YsZqx0J7/+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389064; 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=zDy5j1PSb8emSexNkaagiYCWbGjR1DTjPTTMjdvlItE=; b=DDQ/uHeoE4ekjq6fKTk299zSF9099y1aHRaGFNnA6YwPUmIV/G0qKFrHH6onZVnbuhl2 RDVRZIUiZKYXnalfYu1F1jmNKbmOPw+xrqcOdRmvc4iWlKrF0GDQuFnWf1Y56KqyvZRZX J7zengcliMScp7XJL22mBfOcycAhmX9XO0eO8//OEmsNxiRpt2JahOb7nam/xKOcaO7XH ytfKSSZv0b3upqLImR9kET3kMsNDue8slw1GEOOJBef6Fqh295uV6Xcu3Kyj1vFEYNGKc CVY1nRHLuD7Tdq55vM9r4RrqhVSWhDnIawj0rm595ysb36ngUWqNzdg1GPzRfbmxwgA== 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=hrPV2+b3; 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 85FA8606A689; Fri, 4 Dec 2026 12:57:44 +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=hrPV2+b3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE6AF1F00A1B; Fri, 4 Dec 2026 12:57:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389064; bh=zDy5j1PSb8emSexNkaagiYCWbGjR1DTjPTTMjdvlItE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hrPV2+b3OyKl5bvsOPJDhfA6UUL04MbczsybQLyCH3CXx0jDzkSuxN0yn9Mwdo4V6 qbS4tqHuJiSrzywUU9Qc4WeK1+bYsLCU2SdQ7ghg/c6GZy/2yCIWtydC1J/5GM3/E5 67ASS7+/uL1mCdnLYYbCN1uaxX1wTZxAPG/fTQ3Q= 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.1 0854/1059] btrfs: send: fix invalid access to inline extents in clone_range() Date: Fri, 4 Dec 2026 19:06:25 +0900 Message-ID: <20261204100706.146507972@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-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 afab6a4e6a3c6..2ef340cad3085 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -5755,7 +5755,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)) { @@ -5819,23 +5819,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