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 13D103B1ED7; Wed, 30 Sep 2026 18:58:42 +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=1790794724; cv=none; b=R25L51OW2/FEPg3L+V0d4aRYE3s6uk0ItpBbJLGd9ZDzu+EbejKOwqr+dfnWzF34i5skgJuHb9RrnL6PQLuQXW9h4FBOEKzq5/ethJ9/QFs7Enoc8brZiBQ6XEaC/aScyHAle67kJYsQwbpeDYio+HxM1HkiavzPI5wODlIaD7I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790794724; c=relaxed/simple; bh=nMG22qLgdBAu2HwEfRfe+5gnmuIRB7Ui/kBAcaMvdZk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CEl8H8WrgbwCH91XlOV6ibM9vdOnWSqtKc5+R5s1l66gf0Y6lN8CHqqoyljqtXEtvJithHQk1w4wYdVZKZ60Rum/I/AKS5b43Xwgu4k+9ih0DTv+6hK5cgv6v+53QA5fcmeuk8Tjlk5cIzU38kPV1zYhTCWsHuoTqvJcMHPcDYw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=X+KYiSPq; 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="X+KYiSPq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12F8C1F000FF; Wed, 30 Sep 2026 18:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790794722; bh=FYD17tbURruTLUxf9Anuh0B8ormJRhurDRZwBUX0Q00=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=X+KYiSPqfciyN5pTOLl1Um7i04yGvAqQ1PnpmgrkQMjbOoNLXEqTFf4JaMpaPetk+ GflgGEg7Th0CEmaavy9pVXHUK/LmtL0TjUw8vdzvByP8wSrtUYtNfPb7AT7Yk7wSF7 +cf7ikae+ZL8gUGA1/AagDGHjPMQvI9BrQBP3WHQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Huiwen He , ChenXiaoSong , Steve French , Sasha Levin Subject: [PATCH 6.6 0310/1193] smb/client: flush dirty data before punching a hole Date: Wed, 30 Sep 2026 17:16:34 +0200 Message-ID: <20260930152441.031169695@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152434.301151190@linuxfoundation.org> References: <20260930152434.301151190@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 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Huiwen He [ Upstream commit d7d2adcd022baade5cab65ca492ce63421ce3a6e ] Punching a hole after a large buffered write may leave the range reported as data. Reproduce it with: xfs_io -f \ -c "pwrite -b 3m -S 0x61 0 3m" \ -c "fpunch 1m 1m" \ -c "seek -h 0" \ -c "seek -d 1m" \ /mnt/test/repro Punching 1 MiB at offset 1 MiB should produce: 0 1 MiB 2 MiB 3 MiB | DATA | HOLE | DATA | EOF Instead, the entire file is reported as data. SEEK_HOLE(0) returns EOF, and SEEK_DATA(1M) returns 1M. This happens because a dirty folio spanning the punched range can be written back after the punch and refill the hole. Fix this by flushing and waiting for dirty data in the punched range before invalidating the page cache and issuing FSCTL_SET_ZERO_DATA. The xfstests generic/539 pass against Samba/ksmbd with this change. Signed-off-by: Huiwen He Reviewed-by: ChenXiaoSong Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/smb/client/smb2ops.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 07ed4bfd40977..956d1dc8bca39 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -3328,6 +3328,15 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, goto out; filemap_invalidate_lock(inode->i_mapping); + /* + * Flush dirty data first, otherwise a dirty folio spanning the punched + * range may be written back after the ioctl and refill the hole. + */ + rc = filemap_write_and_wait_range(inode->i_mapping, offset, + offset + len - 1); + if (rc < 0) + goto unlock; + /* * We implement the punch hole through ioctl, so we need remove the page * caches first, otherwise the data may be inconsistent with the server. -- 2.53.0