]> git.proxmox.com Git - mirror_ubuntu-focal-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)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Mon, 25 May 2020 08:41:18 +0000 (10:41 +0200)
BugLink: https://bugs.launchpad.net/bugs/1875660
[ Upstream commit 1d179d6bd67369a52edea8562154b31ee20be1cc ]

If we're creating a nfs_open_context() for a specific file pointer,
we must use the cred assigned to that file.

Fixes: a52458b48af1 ("NFS/NFSD/SUNRPC: replace generic creds with 'struct cred'.")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
fs/nfs/inode.c

index 2a03bfeec10a409a577eb2d773648c032d692d6e..3802c88e837207440afdb2c78977bb62fae4e30f 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;