kernel_samsung_a53x/fs/nfs
Josef Bacik e0841e3344 nfs: fix UAF in direct writes
[ Upstream commit 17f46b803d4f23c66cacce81db35fef3adb8f2af ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-19 09:22:34 +01:00
..
blocklayout blocklayoutdriver: Fix reference leak of pnfs_device_node 2024-11-18 12:12:27 +01:00
filelayout Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
flexfilelayout Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cache_lib.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cache_lib.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
callback.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
callback.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
callback_proc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
callback_xdr.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
client.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
delegation.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
delegation.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dir.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
direct.c nfs: fix UAF in direct writes 2024-11-19 09:22:34 +01:00
dns_resolve.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dns_resolve.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
export.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
file.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
fs_context.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
fscache-index.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
fscache.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
fscache.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
getroot.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
inode.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
internal.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
io.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
iostat.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Kconfig Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Makefile Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mount_clnt.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
namespace.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
netns.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs2super.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs2xdr.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs3_fs.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs3acl.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs3client.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs3proc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs3super.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs3xdr.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs4_fs.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs4client.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs4file.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs4getroot.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs4idmap.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs4idmap.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs4namespace.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs4proc.c NFSv4.2: fix nfs4_listxattr kernel BUG at mm/usercopy.c:102 2024-11-19 08:44:57 +01:00
nfs4renewd.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs4session.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs4session.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs4state.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs4super.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs4sysctl.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs4trace.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs4trace.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs4xdr.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs42.h NFSv4.2: fix listxattr maximum XDR buffer size 2024-11-19 08:44:57 +01:00
nfs42proc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs42xattr.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs42xdr.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfsroot.c NFS: Fix an off by one in root_nfs_cat() 2024-11-19 08:44:57 +01:00
nfstrace.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfstrace.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pagelist.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pnfs.c pNFS: Fix a hang in nfs4_evict_inode() 2024-11-08 11:26:19 +01:00
pnfs.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pnfs_dev.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pnfs_nfs.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
proc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
read.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
super.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
symlink.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sysctl.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sysfs.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sysfs.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
unlink.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
write.c nfs: fix UAF in direct writes 2024-11-19 09:22:34 +01:00