]> git.baikalelectronics.ru Git - kernel.git/commitdiff
NFS: alloc_nfs_open_context() must use the file cred when available
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Sat, 8 Feb 2020 00:32:49 +0000 (19:32 -0500)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Mon, 16 Mar 2020 12:34:28 +0000 (08:34 -0400)
If we're creating a nfs_open_context() for a specific file pointer,
we must use the cred assigned to that file.

Fixes: c04f0e0ce679 ("NFS/NFSD/SUNRPC: replace generic creds with 'struct cred'.")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/inode.c

index 11bf15800ac9974204491ab0f7570ca063dbddfb..a10fb87c6ac33b8196bf25617b58d13a70c90f41 100644 (file)
@@ -959,16 +959,16 @@ struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry,
                                                struct file *filp)
 {
        struct nfs_open_context *ctx;
-       const struct cred *cred = get_current_cred();
 
        ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
-       if (!ctx) {
-               put_cred(cred);
+       if (!ctx)
                return ERR_PTR(-ENOMEM);
-       }
        nfs_sb_active(dentry->d_sb);
        ctx->dentry = dget(dentry);
-       ctx->cred = cred;
+       if (filp)
+               ctx->cred = get_cred(filp->f_cred);
+       else
+               ctx->cred = get_current_cred();
        ctx->ll_cred = NULL;
        ctx->state = NULL;
        ctx->mode = f_mode;