linux/fs/nilfs2
Ryusuke Konishi b3a033e3ec nilfs2: fix potential deadlock with newly created symlinks
Syzbot reported that page_symlink(), called by nilfs_symlink(), triggers
memory reclamation involving the filesystem layer, which can result in
circular lock dependencies among the reader/writer semaphore
nilfs->ns_segctor_sem, s_writers percpu_rwsem (intwrite) and the
fs_reclaim pseudo lock.

This is because after commit 21fc61c73c ("don't put symlink bodies in
pagecache into highmem"), the gfp flags of the page cache for symbolic
links are overwritten to GFP_KERNEL via inode_nohighmem().

This is not a problem for symlinks read from the backing device, because
the __GFP_FS flag is dropped after inode_nohighmem() is called.  However,
when a new symlink is created with nilfs_symlink(), the gfp flags remain
overwritten to GFP_KERNEL.  Then, memory allocation called from
page_symlink() etc.  triggers memory reclamation including the FS layer,
which may call nilfs_evict_inode() or nilfs_dirty_inode().  And these can
cause a deadlock if they are called while nilfs->ns_segctor_sem is held:

Fix this issue by dropping the __GFP_FS flag from the page cache GFP flags
of newly created symlinks in the same way that nilfs_new_inode() and
__nilfs_read_inode() do, as a workaround until we adopt nofs allocation
scope consistently or improve the locking constraints.

Link: https://lkml.kernel.org/r/20241020050003.4308-1-konishi.ryusuke@gmail.com
Fixes: 21fc61c73c ("don't put symlink bodies in pagecache into highmem")
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Reported-by: syzbot+9ef37ac20608f4836256@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9ef37ac20608f4836256
Tested-by: syzbot+9ef37ac20608f4836256@syzkaller.appspotmail.com
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-10-30 20:14:12 -07:00
..
alloc.c nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-03 19:30:16 -07:00
alloc.h nilfs2: fix incorrect kernel-doc declaration of nilfs_palloc_req structure 2024-09-01 20:43:36 -07:00
bmap.c nilfs2: fix missing initial short descriptions of kernel-doc comments 2024-09-01 20:43:37 -07:00
bmap.h nilfs2: use the BITS_PER_LONG macro 2024-09-01 20:43:42 -07:00
btnode.c nilfs2: improve kernel-doc comments for b-tree node helpers 2024-09-01 20:43:36 -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 potential oob read in nilfs_btree_check_delete() 2024-09-09 16:47:42 -07:00
btree.h nilfs2: add missing description of nilfs_btree_path structure 2024-09-01 20:43:36 -07:00
cpfile.c nilfs2: treat missing cpfile header block as metadata corruption 2024-09-01 20:43:39 -07:00
cpfile.h nilfs2: remove nilfs_cpfile_{get,put}_checkpoint() 2024-02-22 15:38:53 -08:00
dat.c nilfs2: fix missing initial short descriptions of kernel-doc comments 2024-09-01 20:43:37 -07:00
dat.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
dir.c nilfs2: propagate directory read errors from nilfs_find_entry() 2024-10-17 00:28:06 -07:00
direct.c nilfs2: fix failure to detect DAT corruption in btree and direct mappings 2024-03-14 09:17:29 -07:00
direct.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
export.h
file.c nilfs2: fix hang in nilfs_lookup_dirty_data_buffers() 2024-02-07 21:20:36 -08:00
gcinode.c nilfs2: add kernel-doc comments to nilfs_remove_all_gcinodes() 2024-04-25 21:07:08 -07:00
ifile.c nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-03 19:30:16 -07:00
ifile.h nilfs2: localize highmem mapping for checkpoint reading within cpfile 2024-02-22 15:38:53 -08:00
inode.c Many singleton patches - please see the various changelogs for details. 2024-09-21 08:20:50 -07:00
ioctl.c nilfs2: add missing argument descriptions for ioctl-related helpers 2024-09-01 20:43:35 -07:00
Kconfig fs: add CONFIG_BUFFER_HEAD 2023-08-02 09:13:09 -06:00
Makefile
mdt.c nilfs2: do not output warnings when clearing dirty buffers 2024-09-01 20:43:35 -07:00
mdt.h nilfs2: fix lockdep warnings during disk space reclamation 2022-04-01 11:46:09 -07:00
namei.c nilfs2: fix potential deadlock with newly created symlinks 2024-10-30 20:14:12 -07:00
nilfs.h nilfs2: propagate directory read errors from nilfs_find_entry() 2024-10-17 00:28:06 -07:00
page.c nilfs2: fix kernel bug due to missing clearing of checked flag 2024-10-28 21:40:40 -07:00
page.h nilfs2: do not output warnings when clearing dirty buffers 2024-09-01 20:43:35 -07:00
recovery.c Many singleton patches - please see the various changelogs for details. 2024-09-21 08:20:50 -07:00
segbuf.c nilfs2: convert segment buffer to use kmap_local 2024-02-22 15:38:53 -08:00
segbuf.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
segment.c Many singleton patches - please see the various changelogs for details. 2024-09-21 08:20:50 -07:00
segment.h nilfs2: use kthread_create and kthread_stop for the log writer thread 2024-09-01 20:43:44 -07:00
sufile.c nilfs2: do not propagate ENOENT error from nilfs_sufile_mark_dirty() 2024-09-01 20:43:40 -07:00
sufile.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
super.c nilfs2: separate inode type information from i_state field 2024-09-01 20:43:43 -07:00
sysfs.c nilfs2: protect references to superblock parameters exposed in sysfs 2024-09-01 17:59:00 -07:00
sysfs.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
the_nilfs.c nilfs2: eliminate the shared counter and spinlock for i_generation 2024-09-01 20:43:43 -07:00
the_nilfs.h nilfs2: eliminate the shared counter and spinlock for i_generation 2024-09-01 20:43:43 -07:00