linux-stable/fs/nfsd
Dai Ngo 6ea71246b7 NFSD: fix use-after-free on source server when doing inter-server copy
[ Upstream commit 019805fea9 ]

Use-after-free occurred when the laundromat tried to free expired
cpntf_state entry on the s2s_cp_stateids list after inter-server
copy completed. The sc_cp_list that the expired copy state was
inserted on was already freed.

When COPY completes, the Linux client normally sends LOCKU(lock_state x),
FREE_STATEID(lock_state x) and CLOSE(open_state y) to the source server.
The nfs4_put_stid call from nfsd4_free_stateid cleans up the copy state
from the s2s_cp_stateids list before freeing the lock state's stid.

However, sometimes the CLOSE was sent before the FREE_STATEID request.
When this happens, the nfsd4_close_open_stateid call from nfsd4_close
frees all lock states on its st_locks list without cleaning up the copy
state on the sc_cp_list list. When the time the FREE_STATEID arrives the
server returns BAD_STATEID since the lock state was freed. This causes
the use-after-free error to occur when the laundromat tries to free
the expired cpntf_state.

This patch adds a call to nfs4_free_cpntf_statelist in
nfsd4_close_open_stateid to clean up the copy state before calling
free_ol_stateid_reaplist to free the lock state's stid on the reaplist.

Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-10-24 09:58:10 +02:00
..
Kconfig NFSD: Remove CONFIG_NFSD_V3 2022-03-11 10:25:14 -05:00
Makefile NFSD: Remove CONFIG_NFSD_V3 2022-03-11 10:25:14 -05:00
acl.h nfsd: eliminate an unnecessary acl size limit 2019-08-28 21:13:45 -04:00
auth.c nfsd: auth: Fix gid sorting when rootsquash enabled 2018-01-22 20:13:07 -08:00
auth.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
blocklayout.c block: remove genhd.h 2022-02-02 07:49:59 -07:00
blocklayoutxdr.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
blocklayoutxdr.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
cache.h nfsd4: make drc_slab global, not per-net 2020-06-01 17:44:45 -04:00
current_stateid.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
export.c fs: add is_idmapped_mnt() helper 2021-12-03 18:44:06 +01:00
export.h nfsd: report per-export stats 2021-01-25 09:36:28 -05:00
fault_inject.c nfsd: no need to check return value of debugfs_create functions 2019-07-03 16:57:17 +02:00
filecache.c nfsd: eliminate the NFSD_FILE_BREAK_* flags 2022-08-17 15:13:40 +02:00
filecache.h nfsd: eliminate the NFSD_FILE_BREAK_* flags 2022-08-17 15:13:40 +02:00
flexfilelayout.c nfsd: use correct format characters 2022-03-17 19:47:38 -04:00
flexfilelayoutxdr.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
flexfilelayoutxdr.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
idmap.h nfsd: Remove duplicate define of IDMAP_NAMESZ/IDMAP_TYPE_xx 2015-07-20 14:58:46 -04:00
lockd.c NFSD: simplify struct nfsfh 2021-10-02 15:51:10 -04:00
netns.h NFSD: Rename boot verifier functions 2022-01-08 14:42:02 -05:00
nfs2acl.c SUNRPC: Return true/false (not 1/0) from bool functions 2022-03-27 23:25:52 -04:00
nfs3acl.c SUNRPC: Change return value type of .pc_encode 2021-10-13 11:34:49 -04:00
nfs3proc.c NFSD: Protect against send buffer overflow in NFSv3 READ 2022-10-24 09:56:50 +02:00
nfs3xdr.c NFSD: Deprecate NFS_OFFSET_MAX 2022-02-09 09:24:40 -05:00
nfs4acl.c acl: handle idmapped mounts 2021-01-24 14:27:17 +01:00
nfs4callback.c NFSD: simplify struct nfsfh 2021-10-02 15:51:10 -04:00
nfs4idmap.c nfsd: Use seq_putc() in two functions 2020-07-13 17:28:46 -04:00
nfs4layouts.c nfsd: fix using the correct variable for sizeof() 2022-03-20 12:49:38 -04:00
nfs4proc.c NFSD: Fix handling of oversized NFSv4 COMPOUND requests 2022-10-24 09:57:04 +02:00
nfs4recover.c nfsd: Fix a memory leak in an error handling path 2022-10-24 09:57:03 +02:00
nfs4state.c NFSD: fix use-after-free on source server when doing inter-server copy 2022-10-24 09:58:10 +02:00
nfs4xdr.c NFSD: Return nfserr_serverfault if splice_ok but buf->pages have data 2022-10-24 09:58:10 +02:00
nfscache.c nfsd: destroy percpu stats counters after reply cache shutdown 2022-05-23 15:22:17 -04:00
nfsctl.c nfsd: Fix null-ptr-deref in nfsd_fill_super() 2022-05-23 11:06:29 -04:00
nfsd.h NFSD: Decode NFSv4 birth time attribute 2022-07-11 13:52:22 -04:00
nfsfh.c NFSD: Remove CONFIG_NFSD_V3 2022-03-11 10:25:14 -05:00
nfsfh.h NFSD: Remove CONFIG_NFSD_V3 2022-03-11 10:25:14 -05:00
nfsproc.c NFSD: Protect against send buffer overflow in NFSv2 READDIR 2022-10-24 09:57:04 +02:00
nfssvc.c NFSD: Remove CONFIG_NFSD_V3 2022-03-11 10:25:14 -05:00
nfsxdr.c SUNRPC: Change return value type of .pc_encode 2021-10-13 11:34:49 -04:00
pnfs.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
state.h NFSD: add courteous server support for thread with only delegation 2022-05-19 12:25:39 -04:00
stats.c nfsd: make nfsd_stats.th_cnt atomic_t 2021-12-13 13:42:51 -05:00
stats.h nfsd: make nfsd_stats.th_cnt atomic_t 2021-12-13 13:42:51 -05:00
trace.c NFSD: Add SPDX header for fs/nfsd/trace.c 2020-11-30 13:00:24 -05:00
trace.h nfsd: eliminate the NFSD_FILE_BREAK_* flags 2022-08-17 15:13:40 +02:00
vfs.c Notable regression fixes: 2022-07-02 11:20:56 -07:00
vfs.h NFSD: Clean up nfsd_open_verified() 2022-05-20 13:18:25 -04:00
xdr.h NFSD: prevent underflow in nfssvc_decode_writeargs() 2022-03-15 09:35:56 -04:00
xdr3.h SUNRPC: Change return value type of .pc_encode 2021-10-13 11:34:49 -04:00
xdr4.h NFSD: Fix handling of oversized NFSv4 COMPOUND requests 2022-10-24 09:57:04 +02:00
xdr4cb.h NFSD CB_OFFLOAD xdr 2018-09-25 20:34:54 -04:00