]> git.baikalelectronics.ru Git - kernel.git/commit
nfsd: clean up potential nfsd_file refcount leaks in COPY codepath
authorJeff Layton <jlayton@kernel.org>
Tue, 17 Jan 2023 19:38:31 +0000 (14:38 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 10 Mar 2023 08:33:24 +0000 (09:33 +0100)
commit0ea9222945b8cad744efecad38a3cdaf24e6be7c
tree6bc18c3a625961f02af3700d33a8e7d3eac0cada
parent85ed3b684414a0a5736aae3783a031c8ddc458a6
nfsd: clean up potential nfsd_file refcount leaks in COPY codepath

[ Upstream commit e4eab085e8f4d0dc7e02166907f9d5c7f1f807bf ]

There are two different flavors of the nfsd4_copy struct. One is
embedded in the compound and is used directly in synchronous copies. The
other is dynamically allocated, refcounted and tracked in the client
struture. For the embedded one, the cleanup just involves releasing any
nfsd_files held on its behalf. For the async one, the cleanup is a bit
more involved, and we need to dequeue it from lists, unhash it, etc.

There is at least one potential refcount leak in this code now. If the
kthread_create call fails, then both the src and dst nfsd_files in the
original nfsd4_copy object are leaked.

The cleanup in this codepath is also sort of weird. In the async copy
case, we'll have up to four nfsd_file references (src and dst for both
flavors of copy structure). They are both put at the end of
nfsd4_do_async_copy, even though the ones held on behalf of the embedded
one outlive that structure.

Change it so that we always clean up the nfsd_file refs held by the
embedded copy structure before nfsd4_copy returns. Rework
cleanup_async_copy to handle both inter and intra copies. Eliminate
nfsd4_cleanup_intra_ssc since it now becomes a no-op.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Stable-dep-of: 0f941912707c ("NFSD: fix problems with cleanup on errors in nfsd4_copy")
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/nfsd/nfs4proc.c