linux/fs/nfs
Josef Bacik 17f46b803d nfs: fix UAF in direct writes
In production we have been hitting the following warning consistently

------------[ cut here ]------------
refcount_t: underflow; use-after-free.
WARNING: CPU: 17 PID: 1800359 at lib/refcount.c:28 refcount_warn_saturate+0x9c/0xe0
Workqueue: nfsiod nfs_direct_write_schedule_work [nfs]
RIP: 0010:refcount_warn_saturate+0x9c/0xe0
PKRU: 55555554
Call Trace:
 <TASK>
 ? __warn+0x9f/0x130
 ? refcount_warn_saturate+0x9c/0xe0
 ? report_bug+0xcc/0x150
 ? handle_bug+0x3d/0x70
 ? exc_invalid_op+0x16/0x40
 ? asm_exc_invalid_op+0x16/0x20
 ? refcount_warn_saturate+0x9c/0xe0
 nfs_direct_write_schedule_work+0x237/0x250 [nfs]
 process_one_work+0x12f/0x4a0
 worker_thread+0x14e/0x3b0
 ? ZSTD_getCParams_internal+0x220/0x220
 kthread+0xdc/0x120
 ? __btf_name_valid+0xa0/0xa0
 ret_from_fork+0x1f/0x30

This is because we're completing the nfs_direct_request twice in a row.

The source of this is when we have our commit requests to submit, we
process them and send them off, and then in the completion path for the
commit requests we have

if (nfs_commit_end(cinfo.mds))
	nfs_direct_write_complete(dreq);

However since we're submitting asynchronous requests we sometimes have
one that completes before we submit the next one, so we end up calling
complete on the nfs_direct_request twice.

The only other place we use nfs_generic_commit_list() is in
__nfs_commit_inode, which wraps this call in a

nfs_commit_begin();
nfs_commit_end();

Which is a common pattern for this style of completion handling, one
that is also repeated in the direct code with get_dreq()/put_dreq()
calls around where we process events as well as in the completion paths.

Fix this by using the same pattern for the commit requests.

Before with my 200 node rocksdb stress running this warning would pop
every 10ish minutes.  With my patch the stress test has been running for
several hours without popping.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Cc: stable@vger.kernel.org
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
2024-03-09 09:14:51 -05:00
..
blocklayout rpc_pipefs: Replace one label in bl_resolve_deviceid() 2024-01-04 10:47:56 -05:00
filelayout pnfs/filelayout: add tracepoint to getdeviceinfo 2024-02-28 16:18:19 -05:00
flexfilelayout hardening updates for v6.7-rc1 2023-10-30 19:09:55 -10:00
cache_lib.c
cache_lib.h
callback.c SUNRPC: discard sv_refcnt, and svc_get/svc_put 2024-01-07 17:54:33 -05:00
callback.h NFS Client Updates for Linux 6.8 2024-01-10 16:13:57 -08:00
callback_proc.c NFSv4.1: if referring calls are complete, trust the stateid argument 2024-01-04 10:47:56 -05:00
callback_xdr.c NFSv4.1: Use the nfs_client's rpc timeouts for backchannel 2024-01-04 17:01:01 -05:00
client.c nfs: make the rpc_stat per net namespace 2024-03-09 09:14:51 -05:00
delegation.c NFSv4: nfs4_do_open() is incorrectly triggering state recovery 2024-03-09 09:14:51 -05:00
delegation.h NFSv4: fairly test all delegations on a SEQ4_ revocation 2023-11-01 15:15:52 -04:00
dir.c nfs: make nfs_set_verifier() safe for use in RCU pathwalk 2024-02-25 02:10:31 -05:00
direct.c nfs: fix UAF in direct writes 2024-03-09 09:14:51 -05:00
dns_resolve.c NFS: Move common includes outside ifdef 2023-08-24 13:24:15 -04:00
dns_resolve.h NFS: Avoid memcpy() run-time warning for struct sockaddr overflows 2022-10-27 15:52:10 -04:00
export.c nfsd: allow reaping files still under writeback 2023-04-26 09:04:59 -04:00
file.c NFS Client Updates for Linux 6.8 2024-01-10 16:13:57 -08:00
fs_context.c NFS: Add an "xprtsec=" NFS mount option 2023-06-19 12:30:17 -04:00
fscache.c NFS: Fix nfs_netfs_issue_read() xarray locking for writeback interrupt 2024-03-09 09:14:38 -05:00
fscache.h netfs: Optimise away reads above the point at which there can be no data 2023-12-28 09:45:27 +00:00
getroot.c NFS: Remove the nfs4_label argument from nfs_setsecurity 2021-11-05 14:54:40 -04:00
inode.c nfs: make the rpc_stat per net namespace 2024-03-09 09:14:51 -05:00
internal.h nfs: make the rpc_stat per net namespace 2024-03-09 09:14:51 -05:00
io.c
iostat.h NFS: Remove all NFSIOS_FSCACHE counters due to conversion to netfs API 2023-04-11 13:08:26 -04:00
Kconfig netfs, fscache: Combine fscache with netfs 2023-12-24 15:08:46 +00:00
Makefile nfs: Convert to new fscache volume/cookie API 2022-01-10 11:53:25 +00:00
mount_clnt.c NFS: Avoid memcpy() run-time warning for struct sockaddr overflows 2022-10-27 15:52:10 -04:00
namespace.c fs: pass the request_mask to generic_fillattr 2023-08-09 08:56:36 +02:00
netns.h nfs: make the rpc_stat per net namespace 2024-03-09 09:14:51 -05:00
nfs.h nfs: move nfs4_xattr_handlers to .rodata 2023-10-09 16:24:20 +02:00
nfs2super.c
nfs2xdr.c NFS: Guard against READDIR loop when entry names exceed MAXNAMELEN 2023-08-30 11:08:27 -04:00
nfs3_fs.h fs: drop unused posix acl handlers 2023-03-06 09:57:12 +01:00
nfs3acl.c Mainly singleton patches all over the place. Series of note are: 2023-04-27 19:57:00 -07:00
nfs3client.c NFS: enable nconnect for RDMA 2024-03-09 09:14:51 -05:00
nfs3proc.c nfs: Convert nfs_symlink() to use a folio 2023-11-01 15:40:44 -04:00
nfs3super.c fs: drop unused posix acl handlers 2023-03-06 09:57:12 +01:00
nfs3xdr.c NFS: Guard against READDIR loop when entry names exceed MAXNAMELEN 2023-08-30 11:08:27 -04:00
nfs4_fs.h NFSv4: nfs4_do_open() is incorrectly triggering state recovery 2024-03-09 09:14:51 -05:00
nfs4client.c NFS: enable nconnect for RDMA 2024-03-09 09:14:51 -05:00
nfs4file.c fs: use splice_copy_file_range() inline helper 2023-12-12 16:20:02 +01:00
nfs4getroot.c
nfs4idmap.c cred: Do not default to init_cred in prepare_kernel_cred() 2022-11-01 10:04:52 -07:00
nfs4idmap.h
nfs4namespace.c NFS: Avoid memcpy() run-time warning for struct sockaddr overflows 2022-10-27 15:52:10 -04:00
nfs4proc.c NFSv4: nfs4_do_open() is incorrectly triggering state recovery 2024-03-09 09:14:51 -05:00
nfs4renewd.c
nfs4session.c NFSv4: Sanity check the parameters in nfs41_update_target_slotid() 2021-11-07 09:23:14 -05:00
nfs4session.h NFSv4: Sanity check the parameters in nfs41_update_target_slotid() 2021-11-07 09:23:14 -05:00
nfs4state.c NFSv4: nfs4_do_open() is incorrectly triggering state recovery 2024-03-09 09:14:51 -05:00
nfs4super.c nfs: fix regression in handling of fsc= option in NFSv4 2024-02-28 16:18:19 -05:00
nfs4sysctl.c fs: Remove the now superfluous sentinel elements from ctl_table array 2023-12-28 04:57:57 -08:00
nfs4trace.c pnfs/filelayout: add tracepoint to getdeviceinfo 2024-02-28 16:18:19 -05:00
nfs4trace.h NFSv4.1: add tracepoint to trunked nfs4_exchange_id calls 2024-03-09 09:14:50 -05:00
nfs4xdr.c NFSv4: Always ask for type with READDIR 2024-01-04 10:47:56 -05:00
nfs42.h NFSv4.2: fix listxattr maximum XDR buffer size 2024-02-28 16:18:18 -05:00
nfs42proc.c nfs42: client needs to strip file mode's suid/sgid bit after ALLOCATE op 2023-10-11 09:37:48 -04:00
nfs42xattr.c list_lru: allow explicit memcg and NUMA node selection 2023-12-12 10:57:01 -08:00
nfs42xdr.c NFSv4.2: Rework scratch handling for READ_PLUS (again) 2023-08-23 15:58:47 -04:00
nfsroot.c NFS: Fix an off by one in root_nfs_cat() 2024-03-09 09:14:51 -05:00
nfstrace.c
nfstrace.h NFS: drop unused nfs_direct_req bytes_left 2024-01-04 10:47:56 -05:00
pagelist.c NFS: Convert buffered read paths to use netfs when fscache is enabled 2023-04-11 13:08:26 -04:00
pnfs.c NFS: avoid infinite loop in pnfs_update_layout. 2024-03-09 09:14:51 -05:00
pnfs.h NFSv4/pnfs: Allow layoutget to return EAGAIN for softerr mounts 2023-10-22 19:47:56 -04:00
pnfs_dev.c NFSv4/pnfs: minor fix for cleanup path in nfs4_get_device_info 2023-08-24 13:24:15 -04:00
pnfs_nfs.c NFSv4.1/pnfs: fix NFS with TLS in pnfs 2024-03-09 09:14:51 -05:00
proc.c nfs: Convert nfs_symlink() to use a folio 2023-11-01 15:40:44 -04:00
read.c NFSv4.2: Rework scratch handling for READ_PLUS (again) 2023-08-23 15:58:47 -04:00
super.c NFS: Display the "fsc=" mount option if it is set 2024-02-28 16:18:18 -05:00
symlink.c fs: Change the type of filler_t 2022-05-09 16:36:48 -04:00
sysctl.c fs: Remove the now superfluous sentinel elements from ctl_table array 2023-12-28 04:57:57 -08:00
sysfs.c NFS: Fix sysfs server name memory leak 2023-08-19 10:26:29 -04:00
sysfs.h NFS: Add sysfs links to sunrpc clients for nfs_clients 2023-06-19 15:04:13 -04:00
unlink.c nfs: rename the nfs_async_rename_done tracepoint 2024-01-04 10:47:56 -05:00
write.c nfs: fix UAF in direct writes 2024-03-09 09:14:51 -05:00