NFSv4.2: fix reference count leaks in _nfs42_proc_copy_notify()
authorXin Xiong <xiongx18@fudan.edu.cn>
Tue, 25 Jan 2022 13:10:45 +0000 (21:10 +0800)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Fri, 25 Feb 2022 23:50:12 +0000 (18:50 -0500)
[You don't often get email from xiongx18@fudan.edu.cn. Learn why this is important at http://aka.ms/LearnAboutSenderIdentification.]

The reference counting issue happens in two error paths in the
function _nfs42_proc_copy_notify(). In both error paths, the function
simply returns the error code and forgets to balance the refcount of
object `ctx`, bumped by get_nfs_open_context() earlier, which may
cause refcount leaks.

Fix it by balancing refcount of the `ctx` object before the function
returns in both error paths.

Signed-off-by: Xin Xiong <xiongx18@fudan.edu.cn>
Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/nfs42proc.c

index 32129446beca6cc4c3cc0f007e88d4dde630ceeb..ca878d021faba01f7008ff1955be7407f2366094 100644 (file)
@@ -591,8 +591,10 @@ static int _nfs42_proc_copy_notify(struct file *src, struct file *dst,
 
        ctx = get_nfs_open_context(nfs_file_open_context(src));
        l_ctx = nfs_get_lock_context(ctx);
-       if (IS_ERR(l_ctx))
-               return PTR_ERR(l_ctx);
+       if (IS_ERR(l_ctx)) {
+               status = PTR_ERR(l_ctx);
+               goto out;
+       }
 
        status = nfs4_set_rw_stateid(&args->cna_src_stateid, ctx, l_ctx,
                                     FMODE_READ);
@@ -600,7 +602,7 @@ static int _nfs42_proc_copy_notify(struct file *src, struct file *dst,
        if (status) {
                if (status == -EAGAIN)
                        status = -NFS4ERR_BAD_STATEID;
-               return status;
+               goto out;
        }
 
        status = nfs4_call_sync(src_server->client, src_server, &msg,
@@ -609,6 +611,7 @@ static int _nfs42_proc_copy_notify(struct file *src, struct file *dst,
        if (status == -ENOTSUPP)
                src_server->caps &= ~NFS_CAP_COPY_NOTIFY;
 
+out:
        put_nfs_open_context(nfs_file_open_context(src));
        return status;
 }