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=1796380278; b=cg/pmokPy4C47IwREY9Do2wpSVc8f3K55UHYKjFQD8+aOwvvU9ovXsUK7yhpGIc28VNz 8Wu2oTL1S5ZkpKU1voAX3qH9rOQwR3+H/K4JXPJU6BOunr6VmZ9oowcYPKBiQL8mA/FcI yPOubT01Hpg/AnjNpYKFArCY0TPeqwzF1zth/p2bxUulFBZshhlraGJBzdpxbcxp5vW32 P2rLxquZ+tRuzhc3qvKaLqAdpBn7JaXQR2GDpPVHSlu5XN8CG2PjqnWpm7i2NDok02BpZ sIo5QIGcBoaV9O/LfPgMe0CW+rVGPlZycpZFtM29ZFs0Ey2MpBmTlyzpP7nvM9Kaisg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380278; 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=dCiZZvEwYo9rH38eR75eF6RWGnFw3Cr4EWabUPpj6OQ=; b=g7xGmzF54FmvnYF5ZBghiK0kwwjG4/aI1zltjUBPzw+EC4OhB3Oz7f8rTqEJEQCGdQ4N 2nbtBjVknskxJfLNUkJCkRxG1HxFe0O/iGQUFGu/wWFLQxIezVqihG4/Lh8r/8jmCd9Da rlc9PN8dWza/rjdX7IIztbu/gCUeZoX1f0zUQgvgsIq41DN1wrr1xLO2kUBiHHDXslyoU i0J+2x4c5AjLOSZMaixYhLlMAyN6WYos1T6Kbn+EvWMxEGy+8v7oOUSDxT0F4Vn9g/McX mqrqf8p3DM0x0411HNiUhKW3OZeUM7G3bF1AQzUoxXDKrH10JLLofjVWm7m1WlPvDng== 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="J5FtbEc/"; 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 357E7606A32C; Fri, 4 Dec 2026 10:31:18 +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=J5FtbEc/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4A101F000C2; Fri, 4 Dec 2026 10:31:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380278; bh=dCiZZvEwYo9rH38eR75eF6RWGnFw3Cr4EWabUPpj6OQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=J5FtbEc/MVOCAog0N9nT0wdbfk1EfNoAgTy2MT7a78wOLVA+N3oHPIg607/mbnz9k BLp1AqCbHDa80MpA8qvdSEIHYV4LCVaQWQUL01G9R2j9RC1aaeMFrvsk8Yacz2zOwt a88Sz72ORRKqFL/hJzOaNRthlfYOY0fZcaSxhJFs= 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 7.3 204/742] btrfs: send: fix invalid access to inline extents in clone_range() Date: Fri, 4 Dec 2026 19:01:08 +0900 Message-ID: <20261204100640.502594659@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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 d4b498ebfa56a..b7e07e2625ed8 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -5842,7 +5842,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)) { @@ -5906,23 +5906,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