** Description changed: + [Impact] + + CephFS can silently return zeros for valid file data on the Noble GA + kernel. The Noble HWE kernel is not affected. + + Christopher Dion's reproducer writes a file filled with 0xFF, punches a + hole near a 4 MiB RADOS object boundary, and reads the valid 16 KiB + immediately before the hole. On an affected kernel, the read succeeds + but the valid 16 KiB is returned as zeros. + + I reproduced the bug on a clean Ubuntu 24.04.5 VM using MicroCeph + 19.2.3, three OSDs and the CephFS kernel client: + + 6.8.0-147-generic: 4 passed, 5 failed + 7.0.0-42-generic: 9 passed, 0 failed + + The five failures occur when the punched range starts before the 4 MiB + object boundary and ends at or beyond the boundary. Crossing the + boundary is not required. + + The reproducer uses hole punching, but the bug affects short reads in + general. It can occur whenever a read covers both a stored RADOS object + prefix and an empty tail. + + The faulty read corrupts the page cache and does not change the data + stored in RADOS. However, an application may make the corruption + persistent if it later writes data based on that corrupted result. + + The same bug was previously reported in Bugzilla #219237: + + https://bugzilla.kernel.org/show_bug.cgi?id=219237 + + The regression was introduced by 92b6cc5 ("netfs: Add iov_iters to + (sub)requests to describe various buffers"). This commit first appeared + in 6.8 kernel. I confirmed that the affected code remains in Linux 6.8, + 6.9, 6.10 and 6.11 kernels + + 92b6cc5 added an iterator to each netfs subrequest and required the + network filesystem to advance it by the number of bytes read before + completing the subrequest. + + Ceph misses this requirement because cephfs and netfs use separate + iterators for the same read. netfs creates subreq->io_iter for the + subrequest, while cephfs passes another local iterator over the same + page-cache pages to the OSD client. + + OSD client writes the returned data into the correct pages but advances + only its own iterator. After a short read, netfs records the number of + bytes returned in subreq->transferred, but subreq->io_iter remains at + the beginning. netfs then uses the unchanged subreq->io_iter to clear + the unread tail and instead clears the full subrequest.. + + 6.12 kernel is not affected because ee4cdf7 ("netfs: Speed up buffered + reading") replaced the old netfs read path. This is a large netfs + redesign rather than a small cephfs fix. + + Older maintained stable kernels (6.6, 6.1, 5.15 and 5.10) are neither + affected. I confirmed that no relevant commit was not backported to + these releases. + + [Test Plan] + + Mount CephFS using the Noble GA kernel and confirm that the Ceph cluster + reports HEALTH_OK: + + uname -a + ceph -s + findmnt /mnt/cephfs + python3 reproduce-ceph-punch-hole-corruption.py /mnt/cephfs + + The reproduce-ceph-punch-hole-corruption.py script is attached to + Christopher Dion's original bug report. + + The affected kernel should report: + + Results: 4 passed, 5 failed out of 9 + + To verify the fix, build and boot a complete Noble kernel package + containing the change. Confirm the kernel version and run the same + reproducer at least three times. + + The patched kernel should report: + + Results: 9 passed, 0 failed out of 9 + + Confirm that dmesg contains no new warnings and that ceph -s remains + healthy after the test. + + [Where problems could occur] + + Dion's cephfs patch changes the cephfs OSD and inline-data completion + paths. If the iterator is advanced by the wrong amount, a later + operation could use the wrong part of the destination buffer. + + Ebner's netfs patch changes generic netfs code. If the iterator is reset + to the wrong position, netfs could clear valid data or fail to clear + part of an unread tail. Other filesystems using the same netfs path + could also be affected. + + The netfs patch uses an existing helper which calculates the expected + iterator position from subreq->len and subreq->transferred. If the + filesystem already advanced the iterator correctly, the helper makes no + change. + + [Other Info] + + Dion's cephfs patch advances subreq->io_iter in the cephfs OSD and + inline-data completion paths. I confirmed that it fixes the reproducer + with a patched kernel: + + Results (unpatched): 4 passed, 5 failed + Results (patched): 9 passed, 0 failed + + I found no matching upstream commit or mailing list submission for the + patch. + + Ebner's netfs patch adds: + + if (test_bit(NETFS_SREQ_CLEAR_TAIL, &subreq->flags)) { + + netfs_reset_subreq_iter(rreq, subreq); + netfs_clear_unread(subreq); + + This resets subreq->io_iter after netfs recorded the number of + transferred bytes. If a filesystem already advanced the iterator + correctly, netfs_reset_subreq_iter() makes no change. + + The original mainline series is not suitable as a Noble backport. + ee4cdf7 is a broader redesign that changes the netfs read interface and + touches netfs, cephfs, 9P, AFS, NFS and SMB. + + However, ee4cdf7 fixes this bug at the same generic point as the netfs + patch. The new netfs_clear_unread() calls netfs_reset_iter() before + iov_iter_zero(): + + static void netfs_clear_unread(struct netfs_io_subrequest *subreq) + { + netfs_reset_iter(subreq); + iov_iter_zero(iov_iter_count(&subreq->io_iter), + &subreq->io_iter); + } + + netfs_reset_iter() is functionally equivalent to Noble's + netfs_reset_subreq_iter(). Both reposition subreq->io_iter using + subreq->transferred before netfs clears the unread tail. + + netfs_clear_unread() has only one caller in Noble, so the reset could + instead be placed inside that function to match Linux 6.12 exactly. + Ebner's patch places it at the call site to keep the stable change to + one line. + + I tested both netfs variants. Ebner's patch and the equivalent reset + inside netfs_clear_unread() each passed all cases. + + The netfs patch was submitted for stable kernels in October 2024: + + https://lore.kernel.org/all/[email protected]/ + + The patch not merged into upstream stable. Greg asked Ebner to use the + original commits in 6.12 kernel, or approval from the relevant + maintainers that a one-off backport is the correct approach: + + https://lore.kernel.org/all/2024111053-expectant-moodiness-6118@gregkh/ + + However,the patch was included into Proxmox 6.8 kernel in October 2024: + + https://github.com/proxmox/pve-kernel/commit/e64f4bf + + I confirmed that Proxmox continued carrying the patch in its maintained + 6.8 branch through August 2026. Proxmox removed the patch from its newer + 6.14 kernel because the old netfs read path no longer exists there. + + Fedora and openSUSE moved from affected 6.8 to 6.11 kernels to 6.12 + without carrying either patch. RHEL and SLE skipped the affected range. + + The two patches can also be applied together. The cephfs patch would + make cephfs follow the Linux 6.8 iterator requirement, while the netfs + patch would provide a generic safeguard. + + + Orignal Description + === + Running Ceph FS on Ubuntu 24.04 (6.8 kernel) - Ubuntu 6.8.0-100.100-generic 6.8.12 Enclosed script reproduce-ceph-punch-hole-corruption.py exposes issue that we have found that on recent kernels CephFS silently corrupts 16KB of data before the requested hole when trying to punch a hole through file (test uses fallocate()). Corruption only occurs when hole touches or crosses a 4MB RADOS object boundary (4MB is the default stripe size). Execution shows the corruption: # python3 ./reproduce-ceph-punch-hole-corruption.py /Shared_DataStore/ CephFS PUNCH_HOLE data corruption reproducer ============================================================ Mount point: /Shared_DataStore/ Object size: 4194304 (4 MiB) Tests crossing 4MB object boundary (expect FAIL on buggy kernels): ------------------------------------------------------------ FAIL 1 page before boundary, 2 pages hole=[4190208, 4198400) checked=[4173824, 4190208) 16384/16384 bytes read as 0x00 (expected 0xFF) FAIL 2 pages before boundary, 4 pages hole=[4186112, 4202496) checked=[4169728, 4186112) 16384/16384 bytes read as 0x00 (expected 0xFF) FAIL 4 pages before boundary, 8 pages hole=[4177920, 4210688) checked=[4161536, 4177920) 16384/16384 bytes read as 0x00 (expected 0xFF) FAIL ends at boundary, 2 pages hole=[4186112, 4194304) checked=[4169728, 4186112) 16384/16384 bytes read as 0x00 (expected 0xFF) FAIL ends at boundary, 1 page hole=[4190208, 4194304) checked=[4173824, 4190208) 16384/16384 bytes read as 0x00 (expected 0xFF) Tests NOT crossing boundary (should always PASS): ------------------------------------------------------------ PASS within object 0 hole=[4161536, 4169728) checked=[4145152, 4161536) PASS mid object 0 hole=[1048576, 1056768) checked=[1032192, 1048576) PASS start of object 1 hole=[4194304, 4202496) checked=[4177920, 4194304) PASS within object 1 hole=[5242880, 5251072) checked=[5226496, 5242880) ============================================================ Results: 4 passed, 5 failed out of 9 BUG CONFIRMED: This kernel has the CephFS PUNCH_HOLE corruption bug. Enclosed is a patch submission detailing issue (AI created): 0001-ceph- fix-data-corruption-from-short-read-on-punch-hole.patch With patch test script now passes: # python3 /home/eceuser/reproduce-ceph-punch-hole-corruption.py /Shared_DataStore/ CephFS PUNCH_HOLE data corruption reproducer ============================================================ Mount point: /Shared_DataStore/ Object size: 4194304 (4 MiB) Tests crossing 4MB object boundary (expect FAIL on buggy kernels): ------------------------------------------------------------ PASS 1 page before boundary, 2 pages hole=[4190208, 4198400) checked=[4173824, 4190208) PASS 2 pages before boundary, 4 pages hole=[4186112, 4202496) checked=[4169728, 4186112) PASS 4 pages before boundary, 8 pages hole=[4177920, 4210688) checked=[4161536, 4177920) PASS ends at boundary, 2 pages hole=[4186112, 4194304) checked=[4169728, 4186112) PASS ends at boundary, 1 page hole=[4190208, 4194304) checked=[4173824, 4190208) Tests NOT crossing boundary (should always PASS): ------------------------------------------------------------ PASS within object 0 hole=[4161536, 4169728) checked=[4145152, 4161536) PASS mid object 0 hole=[1048576, 1056768) checked=[1032192, 1048576) PASS start of object 1 hole=[4194304, 4202496) checked=[4177920, 4194304) PASS within object 1 hole=[5242880, 5251072) checked=[5226496, 5242880) ============================================================ Results: 9 passed, 0 failed out of 9 All tests passed. This kernel is not affected (or the fix is applied). Appears as if following commit causes the issue: 92b6cc5d1e7c ("netfs: Add iov_iters to (sub)requests to describe various buffers") by David Howells, authored 2023-09-27, committed 2023-12-24. Merged in v6.8-rc1. This is only present in 6.8 and 6.9 kernels, 6.10 rewrote this activity under ee4cdf7ba857 ("netfs: Speed up buffered reading") by David Howells, 2024-07-02. Merged in v6.10.) which no longer has this issue. Asking for either analysis of enclosed patch to be included into Stable or if there is another/better way to fix.
** Description changed: [Impact] CephFS can silently return zeros for valid file data on the Noble GA kernel. The Noble HWE kernel is not affected. Christopher Dion's reproducer writes a file filled with 0xFF, punches a hole near a 4 MiB RADOS object boundary, and reads the valid 16 KiB immediately before the hole. On an affected kernel, the read succeeds but the valid 16 KiB is returned as zeros. I reproduced the bug on a clean Ubuntu 24.04.5 VM using MicroCeph 19.2.3, three OSDs and the CephFS kernel client: 6.8.0-147-generic: 4 passed, 5 failed 7.0.0-42-generic: 9 passed, 0 failed The five failures occur when the punched range starts before the 4 MiB object boundary and ends at or beyond the boundary. Crossing the boundary is not required. The reproducer uses hole punching, but the bug affects short reads in general. It can occur whenever a read covers both a stored RADOS object prefix and an empty tail. The faulty read corrupts the page cache and does not change the data stored in RADOS. However, an application may make the corruption persistent if it later writes data based on that corrupted result. The same bug was previously reported in Bugzilla #219237: https://bugzilla.kernel.org/show_bug.cgi?id=219237 The regression was introduced by 92b6cc5 ("netfs: Add iov_iters to (sub)requests to describe various buffers"). This commit first appeared in 6.8 kernel. I confirmed that the affected code remains in Linux 6.8, 6.9, 6.10 and 6.11 kernels 92b6cc5 added an iterator to each netfs subrequest and required the network filesystem to advance it by the number of bytes read before completing the subrequest. Ceph misses this requirement because cephfs and netfs use separate iterators for the same read. netfs creates subreq->io_iter for the subrequest, while cephfs passes another local iterator over the same page-cache pages to the OSD client. OSD client writes the returned data into the correct pages but advances only its own iterator. After a short read, netfs records the number of bytes returned in subreq->transferred, but subreq->io_iter remains at the beginning. netfs then uses the unchanged subreq->io_iter to clear the unread tail and instead clears the full subrequest.. 6.12 kernel is not affected because ee4cdf7 ("netfs: Speed up buffered reading") replaced the old netfs read path. This is a large netfs redesign rather than a small cephfs fix. Older maintained stable kernels (6.6, 6.1, 5.15 and 5.10) are neither affected. I confirmed that no relevant commit was not backported to these releases. [Test Plan] Mount CephFS using the Noble GA kernel and confirm that the Ceph cluster reports HEALTH_OK: uname -a ceph -s findmnt /mnt/cephfs python3 reproduce-ceph-punch-hole-corruption.py /mnt/cephfs The reproduce-ceph-punch-hole-corruption.py script is attached to Christopher Dion's original bug report. The affected kernel should report: Results: 4 passed, 5 failed out of 9 To verify the fix, build and boot a complete Noble kernel package containing the change. Confirm the kernel version and run the same reproducer at least three times. The patched kernel should report: Results: 9 passed, 0 failed out of 9 Confirm that dmesg contains no new warnings and that ceph -s remains healthy after the test. [Where problems could occur] Dion's cephfs patch changes the cephfs OSD and inline-data completion paths. If the iterator is advanced by the wrong amount, a later operation could use the wrong part of the destination buffer. Ebner's netfs patch changes generic netfs code. If the iterator is reset to the wrong position, netfs could clear valid data or fail to clear part of an unread tail. Other filesystems using the same netfs path could also be affected. The netfs patch uses an existing helper which calculates the expected iterator position from subreq->len and subreq->transferred. If the filesystem already advanced the iterator correctly, the helper makes no change. [Other Info] Dion's cephfs patch advances subreq->io_iter in the cephfs OSD and inline-data completion paths. I confirmed that it fixes the reproducer with a patched kernel: Results (unpatched): 4 passed, 5 failed Results (patched): 9 passed, 0 failed I found no matching upstream commit or mailing list submission for the patch. Ebner's netfs patch adds: if (test_bit(NETFS_SREQ_CLEAR_TAIL, &subreq->flags)) { + netfs_reset_subreq_iter(rreq, subreq); - netfs_clear_unread(subreq); + netfs_clear_unread(subreq); This resets subreq->io_iter after netfs recorded the number of transferred bytes. If a filesystem already advanced the iterator correctly, netfs_reset_subreq_iter() makes no change. The original mainline series is not suitable as a Noble backport. ee4cdf7 is a broader redesign that changes the netfs read interface and touches netfs, cephfs, 9P, AFS, NFS and SMB. However, ee4cdf7 fixes this bug at the same generic point as the netfs patch. The new netfs_clear_unread() calls netfs_reset_iter() before iov_iter_zero(): static void netfs_clear_unread(struct netfs_io_subrequest *subreq) { - netfs_reset_iter(subreq); - iov_iter_zero(iov_iter_count(&subreq->io_iter), - &subreq->io_iter); + netfs_reset_iter(subreq); + iov_iter_zero(iov_iter_count(&subreq->io_iter), + &subreq->io_iter); } netfs_reset_iter() is functionally equivalent to Noble's netfs_reset_subreq_iter(). Both reposition subreq->io_iter using subreq->transferred before netfs clears the unread tail. netfs_clear_unread() has only one caller in Noble, so the reset could instead be placed inside that function to match Linux 6.12 exactly. Ebner's patch places it at the call site to keep the stable change to one line. I tested both netfs variants. Ebner's patch and the equivalent reset inside netfs_clear_unread() each passed all cases. The netfs patch was submitted for stable kernels in October 2024: https://lore.kernel.org/all/[email protected]/ The patch not merged into upstream stable. Greg asked Ebner to use the original commits in 6.12 kernel, or approval from the relevant maintainers that a one-off backport is the correct approach: https://lore.kernel.org/all/2024111053-expectant-moodiness-6118@gregkh/ However,the patch was included into Proxmox 6.8 kernel in October 2024: https://github.com/proxmox/pve-kernel/commit/e64f4bf I confirmed that Proxmox continued carrying the patch in its maintained 6.8 branch through August 2026. Proxmox removed the patch from its newer 6.14 kernel because the old netfs read path no longer exists there. Fedora and openSUSE moved from affected 6.8 to 6.11 kernels to 6.12 without carrying either patch. RHEL and SLE skipped the affected range. The two patches can also be applied together. The cephfs patch would make cephfs follow the Linux 6.8 iterator requirement, while the netfs patch would provide a generic safeguard. Orignal Description - === + =================== Running Ceph FS on Ubuntu 24.04 (6.8 kernel) - Ubuntu 6.8.0-100.100-generic 6.8.12 Enclosed script reproduce-ceph-punch-hole-corruption.py exposes issue that we have found that on recent kernels CephFS silently corrupts 16KB of data before the requested hole when trying to punch a hole through file (test uses fallocate()). Corruption only occurs when hole touches or crosses a 4MB RADOS object boundary (4MB is the default stripe size). Execution shows the corruption: # python3 ./reproduce-ceph-punch-hole-corruption.py /Shared_DataStore/ CephFS PUNCH_HOLE data corruption reproducer ============================================================ Mount point: /Shared_DataStore/ Object size: 4194304 (4 MiB) Tests crossing 4MB object boundary (expect FAIL on buggy kernels): ------------------------------------------------------------ FAIL 1 page before boundary, 2 pages hole=[4190208, 4198400) checked=[4173824, 4190208) 16384/16384 bytes read as 0x00 (expected 0xFF) FAIL 2 pages before boundary, 4 pages hole=[4186112, 4202496) checked=[4169728, 4186112) 16384/16384 bytes read as 0x00 (expected 0xFF) FAIL 4 pages before boundary, 8 pages hole=[4177920, 4210688) checked=[4161536, 4177920) 16384/16384 bytes read as 0x00 (expected 0xFF) FAIL ends at boundary, 2 pages hole=[4186112, 4194304) checked=[4169728, 4186112) 16384/16384 bytes read as 0x00 (expected 0xFF) FAIL ends at boundary, 1 page hole=[4190208, 4194304) checked=[4173824, 4190208) 16384/16384 bytes read as 0x00 (expected 0xFF) Tests NOT crossing boundary (should always PASS): ------------------------------------------------------------ PASS within object 0 hole=[4161536, 4169728) checked=[4145152, 4161536) PASS mid object 0 hole=[1048576, 1056768) checked=[1032192, 1048576) PASS start of object 1 hole=[4194304, 4202496) checked=[4177920, 4194304) PASS within object 1 hole=[5242880, 5251072) checked=[5226496, 5242880) ============================================================ Results: 4 passed, 5 failed out of 9 BUG CONFIRMED: This kernel has the CephFS PUNCH_HOLE corruption bug. Enclosed is a patch submission detailing issue (AI created): 0001-ceph- fix-data-corruption-from-short-read-on-punch-hole.patch With patch test script now passes: # python3 /home/eceuser/reproduce-ceph-punch-hole-corruption.py /Shared_DataStore/ CephFS PUNCH_HOLE data corruption reproducer ============================================================ Mount point: /Shared_DataStore/ Object size: 4194304 (4 MiB) Tests crossing 4MB object boundary (expect FAIL on buggy kernels): ------------------------------------------------------------ PASS 1 page before boundary, 2 pages hole=[4190208, 4198400) checked=[4173824, 4190208) PASS 2 pages before boundary, 4 pages hole=[4186112, 4202496) checked=[4169728, 4186112) PASS 4 pages before boundary, 8 pages hole=[4177920, 4210688) checked=[4161536, 4177920) PASS ends at boundary, 2 pages hole=[4186112, 4194304) checked=[4169728, 4186112) PASS ends at boundary, 1 page hole=[4190208, 4194304) checked=[4173824, 4190208) Tests NOT crossing boundary (should always PASS): ------------------------------------------------------------ PASS within object 0 hole=[4161536, 4169728) checked=[4145152, 4161536) PASS mid object 0 hole=[1048576, 1056768) checked=[1032192, 1048576) PASS start of object 1 hole=[4194304, 4202496) checked=[4177920, 4194304) PASS within object 1 hole=[5242880, 5251072) checked=[5226496, 5242880) ============================================================ Results: 9 passed, 0 failed out of 9 All tests passed. This kernel is not affected (or the fix is applied). Appears as if following commit causes the issue: 92b6cc5d1e7c ("netfs: Add iov_iters to (sub)requests to describe various buffers") by David Howells, authored 2023-09-27, committed 2023-12-24. Merged in v6.8-rc1. This is only present in 6.8 and 6.9 kernels, 6.10 rewrote this activity under ee4cdf7ba857 ("netfs: Speed up buffered reading") by David Howells, 2024-07-02. Merged in v6.10.) which no longer has this issue. Asking for either analysis of enclosed patch to be included into Stable or if there is another/better way to fix. -- You received this bug notification because you are a member of Ubuntu Bugs, which is subscribed to Ubuntu. https://bugs.launchpad.net/bugs/2144592 Title: Punching hole through CephFS hosted file causes corruption when crossing 4MB RADOS object boundary To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2144592/+subscriptions -- ubuntu-bugs mailing list [email protected] https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs
