linux-stable/fs
Josef Bacik 5ada9016b1 nfs: fix panic when nfs4_ff_layout_prepare_ds() fails
[ Upstream commit 719fcafe07 ]

We've been seeing the following panic in production

BUG: kernel NULL pointer dereference, address: 0000000000000065
PGD 2f485f067 P4D 2f485f067 PUD 2cc5d8067 PMD 0
RIP: 0010:ff_layout_cancel_io+0x3a/0x90 [nfs_layout_flexfiles]
Call Trace:
 <TASK>
 ? __die+0x78/0xc0
 ? page_fault_oops+0x286/0x380
 ? __rpc_execute+0x2c3/0x470 [sunrpc]
 ? rpc_new_task+0x42/0x1c0 [sunrpc]
 ? exc_page_fault+0x5d/0x110
 ? asm_exc_page_fault+0x22/0x30
 ? ff_layout_free_layoutreturn+0x110/0x110 [nfs_layout_flexfiles]
 ? ff_layout_cancel_io+0x3a/0x90 [nfs_layout_flexfiles]
 ? ff_layout_cancel_io+0x6f/0x90 [nfs_layout_flexfiles]
 pnfs_mark_matching_lsegs_return+0x1b0/0x360 [nfsv4]
 pnfs_error_mark_layout_for_return+0x9e/0x110 [nfsv4]
 ? ff_layout_send_layouterror+0x50/0x160 [nfs_layout_flexfiles]
 nfs4_ff_layout_prepare_ds+0x11f/0x290 [nfs_layout_flexfiles]
 ff_layout_pg_init_write+0xf0/0x1f0 [nfs_layout_flexfiles]
 __nfs_pageio_add_request+0x154/0x6c0 [nfs]
 nfs_pageio_add_request+0x26b/0x380 [nfs]
 nfs_do_writepage+0x111/0x1e0 [nfs]
 nfs_writepages_callback+0xf/0x30 [nfs]
 write_cache_pages+0x17f/0x380
 ? nfs_pageio_init_write+0x50/0x50 [nfs]
 ? nfs_writepages+0x6d/0x210 [nfs]
 ? nfs_writepages+0x6d/0x210 [nfs]
 nfs_writepages+0x125/0x210 [nfs]
 do_writepages+0x67/0x220
 ? generic_perform_write+0x14b/0x210
 filemap_fdatawrite_wbc+0x5b/0x80
 file_write_and_wait_range+0x6d/0xc0
 nfs_file_fsync+0x81/0x170 [nfs]
 ? nfs_file_mmap+0x60/0x60 [nfs]
 __x64_sys_fsync+0x53/0x90
 do_syscall_64+0x3d/0x90
 entry_SYSCALL_64_after_hwframe+0x46/0xb0

Inspecting the core with drgn I was able to pull this

  >>> prog.crashed_thread().stack_trace()[0]
  #0 at 0xffffffffa079657a (ff_layout_cancel_io+0x3a/0x84) in ff_layout_cancel_io at fs/nfs/flexfilelayout/flexfilelayout.c:2021:27
  >>> prog.crashed_thread().stack_trace()[0]['idx']
  (u32)1
  >>> prog.crashed_thread().stack_trace()[0]['flseg'].mirror_array[1].mirror_ds
  (struct nfs4_ff_layout_ds *)0xffffffffffffffed

This is clear from the stack trace, we call nfs4_ff_layout_prepare_ds()
which could error out initializing the mirror_ds, and then we go to
clean it all up and our check is only for if (!mirror->mirror_ds).  This
is inconsistent with the rest of the users of mirror_ds, which have

  if (IS_ERR_OR_NULL(mirror_ds))

to keep from tripping over this exact scenario.  Fix this up in
ff_layout_cancel_io() to make sure we don't panic when we get an error.
I also spot checked all the other instances of checking mirror_ds and we
appear to be doing the correct checks everywhere, only unconditionally
dereferencing mirror_ds when we know it would be valid.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Fixes: b739a5bd9d ("NFSv4/flexfiles: Cancel I/O if the layout is recalled or revoked")
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-03-26 18:18:49 -04:00
..
9p 9p: Fix initialisation of netfs_inode for 9p 2024-02-05 20:17:04 +00:00
adfs
affs vfs-6.7.fsid 2023-11-07 12:11:26 -08:00
afs afs: Revert "afs: Hide silly-rename files from userspace" 2024-03-26 18:18:49 -04:00
autofs autofs: add: new_inode check in autofs_fill_super() 2023-11-20 14:56:36 +01:00
bcachefs bcachefs: time_stats: Check for last_event == 0 when updating freq stats 2024-02-16 19:14:31 +01:00
befs vfs-6.7.fsid 2023-11-07 12:11:26 -08:00
bfs
btrfs btrfs: fix data race at btrfs_use_block_rsv() when accessing block reserve 2024-03-26 18:17:54 -04:00
cachefiles cachefiles: fix memory leak in cachefiles_add_cache() 2024-03-01 13:41:47 +01:00
ceph ceph: add ceph_cap_unlink_work to fire check_caps() immediately 2024-03-26 18:17:50 -04:00
coda
configfs
cramfs vfs-6.7.ctime 2023-10-30 09:47:13 -10:00
crypto This update includes the following changes: 2023-11-02 16:15:30 -10:00
debugfs debugfs: initialize cancellations earlier 2023-12-22 07:33:02 +01:00
devpts
dlm dlm: use kernel_connect() and kernel_bind() 2024-01-31 16:21:00 -08:00
ecryptfs ecryptfs: Reject casefold directory inodes 2024-02-05 20:16:48 +00:00
efivarfs efivarfs: Request at most 512 bytes for variable names 2024-03-06 14:53:57 +00:00
efs vfs-6.7.fsid 2023-11-07 12:11:26 -08:00
erofs erofs: fix lockdep false positives on initializing erofs_pseudo_mnt 2024-03-26 18:18:26 -04:00
exfat exfat: fix ctime is not updated 2023-11-03 22:24:11 +09:00
exportfs fs: fix build error with CONFIG_EXPORTFS=m or not defined 2023-10-28 16:16:19 +02:00
ext2 quota: Properly annotate i_dquot arrays with __rcu 2024-03-26 18:18:32 -04:00
ext4 quota: Properly annotate i_dquot arrays with __rcu 2024-03-26 18:18:32 -04:00
f2fs f2fs: zone: fix to remove pow2 check condition for zoned block device 2024-03-26 18:18:49 -04:00
fat vfs-6.7.fsid 2023-11-07 12:11:26 -08:00
freevxfs vfs-6.7.fsid 2023-11-07 12:11:26 -08:00
fscache netfs, fscache: Prevent Oops in fscache_put_cache() 2024-01-31 16:21:06 -08:00
fuse fuse: disable FOPEN_PARALLEL_DIRECT_WRITES with FUSE_DIRECT_IO_ALLOW_MMAP 2023-12-04 10:19:32 +01:00
gfs2 gfs2: fix kernel BUG in gfs2_quota_cleanup 2024-01-25 15:44:43 -08:00
hfs vfs-6.7.ctime 2023-10-30 09:47:13 -10:00
hfsplus vfs-6.7.ctime 2023-10-30 09:47:13 -10:00
hostfs
hpfs
hugetlbfs mm: hugetlb pages should not be reserved by shmat() if SHM_NORESERVE 2024-02-23 09:51:56 +01:00
iomap iomap: clear the per-folio dirty bits on all writeback failures 2024-03-26 18:17:58 -04:00
isofs
jbd2 jbd2: fix soft lockup in journal_finish_inode_data_buffers() 2023-12-12 10:25:46 -05:00
jffs2 vfs-6.7.fsid 2023-11-07 12:11:26 -08:00
jfs quota: Properly annotate i_dquot arrays with __rcu 2024-03-26 18:18:32 -04:00
kernfs fs/kernfs/dir: obey S_ISGID 2024-02-05 20:17:04 +00:00
lockd
minix
netfs
nfs nfs: fix panic when nfs4_ff_layout_prepare_ds() fails 2024-03-26 18:18:49 -04:00
nfs_common
nfsd nfsd: don't take fi_lock in nfsd_break_deleg_cb() 2024-02-23 09:51:59 +01:00
nilfs2 nilfs2: fix potential bug in end_buffer_async_write 2024-02-23 09:51:59 +01:00
nls
notify vfs-6.7.fsid 2023-11-07 12:11:26 -08:00
ntfs vfs-6.7.fsid 2023-11-07 12:11:26 -08:00
ntfs3 fs/ntfs3: fix build without CONFIG_NTFS3_LZX_XPRESS 2024-03-02 18:23:50 +01:00
ocfs2 quota: Properly annotate i_dquot arrays with __rcu 2024-03-26 18:18:32 -04:00
omfs
openpromfs
orangefs vfs-6.7.ctime 2023-10-30 09:47:13 -10:00
overlayfs ovl: Always reject mounting over case-insensitive directories 2024-03-26 18:17:59 -04:00
proc fs/proc: do_task_stat: use sig->stats_lock to gather the threads/children stats 2024-02-23 09:51:58 +01:00
pstore pstore: inode: Only d_invalidate() is needed 2024-03-26 18:18:20 -04:00
qnx4
qnx6
quota quota: Properly annotate i_dquot arrays with __rcu 2024-03-26 18:18:32 -04:00
ramfs
reiserfs quota: Properly annotate i_dquot arrays with __rcu 2024-03-26 18:18:32 -04:00
romfs vfs-6.7.ctime 2023-10-30 09:47:13 -10:00
smb cifs: Fix writeback data corruption 2024-03-26 18:18:43 -04:00
squashfs squashfs: squashfs_read_data need to check if the length is 0 2023-12-06 16:12:45 -08:00
sysfs
sysv
tracefs eventfs: Keep all directory links at 1 2024-02-23 09:51:45 +01:00
ubifs ubifs: ubifs_symlink: Fix memleak of inode->i_link in error path 2024-01-31 16:21:02 -08:00
udf \n 2023-11-02 08:19:51 -10:00
ufs fix ufs_get_locked_folio() breakage 2023-12-13 11:14:09 -05:00
unicode
vboxsf
verity
xfs xfs: read only mounts with fsopen mount API are busted 2024-01-31 16:21:12 -08:00
zonefs zonefs: Improve error handling 2024-02-23 09:51:53 +01:00
aio.c fs/aio: Restrict kiocb_set_cancel_fn() to I/O submitted via libaio 2024-03-01 13:41:46 +01:00
anon_inodes.c
attr.c
bad_inode.c
binfmt_elf.c
binfmt_elf_fdpic.c execve updates for v6.7-rc1 2023-10-30 19:28:19 -10:00
binfmt_elf_test.c
binfmt_flat.c
binfmt_misc.c execve updates for v6.7-rc1 2023-10-30 19:28:19 -10:00
binfmt_script.c
buffer.c As usual, lots of singleton and doubleton patches all over the tree and 2023-11-02 20:53:31 -10:00
char_dev.c As usual, lots of singleton and doubleton patches all over the tree and 2023-11-02 20:53:31 -10:00
compat_binfmt_elf.c
coredump.c
d_path.c
dax.c
dcache.c fast_dput(): handle underflows gracefully 2024-02-05 20:16:57 +00:00
direct-io.c
drop_caches.c
eventfd.c
eventpoll.c
exec.c exec: Fix error handling in begin_new_exec() 2024-01-31 16:21:11 -08:00
fcntl.c fs: Fix rw_hint validation 2024-03-26 18:17:58 -04:00
fhandle.c do_sys_name_to_handle(): use kzalloc() to fix kernel-infoleak 2024-03-26 18:17:57 -04:00
file.c file, i915: fix file reference for mmap_singleton() 2023-10-25 22:17:04 +02:00
file_table.c As usual, lots of singleton and doubleton patches all over the tree and 2023-11-02 20:53:31 -10:00
filesystems.c
fs-writeback.c vfs-6.7.misc 2023-10-30 09:14:19 -10:00
fs_context.c
fs_parser.c
fs_pin.c
fs_struct.c
fs_types.c
fsopen.c
init.c
inode.c filemap: add a per-mapping stable writes flag 2023-11-20 15:05:18 +01:00
internal.h
ioctl.c lsm: new security_file_ioctl_compat() hook 2024-01-31 16:21:00 -08:00
Kconfig mm/hugetlb: have CONFIG_HUGETLB_PAGE select CONFIG_XARRAY_MULTI 2023-12-06 16:12:49 -08:00
Kconfig.binfmt
kernel_read_file.c
libfs.c libfs: getdents() should return 0 after reaching EOD 2023-11-20 15:34:22 +01:00
locks.c As usual, lots of singleton and doubleton patches all over the tree and 2023-11-02 20:53:31 -10:00
Makefile
mbcache.c
mnt_idmapping.c fs: export mnt_idmap_get/mnt_idmap_put 2023-11-03 23:28:33 +01:00
mount.h
mpage.c buffer: remove folio_create_empty_buffers() 2023-10-25 16:47:10 -07:00
namei.c new helper: user_path_locked_at() 2024-02-16 19:14:30 +01:00
namespace.c fs: relax mount_setattr() permission checks 2024-02-23 09:51:55 +01:00
nsfs.c
open.c cred: get rid of CONFIG_DEBUG_CREDENTIALS 2023-12-15 14:19:48 -08:00
pipe.c pipe: wakeup wr_wait after setting max_usage 2024-01-31 16:20:53 -08:00
pnode.c
pnode.h
posix_acl.c
proc_namespace.c
read_write.c
readdir.c
remap_range.c
select.c fs/select: rework stack allocation hack for clang 2024-03-26 18:17:59 -04:00
seq_file.c
signalfd.c
splice.c
stack.c
stat.c fs: Pass AT_GETATTR_NOSEC flag to getattr interface function 2023-11-18 14:54:07 +01:00
statfs.c
super.c overlayfs update for 6.7-rc1 2023-11-07 11:46:31 -08:00
sync.c
sysctls.c
timerfd.c
userfaultfd.c As usual, lots of singleton and doubleton patches all over the tree and 2023-11-02 20:53:31 -10:00
utimes.c
xattr.c