linux-stable/fs/nilfs2
Ryusuke Konishi 614d397be0 nilfs2: fix potential kernel bug due to lack of writeback flag waiting
commit a4ca369ca2 upstream.

Destructive writes to a block device on which nilfs2 is mounted can cause
a kernel bug in the folio/page writeback start routine or writeback end
routine (__folio_start_writeback in the log below):

 kernel BUG at mm/page-writeback.c:3070!
 Oops: invalid opcode: 0000 [#1] PREEMPT SMP KASAN PTI
 ...
 RIP: 0010:__folio_start_writeback+0xbaa/0x10e0
 Code: 25 ff 0f 00 00 0f 84 18 01 00 00 e8 40 ca c6 ff e9 17 f6 ff ff
  e8 36 ca c6 ff 4c 89 f7 48 c7 c6 80 c0 12 84 e8 e7 b3 0f 00 90 <0f>
  0b e8 1f ca c6 ff 4c 89 f7 48 c7 c6 a0 c6 12 84 e8 d0 b3 0f 00
 ...
 Call Trace:
  <TASK>
  nilfs_segctor_do_construct+0x4654/0x69d0 [nilfs2]
  nilfs_segctor_construct+0x181/0x6b0 [nilfs2]
  nilfs_segctor_thread+0x548/0x11c0 [nilfs2]
  kthread+0x2f0/0x390
  ret_from_fork+0x4b/0x80
  ret_from_fork_asm+0x1a/0x30
  </TASK>

This is because when the log writer starts a writeback for segment summary
blocks or a super root block that use the backing device's page cache, it
does not wait for the ongoing folio/page writeback, resulting in an
inconsistent writeback state.

Fix this issue by waiting for ongoing writebacks when putting
folios/pages on the backing device into writeback state.

Link: https://lkml.kernel.org/r/20240530141556.4411-1-konishi.ryusuke@gmail.com
Fixes: 9ff05123e3 ("nilfs2: segment constructor")
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Tested-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-06-21 14:38:46 +02:00
..
alloc.c nilfs2: fix WARNING in mark_buffer_dirty due to discarded buffer reuse 2023-08-21 13:46:25 -07:00
alloc.h
bmap.c nilfs2: fix infinite loop in nilfs_mdt_get_block() 2023-05-06 10:10:07 -07:00
bmap.h
btnode.c nilfs2: fix incomplete buffer cleanup in nilfs_btnode_abort_change_key() 2023-06-12 11:31:49 -07:00
btnode.h fs/nilfs2: Use the enum req_op and blk_opf_t types 2022-07-14 12:14:33 -06:00
btree.c nilfs2: fix failure to detect DAT corruption in btree and direct mappings 2024-04-03 15:28:34 +02:00
btree.h
cpfile.c
cpfile.h
dat.c nilfs2: prevent WARNING in nilfs_dat_commit_end() 2023-02-02 22:50:10 -08:00
dat.h
dir.c nilfs2: fix nilfs_empty_dir() misjudgment and long loop on I/O errors 2024-06-21 14:38:22 +02:00
direct.c nilfs2: fix failure to detect DAT corruption in btree and direct mappings 2024-04-03 15:28:34 +02:00
direct.h
export.h
file.c nilfs2: fix hang in nilfs_lookup_dirty_data_buffers() 2024-02-23 09:25:11 +01:00
gcinode.c nilfs2: fix potential use after free in nilfs_gccache_submit_read_data() 2023-09-29 17:20:46 -07:00
ifile.c
ifile.h
inode.c nilfs2: prevent kernel bug at submit_bh_wbc() 2024-04-03 15:28:34 +02:00
ioctl.c nilfs2: fix out-of-range warning 2024-06-12 11:11:31 +02:00
Kconfig fs: add CONFIG_BUFFER_HEAD 2023-08-02 09:13:09 -06:00
Makefile
mdt.c nilfs2: replace obvious uses of b_page with b_folio 2023-01-18 17:12:41 -08:00
mdt.h nilfs2: fix lockdep warnings during disk space reclamation 2022-04-01 11:46:09 -07:00
namei.c nilfs2: convert to ctime accessor functions 2023-07-24 10:30:02 +02:00
nilfs.h fs: port ->permission() to pass mnt_idmap 2023-01-19 09:24:28 +01:00
page.c nilfs2: prevent general protection fault in nilfs_clear_dirty_page() 2023-06-19 13:19:35 -07:00
page.h nilfs2: get rid of nilfs_mapping_init() 2022-04-01 11:46:09 -07:00
recovery.c nilfs2: fix data corruption in dsync block recovery for small block sizes 2024-02-23 09:25:11 +01:00
segbuf.c nilfs2: fix buffer corruption due to concurrent device reads 2023-06-19 13:19:33 -07:00
segbuf.h
segment.c nilfs2: fix potential kernel bug due to lack of writeback flag waiting 2024-06-21 14:38:46 +02:00
segment.h
sufile.c nilfs2: prevent WARNING in nilfs_sufile_set_segment_usage() 2023-12-13 18:45:22 +01:00
sufile.h
super.c nilfs2: use setup_bdev_super to de-duplicate the mount code 2023-08-10 10:34:56 +02:00
sysfs.c
sysfs.h
the_nilfs.c nilfs2: fix missing error check for sb_set_blocksize call 2023-12-13 18:45:22 +01:00
the_nilfs.h nilfs2: fix use-after-free of nilfs_root in dirtying inodes via iput 2023-08-04 13:03:43 -07:00