From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC26F4C10DD; Thu, 17 Sep 2026 15:57:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789660667; cv=none; b=lUuHyouAUHcpmex8PLFn38bK16czDYT6loZV03216XUveap837OYcreNmIne9ydME2xvyXOJ65oy+MAfL+wqhY8iETgG9njx4eanaCl0sc4K8w9Ae3givQQ0xoSexN3qi+gNCWe/4c8c6skRVje21RoHWTJf49KR0e39ahka7Zs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789660667; c=relaxed/simple; bh=vkgMtXxpWsfs6vSI5jk/pxziJ+hrEnJKEkbqr5pPwEQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k4TBgT7Txh6qZxXaeCRqk+7gGyW1mw1r+zX5FMWKZ15wRG3BJoBO7FiS/KYttuvTUE5ZEYI/HqYOEpYzy8ov+fZJHnudT1N9jmNb22ACD4Xsp9s4SVWBx5lrfXK25+0xV+2RVtFql25K2oO9OTMVQcZVQK9T2+Ib9gPwIQgdyOo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=gBlx/ICc; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="gBlx/ICc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9F1C1F000FF; Thu, 17 Sep 2026 15:57:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789660665; bh=vbgnn3MjoU0kCIZPckgO/dMKPpf8FoczGQQgimTwPho=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gBlx/ICcP4GnFl406PaImxPZ24YJFlEe0IXMF7z7ZWOHHjdJCX/jh91ZxdRfl+iF5 GtCZvLlXxRB+7MuGqpvO7WdcCnEHDoPrQAMc7uw7oPVQAJshAn2TCnvX26QW74GIFh 3AdmSAX9W3kHbq8r/0Ws2OanCfgbAaz3UHD7ZN0M= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Lin Jiapeng (TencentOS Red Team)" , "Darrick J. Wong" , Christoph Hellwig , Carlos Maiolino Subject: [PATCH 7.2 669/733] xfs: fix exchange-range reflink flag clearing issue with INO1_WRITTEN Date: Thu, 17 Sep 2026 16:16:17 +0100 Message-ID: <20260917151409.380647726@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917151350.597953846@linuxfoundation.org> References: <20260917151350.597953846@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lin Jiapeng commit a23eca88448e52eb1a81549862df7adce794fafb upstream. When exchanging two full-file ranges, xmi_can_exchange_reflink_flags() can move the reflink inode flag from the file that currently has it to the other file, as long as exactly one side is marked. This assumes that the file contents, and therefore all shared extents, are exchanged. That assumption is not true when XFS_EXCHMAPS_INO1_WRITTEN is set. xfs_exchmaps_can_skip_mapping() can skip hole and unwritten mappings from file1, so an exchange can complete without moving every mapping that the earlier flag-swap decision accounted for. In that case the post-operation cleanup can clear the reflink flag from an inode that still owns shared written extents. Later writes then take the non-reflink write path and may update blocks that should still have been protected by CoW, which shows up as data corruption between reflink-related files. Fix this by disabling the reflink flag exchange whenever XFS_EXCHMAPS_INO1_WRITTEN is requested. The contents exchange can still proceed; the conservative outcome is that both inodes keep the reflink flag. The regular reflink flag cleanup path can drop the extra flag later once the inode no longer has shared extents. Reported-by: Lin Jiapeng (TencentOS Red Team) Fixes: 966ceafc7a43 ("xfs: create deferred log items for file mapping exchanges") Cc: stable@vger.kernel.org # v6.10 Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Lin Jiapeng Signed-off-by: Carlos Maiolino Signed-off-by: Greg Kroah-Hartman --- fs/xfs/libxfs/xfs_exchmaps.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/fs/xfs/libxfs/xfs_exchmaps.c +++ b/fs/xfs/libxfs/xfs_exchmaps.c @@ -969,6 +969,16 @@ xmi_can_exchange_reflink_flags( if (req->flags & XFS_EXCHMAPS_INO1_WRITTEN) return false; + /* + * The INO1_WRITTEN optimization can skip exchanging hole and + * unwritten mappings, which means we cannot guarantee that all + * shared extents actually moved to the other file. Clearing the + * reflink flag of an inode that still holds shared extents breaks + * the CoW write path, so refuse to exchange the flags in that case. + */ + if (req->flags & XFS_EXCHMAPS_INO1_WRITTEN) + return false; + if (hweight32(reflink_state) != 1) return false; if (req->startoff1 != 0 || req->startoff2 != 0)