linux/fs/nilfs2
Ryusuke Konishi 607dc724b1 nilfs2: handle errors that nilfs_prepare_chunk() may return
commit ee70999a98 upstream.

Patch series "nilfs2: fix issues with rename operations".

This series fixes BUG_ON check failures reported by syzbot around rename
operations, and a minor behavioral issue where the mtime of a child
directory changes when it is renamed instead of moved.


This patch (of 2):

The directory manipulation routines nilfs_set_link() and
nilfs_delete_entry() rewrite the directory entry in the folio/page
previously read by nilfs_find_entry(), so error handling is omitted on the
assumption that nilfs_prepare_chunk(), which prepares the buffer for
rewriting, will always succeed for these.  And if an error is returned, it
triggers the legacy BUG_ON() checks in each routine.

This assumption is wrong, as proven by syzbot: the buffer layer called by
nilfs_prepare_chunk() may call nilfs_get_block() if necessary, which may
fail due to metadata corruption or other reasons.  This has been there all
along, but improved sanity checks and error handling may have made it more
reproducible in fuzzing tests.

Fix this issue by adding missing error paths in nilfs_set_link(),
nilfs_delete_entry(), and their caller nilfs_rename().

Link: https://lkml.kernel.org/r/20250111143518.7901-1-konishi.ryusuke@gmail.com
Link: https://lkml.kernel.org/r/20250111143518.7901-2-konishi.ryusuke@gmail.com
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Reported-by: syzbot+32c3706ebf5d95046ea1@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=32c3706ebf5d95046ea1
Reported-by: syzbot+1097e95f134f37d9395c@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=1097e95f134f37d9395c
Fixes: 2ba466d74e ("nilfs2: directory entry operations")
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2025-03-13 12:51:12 +01:00
..
alloc.c nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-18 13:07:36 +02:00
alloc.h nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-18 13:07:36 +02:00
bmap.c nilfs2: fix infinite loop in nilfs_mdt_get_block() 2023-05-11 23:00:39 +09:00
bmap.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
btnode.c nilfs2: fix null-ptr-deref in block_dirty_buffer tracepoint 2024-12-14 19:50:36 +01:00
btnode.h nilfs2: fix lockdep warnings in page operations for btree nodes 2022-05-25 09:57:26 +02:00
btree.c nilfs2: fix potential oob read in nilfs_btree_check_delete() 2024-10-17 15:10:58 +02:00
btree.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
cpfile.c nilfs2: fix typos in comments 2021-05-06 19:24:13 -07:00
cpfile.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
dat.c nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-18 13:07:36 +02:00
dat.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
dir.c nilfs2: handle errors that nilfs_prepare_chunk() may return 2025-03-13 12:51:12 +01:00
direct.c nilfs2: fix failure to detect DAT corruption in btree and direct mappings 2024-04-10 16:18:42 +02:00
direct.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
export.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
file.c nilfs2: fix hang in nilfs_lookup_dirty_data_buffers() 2024-02-23 08:55:08 +01:00
gcinode.c nilfs2: fix null-ptr-deref in block_dirty_buffer tracepoint 2024-12-14 19:50:36 +01:00
ifile.c nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-18 13:07:36 +02:00
ifile.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
inode.c nilfs2: do not output warnings when clearing dirty buffers 2025-03-13 12:50:45 +01:00
ioctl.c nilfs2: fix out-of-range warning 2024-06-16 13:39:16 +02:00
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mdt.c nilfs2: do not output warnings when clearing dirty buffers 2025-03-13 12:50:45 +01:00
mdt.h nilfs2: fix lockdep warnings during disk space reclamation 2022-05-25 09:57:26 +02:00
namei.c nilfs2: handle errors that nilfs_prepare_chunk() may return 2025-03-13 12:51:12 +01:00
nilfs.h nilfs2: handle errors that nilfs_prepare_chunk() may return 2025-03-13 12:51:12 +01:00
page.c nilfs2: do not force clear folio if buffer is referenced 2025-03-13 12:50:45 +01:00
page.h nilfs2: do not output warnings when clearing dirty buffers 2025-03-13 12:50:45 +01:00
recovery.c nilfs2: fix missing cleanup on rollforward recovery error 2024-09-12 11:07:44 +02:00
segbuf.c nilfs2: fix buffer corruption due to concurrent device reads 2023-06-28 10:29:42 +02:00
segbuf.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
segment.c nilfs2: protect access to buffers with no active references 2025-03-13 12:50:45 +01:00
segment.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
sufile.c nilfs2: prevent WARNING in nilfs_sufile_set_segment_usage() 2023-12-13 18:36:43 +01:00
sufile.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
super.c nilfs2: fix buffer corruption due to concurrent device reads 2023-06-28 10:29:42 +02:00
sysfs.c nilfs2: protect references to superblock parameters exposed in sysfs 2024-09-12 11:07:52 +02:00
sysfs.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
the_nilfs.c nilfs2: fix inode number range checks 2024-07-18 13:07:32 +02:00
the_nilfs.h nilfs2: fix inode number range checks 2024-07-18 13:07:32 +02:00