Hello, __writeback_single_inode() clears I_METADATA_WRITEBACK before calling ->sync_inode_metadata(), and does not restore it when the callback fails. The inode's I_DIRTY bits were already cleared in the same writeback pass. For ext2, the failed inode-table buffer has also lost its dirty bit before the write is submitted. A later fsync() on an independently opened file descriptor therefore sees no dirty state, no I_METADATA_WRITEBACK and no file-mapping error, and returns success even though the metadata change (fchmod) was never persisted. A subsequent clean unmount and remount shows the old mode. The PoC uses QEMU's blkdebug driver to fail the first write_aio to the inode-table sector of an ext2 or no-journal ext4 image. It compares the first and second fsync on the same fd, an fsync on an independent pre-opened fd, syncfs, and the on-disk mode after dropping the block device cache and remounting. The no-fault control persists the mode. This is a durability correctness bug, not memory corruption or privilege escalation. Restore I_METADATA_WRITEBACK when the callback fails and record the error in the file mapping with mapping_set_error(). The restored flag makes later data-integrity fsyncs retry and re-report the failure; the mapping error makes it visible to independent file descriptors through file_check_and_advance_wb_err() and to syncfs() through the superblock error. This does not make the failed metadata write succeed; it turns a false success into a reported EIO. HEAD commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc git tree: fe970b05333fb8e41da21e9e289f652abcc7cba7 source version: Linux 7.4.0-rc4 compiler: gcc 11.4.0, GNU ld 2.38 QEMU: 6.2.0, x86-64 TCG Console output: https://gist.githubusercontent.com/ForestHYS/a863cdcd092e9c40690a9f70a91c2216/raw/5b87bdbe82f974517847aa451f67c890c69d233c/console-output.txt Kernel config: https://gist.githubusercontent.com/ForestHYS/a863cdcd092e9c40690a9f70a91c2216/raw/5b87bdbe82f974517847aa451f67c890c69d233c/kernel-config.txt PoC source (save as poc_init.c): https://gist.githubusercontent.com/ForestHYS/a863cdcd092e9c40690a9f70a91c2216/raw/5b87bdbe82f974517847aa451f67c890c69d233c/poc.c Fault harness (save as run.sh): https://gist.githubusercontent.com/ForestHYS/a863cdcd092e9c40690a9f70a91c2216/raw/5b87bdbe82f974517847aa451f67c890c69d233c/run.sh Fixed-kernel console: https://gist.githubusercontent.com/ForestHYS/a863cdcd092e9c40690a9f70a91c2216/raw/5b87bdbe82f974517847aa451f67c890c69d233c/fixed-console-output.txt Build the test kernel from the commit above with the attached config: mkdir -p build cp kernel-config.txt build/.config make O=build olddefconfig make O=build -j"$(nproc)" bzImage The harness creates the ext2 and no-journal ext4 images, computes the inode-table sector with mke2fs and debugfs, and runs QEMU with a blkdebug write_aio fault on that sector. Put the files in the layout the harness expects and run it: mkdir -p repro poc artifacts cp run.sh repro/run.sh cp poc.c poc/poc_init.c CODE_REPAIR_SOURCE="$PWD/build" \ CODE_REPAIR_ARTIFACT_DIR="$PWD/artifacts" \ sh repro/run.sh The harness needs qemu-system-x86_64, mke2fs and debugfs. It runs meta, meta_b, meta4, meta4_b, the no-fault controls, and a data-error control. On the unmodified ext2 image the first fsync returned EIO, the second fsync and an independent fd's fsync returned 0, syncfs returned EIO, and the remounted mode was 0644. With this patch the second fsync, the independent fd's fsync and syncfs all return EIO; the remounted mode remains 0644 because the failed write was not retried successfully, but the failure is no longer reported as success. The no-fault ext2/ext4 controls persist 0601, and the data-error control still reports EIO on the independent fd. Fixes: c474bc56b6d1 ("fs: Provide way for filesystem to wait for metadata writeback") Signed-off-by: ForestHYS --- Validation: scripts/checkpatch.pl --no-tree --strict reports no errors or warnings, and git apply --check succeeds. The patched kernel was built and booted; the metadata fault cases report EIO on all later fsync/syncfs paths, and the no-fault and data-error controls pass. diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 15260cf2a..6e62c955a 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -1886,6 +1886,10 @@ __writeback_single_inode(struct inode *inode, struct writeback_control *wbc) inode_state_clear(inode, I_METADATA_WRITEBACK); spin_unlock(&inode->i_lock); err = inode->i_sb->s_op->sync_inode_metadata(inode, wbc); + if (err) { + set_inode_metadata_writeback(inode); + mapping_set_error(mapping, err); + } if (ret == 0) ret = err; } Thanks, Forest Huang