NFSD: fix missing refcount in nfsd4_copy by nfsd4_do_async_copy
authorDai Ngo <dai.ngo@oracle.com>
Thu, 29 Oct 2020 19:07:16 +0000 (15:07 -0400)
committerJ. Bruce Fields <bfields@redhat.com>
Thu, 5 Nov 2020 22:25:14 +0000 (17:25 -0500)
Need to initialize nfsd4_copy's refcount to 1 to avoid use-after-free
warning when nfs4_put_copy is called from nfsd4_cb_offload_release.

Fixes: ce0887ac96d3 ("NFSD add nfs4 inter ssc to nfsd4_copy")
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
fs/nfsd/nfs4proc.c

index 9c43cad7e40812e9f46ede0423d37d2e8e1d43a7..e83b21778816d957d33f277c6a7a048ad71b82d6 100644 (file)
@@ -1486,6 +1486,7 @@ do_callback:
        cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
        if (!cb_copy)
                goto out;
+       refcount_set(&cb_copy->refcount, 1);
        memcpy(&cb_copy->cp_res, &copy->cp_res, sizeof(copy->cp_res));
        cb_copy->cp_clp = copy->cp_clp;
        cb_copy->nfserr = copy->nfserr;